Skip to content

Commit

Permalink
Implement imix packet size selection for udp
Browse files Browse the repository at this point in the history
This provides a somewhat more realistic workload for middleware
performance testing.
  • Loading branch information
danobi committed Sep 14, 2023
1 parent 11c94f7 commit ff08316
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/iperf_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
# endif
#endif

/* 20B for ipv4 and 8B for udp */
#define HEADER_OVERHEAD (20 + 8)

/* iperf_udp_recv
*
* receives the data for UDP
Expand Down Expand Up @@ -204,6 +207,32 @@ iperf_udp_recv(struct iperf_stream *sp)
return r;
}

/* Determine send size for a single packet */
static int iperf_udp_send_size(struct iperf_stream *sp)
{
int class_sz;
int r;

if (!sp->settings->imix)
return sp->settings->blksize;

/* IMIX (according to wikipedia) says:
* Packet size (incl. IP header) # Packets Distribution (in packets)
* 40 7 58.333333%
* 576 4 33.333333%
* 1500 1 8.333333%
*/
r = random() % 1000;
if (r < 580)
class_sz = 40;
else if (r < 580 + 333)
class_sz = 576;
else
class_sz = 1500;

return class_sz - HEADER_OVERHEAD;
}


/* iperf_udp_send
*
Expand All @@ -213,9 +242,10 @@ int
iperf_udp_send(struct iperf_stream *sp)
{
int r;
int size = sp->settings->blksize;
int size;
struct iperf_time before;

size = iperf_udp_send_size(sp);
iperf_time_now(&before);

++sp->packet_count;
Expand Down Expand Up @@ -264,7 +294,7 @@ iperf_udp_send(struct iperf_stream *sp)
sp->result->bytes_sent_this_interval += r;

if (sp->test->debug_level >= DEBUG_LEVEL_DEBUG)
printf("sent %d bytes of %d, total %" PRIu64 "\n", r, sp->settings->blksize, sp->result->bytes_sent);
printf("sent %d bytes of %d, total %" PRIu64 "\n", r, size, sp->result->bytes_sent);

return r;
}
Expand Down Expand Up @@ -631,5 +661,6 @@ iperf_udp_connect(struct iperf_test *test)
int
iperf_udp_init(struct iperf_test *test)
{
srandom(0xDEADF00D);
return 0;
}

0 comments on commit ff08316

Please sign in to comment.