Commit f039a318 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

networkTool: randomize burst of frames

parent 400b86fe
......@@ -268,7 +268,7 @@ int tx_burst_to(my_socket *sock, wr_sockaddr_t *to, int burst_id, int burst_numb
{
struct bench_pkt *p;
int i, delta, slen, pktn, pktt, pkts;
int i, j, delta, slen, pktn, pktt, pkts;
struct my_socket *s = (struct my_socket *)sock;
struct sockaddr_ll sll;
int rval;
......@@ -276,54 +276,84 @@ int tx_burst_to(my_socket *sock, wr_sockaddr_t *to, int burst_id, int burst_numb
int percent = burst_number/100;
struct timeval tsend, tstamp;
if(data_length > ETHER_MTU-8) return -EINVAL;
if(data_length < sizeof(struct bench_pkt)) return -EINVAL;
/* alloc packet */
p = (bench_pkt*)calloc(1, data_length);
if (!p) exit(5);
p->burst_id = burst_id;
p->size = data_length;
if(data_length < 60) /* pad to the minimum allowed packet size */
data_length = 60;
if(rtOpts->randomized == 0) {
if(data_length > ETHER_MTU-8) return -EINVAL;
if(data_length < sizeof(struct bench_pkt)) return -EINVAL;
memset(&sll, 0, sizeof(struct sockaddr_ll));
if(data_length < 60) /* pad to the minimum allowed packet size */
data_length = 60;
/* alloc packet */
p = (bench_pkt*)calloc(1, data_length);
if (!p) exit(5);
p->burst_id = burst_id;
p->size = data_length;
memset(&sll, 0, sizeof(struct sockaddr_ll));
sll.sll_ifindex = s->if_index;
sll.sll_family = AF_PACKET;
sll.sll_protocol = htons(to->ethertype);
sll.sll_halen = 6;
memcpy(sll.sll_addr, to->mac, sizeof(mac_addr_t));
gettimeofday(&tsend, NULL); /* time of prev-than-first tx */
}
sll.sll_ifindex = s->if_index;
sll.sll_family = AF_PACKET;
sll.sll_protocol = htons(to->ethertype);
sll.sll_halen = 6;
memcpy(sll.sll_addr, to->mac, sizeof(mac_addr_t));
gettimeofday(&tsend, NULL); /* time of prev-than-first tx */
for (i=0; i<burst_number; i++)
{
p->seq = i;
/* wait tx time */
if(pkt_time_interval)
{
tsend.tv_usec += pkt_time_interval;
if (tsend.tv_usec > 1000*1000)
{
tsend.tv_usec -= 1000*1000;
tsend.tv_sec++;
}
gettimeofday(&tstamp, NULL);
delta = (tsend.tv_sec - tstamp.tv_sec)*1000*1000+tsend.tv_usec - tstamp.tv_usec;
if (delta < 0) delta = 0;
usleep(delta);
}
/* stamp packet and send it */
gettimeofday(&p->tx, NULL);
rval = sendto(s->fd, p, data_length, 0, (struct sockaddr *)&sll,sizeof(struct sockaddr_ll));
if(rval<0)
{
printf("Sending burst failed at frame %d\n",i);
}
if((rtOpts->show_rxtx_data == DEBUG_LIGHT) && (i%percent) == 0)
printf("send %d \%\n",i/percent);
if(rtOpts->randomized) {
data_length = rand()%(ETHER_MTU-8-120)+60;
p = (bench_pkt*)calloc(1, data_length);
if (!p) exit(5);
p->burst_id = burst_id;
p->size = data_length;
for(j=0; j<data_length-sizeof(struct bench_pkt)-1; ++j)
p->payload[j] = (char)(rand()%0xff);
memset(&sll, 0, sizeof(struct sockaddr_ll));
sll.sll_ifindex = s->if_index;
sll.sll_family = AF_PACKET;
//sll.sll_protocol = rand()%0xffff;
sll.sll_protocol = htons(to->ethertype);
sll.sll_halen = 6;
//for(j=0; j<6; ++j)
// sll.sll_addr[j] = rand()%0xff;
memcpy(sll.sll_addr, to->mac, sizeof(mac_addr_t));
gettimeofday(&tsend, NULL); /* time of prev-than-first tx */
}
p->seq = i;
/* wait tx time */
if(pkt_time_interval)
{
tsend.tv_usec += pkt_time_interval;
if (tsend.tv_usec > 1000*1000)
{
tsend.tv_usec -= 1000*1000;
tsend.tv_sec++;
}
gettimeofday(&tstamp, NULL);
delta = (tsend.tv_sec - tstamp.tv_sec)*1000*1000+tsend.tv_usec - tstamp.tv_usec;
if (delta < 0) delta = 0;
usleep(delta);
}
/* stamp packet and send it */
gettimeofday(&p->tx, NULL);
rval = sendto(s->fd, p, data_length, 0, (struct sockaddr *)&sll,sizeof(struct sockaddr_ll));
if(rval<0)
{
printf("Sending burst failed at frame %d; len=%u\n",i, data_length);
}
if((rtOpts->show_rxtx_data == DEBUG_LIGHT) && (i%percent) == 0)
printf("send %d \%\n",i/percent);
if(rtOpts->randomized) {
free(p);
p = NULL;
}
}
if(!p) free(p);
return i;
}
......@@ -424,9 +454,9 @@ int startup(int argc, char **argv, RunTimeOpts *rtOpts)
rtOpts->pkt_number_in_burst = 100;
rtOpts->pkt_payload_size = 500;
rtOpts->show_rxtx_data =DEBUG_NO;
memcpy(rtOpts->dst_mac, DEFAULT_UNICAST_MAC, sizeof(mac_addr_t));
while( (c = getopt(argc, argv, "?r:t:f:s:n:u:mbe:v:z:h:j:q:g:")) != -1 ) {
rtOpts->randomized = 0;
memcpy(rtOpts->dst_mac, DEFAULT_UNICAST_MAC, sizeof(mac_addr_t));
while( (c = getopt(argc, argv, "?r:t:f:s:n:u:mbae:v:z:h:j:q:g:")) != -1 ) {
switch(c) {
case '?':
printf(
......@@ -449,9 +479,10 @@ int startup(int argc, char **argv, RunTimeOpts *rtOpts)
"-g MAC send to specified MAC (format: AA:BB:CC:DD:FF:11)\n"
"-e ethertype set ethertype\n"
"-v time_interval set time interval between frames in burts (not optimal, smallest 60[us])\n"
"-q time_interval set time interval between frames in burst (using optimized functions)"
" can be used also during reception then rx_fasters_burst_from() used "
"-q time_interval set time interval between frames in burst (using optimized functions)\n"
" can be used also during reception then rx_fasters_burst_from() used\n"
"-z payload_size set payload size\n"
"-a randomize frames in burst\n"
"-h show rx/tx data (e.g.: time)\n"
"\n",
DEFAULT_UNICAST_MAC[0],DEFAULT_UNICAST_MAC[1],DEFAULT_UNICAST_MAC[2],
......@@ -586,6 +617,11 @@ int startup(int argc, char **argv, RunTimeOpts *rtOpts)
rtOpts->dst_mac[4],
rtOpts->dst_mac[5]);
break;
case 'a':
rtOpts->randomized = 1;
srand((int)time(NULL));
break;
default:
printf("Wrong arguments\n"
......
......@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
......@@ -131,6 +132,7 @@ typedef struct {
int pkt_number_in_burst;
size_t pkt_payload_size;
int show_rxtx_data;
int randomized;
} RunTimeOpts;
#endif
\ No newline at end of file
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment