added udp jitter/packet count calculation
This commit is contained in:
parent
71a7ccf6d3
commit
f4ca73a1b1
@ -300,10 +300,14 @@ int iperf_tcp_recv(struct iperf_stream *sp)
|
||||
}
|
||||
|
||||
int iperf_udp_recv(struct iperf_stream *sp)
|
||||
{ int result, message;
|
||||
char ch;
|
||||
{
|
||||
int result, message;
|
||||
int size = sp->settings->blksize;
|
||||
double transit = 0, d = 0;
|
||||
char *buf = (char *) malloc(size);
|
||||
struct udp_datagram *udp = (struct udp_datagram *) buf;
|
||||
struct timeval arrival_time;
|
||||
|
||||
if(!buf)
|
||||
{
|
||||
perror("malloc: unable to allocate receive buffer");
|
||||
@ -317,17 +321,30 @@ int iperf_udp_recv(struct iperf_stream *sp)
|
||||
//interprete the type of message in packet
|
||||
if(result > 0)
|
||||
{
|
||||
ch = buf[0];
|
||||
message = (int) ch;
|
||||
message = udp->state;
|
||||
}
|
||||
|
||||
if(message != STREAM_END && (sp->stream_id == udp->stream_id))
|
||||
{
|
||||
sp->result->bytes_received+= result;
|
||||
//if((sp->packet_count + 1) == udp->packet_count)
|
||||
sp->packet_count++;
|
||||
|
||||
//jitter measurement
|
||||
if(gettimeofday(&arrival_time, NULL) < 0) {
|
||||
perror("gettimeofday");
|
||||
}
|
||||
|
||||
transit = timeval_diff(&udp->sent_time, &arrival_time);
|
||||
d = transit - sp->prev_transit;
|
||||
if(d < 0)
|
||||
d = -d;
|
||||
sp->prev_transit = transit;
|
||||
sp->jitter += (d - sp->jitter)/ 16.0;
|
||||
}
|
||||
|
||||
if(message == 3 || message == 9 || message == 8)
|
||||
{
|
||||
printf("Recieved %d from client\n", message);
|
||||
}
|
||||
|
||||
if(message != STREAM_END)
|
||||
sp->result->bytes_received+= result;
|
||||
|
||||
free(buf);
|
||||
return message;
|
||||
@ -382,7 +399,8 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
||||
|
||||
result = send(sp->socket, buf, size , 0);
|
||||
|
||||
sp->result->bytes_sent+= size;
|
||||
if(buf[0] != STREAM_END)
|
||||
sp->result->bytes_sent+= size;
|
||||
|
||||
free(buf);
|
||||
return result;
|
||||
@ -390,7 +408,7 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
||||
|
||||
int iperf_udp_send(struct iperf_stream *sp)
|
||||
{
|
||||
int result = 0, i;
|
||||
int result = 0;
|
||||
struct timeval before, after;
|
||||
int64_t adjustus, dtargus;
|
||||
|
||||
@ -399,6 +417,9 @@ int iperf_udp_send(struct iperf_stream *sp)
|
||||
{
|
||||
int size = sp->settings->blksize;
|
||||
char *buf = (char *) malloc(size);
|
||||
// this is for udp packet/jitter/lost packet measurements
|
||||
struct udp_datagram *udp = (struct udp_datagram *) buf;
|
||||
|
||||
if(!buf)
|
||||
{
|
||||
perror("malloc: unable to allocate transmit buffer");
|
||||
@ -409,30 +430,36 @@ int iperf_udp_send(struct iperf_stream *sp)
|
||||
|
||||
assert(dtargus != 0);
|
||||
|
||||
// record the packet sent time
|
||||
if(gettimeofday(&udp->sent_time, 0) < 0)
|
||||
perror("gettimeofday");
|
||||
|
||||
switch(sp->settings->state)
|
||||
{
|
||||
case STREAM_BEGIN:
|
||||
buf[0]= STREAM_BEGIN;
|
||||
for(i=1; i < size; i++)
|
||||
buf[i] = i % 37;
|
||||
udp->state = STREAM_BEGIN;
|
||||
udp->stream_id = (int)sp;
|
||||
udp->packet_count = (sp->packet_count)++;
|
||||
break;
|
||||
|
||||
case STREAM_END:
|
||||
buf[0]= STREAM_END;
|
||||
udp->state = STREAM_END;
|
||||
udp->stream_id = (int) sp;
|
||||
break;
|
||||
|
||||
case RESULT_REQUEST:
|
||||
buf[0]= RESULT_REQUEST;
|
||||
udp->state = RESULT_REQUEST;
|
||||
udp->stream_id = (int) sp;
|
||||
break;
|
||||
|
||||
case ALL_STREAMS_END:
|
||||
buf[0]= ALL_STREAMS_END;
|
||||
udp->state = ALL_STREAMS_END;
|
||||
break;
|
||||
|
||||
default:
|
||||
buf[0]= 0;
|
||||
for(i=1; i < size; i++)
|
||||
buf[i] = i % 37;
|
||||
udp->state = 0;
|
||||
udp->stream_id = (int)sp;
|
||||
udp->packet_count = sp->packet_count++;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -466,6 +493,7 @@ int iperf_udp_send(struct iperf_stream *sp)
|
||||
// RESET THE TIMER
|
||||
update_timer(sp->send_timer, 0, dtargus);
|
||||
free(buf);
|
||||
|
||||
} // timer_expired_micro
|
||||
|
||||
return result;
|
||||
@ -582,6 +610,7 @@ void iperf_init_test(struct iperf_test *test)
|
||||
|
||||
if(test->default_settings->state != RESULT_REQUEST)
|
||||
connect_msg(sp);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -653,7 +682,7 @@ void *iperf_stats_callback(struct iperf_test *test)
|
||||
|
||||
char *iperf_reporter_callback(struct iperf_test *test)
|
||||
{
|
||||
int count = 0;
|
||||
int count = 0, total_packets = 0;
|
||||
char ubuf[UNIT_LEN];
|
||||
char nbuf[UNIT_LEN];
|
||||
struct iperf_stream *sp = test->streams;
|
||||
@ -723,9 +752,11 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
||||
if(test->role == 'c')
|
||||
bytes+= sp->result->bytes_sent;
|
||||
else
|
||||
{
|
||||
bytes+= sp->result->bytes_received;
|
||||
}
|
||||
|
||||
if(test->protocol == Pudp)
|
||||
total_packets+= sp->packet_count;
|
||||
|
||||
|
||||
if(test->protocol == Ptcp)
|
||||
{
|
||||
@ -761,7 +792,7 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
||||
else
|
||||
{
|
||||
sprintf(message, report_bw_jitter_loss_format, sp->socket, start_time,
|
||||
end_time, ubuf, nbuf, 0.0, 0, 0, 0.0);
|
||||
end_time, ubuf, nbuf, sp->jitter * 1000, 0, sp->packet_count, 0.0);
|
||||
strcat(message_final, message);
|
||||
}
|
||||
}
|
||||
@ -784,7 +815,7 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(message, report_sum_bw_jitter_loss_format, start_time, end_time, ubuf, nbuf, 0.0, 0, 0, 0.0);
|
||||
sprintf(message, report_sum_bw_jitter_loss_format, start_time, end_time, ubuf, nbuf,sp->jitter, 0, total_packets, 0.0);
|
||||
strcat(message_final, message);
|
||||
}
|
||||
|
||||
@ -855,6 +886,11 @@ struct iperf_stream *iperf_new_stream(struct iperf_test *testp)
|
||||
|
||||
sp->socket = -1;
|
||||
|
||||
sp->packet_count =0;
|
||||
sp->stream_id = (int)sp;
|
||||
sp->jitter = 0.0;
|
||||
sp->prev_transit = 0.0;
|
||||
|
||||
sp->result->bytes_received = 0;
|
||||
sp->result->bytes_sent = 0;
|
||||
gettimeofday(&sp->result->start_time, NULL);
|
||||
@ -906,6 +942,7 @@ int iperf_udp_accept(struct iperf_test *test)
|
||||
int sz;
|
||||
|
||||
buf = (char *) malloc(test->default_settings->blksize);
|
||||
struct udp_datagram *udp = (struct udp_datagram *) buf;
|
||||
len = sizeof sa_peer;
|
||||
|
||||
sz = recvfrom(test->listener_sock_udp, buf, test->default_settings->blksize, 0, (struct sockaddr *) &sa_peer, &len);
|
||||
@ -929,20 +966,24 @@ int iperf_udp_accept(struct iperf_test *test)
|
||||
sp->result->bytes_received+= sz;
|
||||
iperf_add_stream(test, sp);
|
||||
|
||||
|
||||
test->listener_sock_udp = netannounce(Pudp, NULL, test->server_port);
|
||||
if(test->listener_sock_udp < 0)
|
||||
return -1;
|
||||
|
||||
|
||||
FD_SET(test->listener_sock_udp, &test->read_set);
|
||||
test->max_fd = (test->max_fd < test->listener_sock_udp) ? test->listener_sock_udp : test->max_fd;
|
||||
|
||||
if(test->default_settings->state != RESULT_REQUEST)
|
||||
connect_msg(sp);
|
||||
|
||||
printf("1st UDP data packet for socket %d has arrived \n", sp->socket);
|
||||
sp->stream_id = udp->stream_id;
|
||||
sp->packet_count++;
|
||||
printf("Stream id = %d\tudp_id = %d\tcount = %d\n", sp->stream_id, udp->stream_id, sp->packet_count);
|
||||
|
||||
free(buf);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int iperf_tcp_accept(struct iperf_test *test)
|
||||
@ -1100,7 +1141,7 @@ void iperf_run_server(struct iperf_test *test)
|
||||
else if(result >0)
|
||||
{
|
||||
// Accept a new TCP connection
|
||||
if (FD_ISSET(test->listener_sock_tcp, &test->temp_set) )
|
||||
if (FD_ISSET(test->listener_sock_tcp, &test->temp_set))
|
||||
{
|
||||
test->protocol = Ptcp;
|
||||
test->default_settings->blksize = DEFAULT_TCP_BLKSIZE;
|
||||
|
@ -5,7 +5,6 @@ struct iperf_interval_results
|
||||
iperf_size_t bytes_transferred;
|
||||
int interval_duration;
|
||||
struct iperf_interval_results *next;
|
||||
|
||||
void * custom_data;
|
||||
};
|
||||
|
||||
@ -44,11 +43,15 @@ struct iperf_stream
|
||||
|
||||
/* non configurable members */
|
||||
struct iperf_stream_result *result; //structure pointer to result
|
||||
|
||||
int socket; // socket
|
||||
|
||||
struct timer *send_timer;
|
||||
|
||||
/* for udp measurements - Need to change the members */
|
||||
int packet_count;
|
||||
int stream_id; // stream identity
|
||||
double jitter;
|
||||
double prev_transit;
|
||||
|
||||
struct sockaddr_storage local_addr;
|
||||
struct sockaddr_storage remote_addr;
|
||||
|
||||
@ -101,6 +104,19 @@ struct iperf_test
|
||||
};
|
||||
|
||||
|
||||
struct udp_datagram
|
||||
{
|
||||
int state;
|
||||
int stream_id;
|
||||
int packet_count;
|
||||
struct timeval sent_time;
|
||||
};
|
||||
|
||||
|
||||
void add_interval_list(struct iperf_stream_result *rp, struct iperf_interval_results temp);
|
||||
void display_interval_list(struct iperf_stream_result *rp);
|
||||
void send_result_to_client(struct iperf_stream *sp);
|
||||
void receive_result_from_server(struct iperf_test *test);
|
||||
int getsock_tcp_mss( int inSock );
|
||||
int set_socket_options(struct iperf_stream *sp, struct iperf_test *test);
|
||||
void connect_msg(struct iperf_stream *sp);
|
||||
|
@ -24,7 +24,8 @@ timeval_to_double(struct timeval *tv)
|
||||
double
|
||||
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);
|
||||
return (tv1->tv_sec - tv0->tv_sec) + abs(tv1->tv_usec - tv0->tv_usec) / 1000000.0;
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
Reference in New Issue
Block a user