From 3b1cadc1fd4d881094a62ce3b54a40b05deaec53 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 23 Feb 2012 06:47:23 +0100 Subject: [PATCH 1/3] Added speedtest for vde components --- Makefile.am | 13 +++-- configure.ac | 2 + tests/speedtest.c | 85 +++++++++++++++++++++++++++++++ tests/speedtest_recv.c | 111 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 tests/speedtest.c create mode 100644 tests/speedtest_recv.c diff --git a/Makefile.am b/Makefile.am index acf1951..fe67357 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,7 +64,7 @@ dist-hook: rm -f $(addprefix $(top_distdir)/,$(WRAPPERS_SRC)) rm -f $(addprefix $(top_distdir)/,$(WRAPPERS_HDR)) -bin_PROGRAMS = src/vde_hub src/vde_hub2hub +bin_PROGRAMS = src/vde_hub src/vde_hub2hub tests/speedtest tests/speedtest_recv # dynamic modules @@ -89,7 +89,7 @@ lib_LTLIBRARIES = src/libvde.la src_libvde_la_SOURCES = $(VDE_SRC) # XXX consider adding -export-symbols src_libvde_la_LDFLAGS = $(GLIB_LIBS) $(JSONC_LIBS) -ldl -export-dynamic \ - -version-info $(LIBVDE_VERSION) + -version-info $(LIBVDE_VERSION) # XXX define this better src_libvde_la_CPPFLAGS = \ -DVDE_DEFAULT_MODULES_PATH='{"$(modulesdir)", "src/.libs", NULL}' \ @@ -105,6 +105,13 @@ src_vde_hub2hub_SOURCES = src/vde_hub2hub.c src/libevent_handler.c src_vde_hub2hub_LDADD = src/libvde.la $(JSONC_LIBS) src_vde_hub2hub_LDFLAGS = -levent +# speedtest +tests_speedtest_SOURCES = tests/speedtest.c +tests_speedtest_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS) -I$(top_srcdir)/src/include/ +tests_speedtest_LDADD = $(CHECK_LIBS) -lvdeplug +tests_speedtest_recv_SOURCES = tests/speedtest_recv.c +tests_speedtest_recv_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS) -I$(top_srcdir)/src/include/ +tests_speedtest_recv_LDADD = $(CHECK_LIBS) -lvdeplug if CHECK TESTS = tests/check_context tests/check_vde_ordhash @@ -172,4 +179,4 @@ install-data-local: doxygen-install clean-local: doxygen-clean -uninstall-local: doxygen-uninstall + diff --git a/configure.ac b/configure.ac index b91b235..463227b 100644 --- a/configure.ac +++ b/configure.ac @@ -26,6 +26,8 @@ AC_PROG_LIBTOOL VDE_CHECK_LIB_HEADER([event], [event_init], [event.h], , AC_MSG_ERROR([Could not find libevent])) +VDE_CHECK_LIB_HEADER([vdeplug], [vde_send], [libvdeplug.h], , ) + PKG_CHECK_MODULES(GLIB, glib-2.0, , AC_MSG_ERROR([Could not find glib 2.0])) diff --git a/tests/speedtest.c b/tests/speedtest.c new file mode 100644 index 0000000..a3a4286 --- /dev/null +++ b/tests/speedtest.c @@ -0,0 +1,85 @@ +/* Test for vde_switch */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#define BUFSIZE 2048 + +void exiting(int signo) +{ + exit(0); +} + + +int main (int argc, char **argv) { + const unsigned char eth_hdr[14] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00}; + char buf[BUFSIZE]; + VDECONN *plug; + int randomfd, n; + unsigned long long *count; + int rate = 0; + unsigned long long interval = 0; + + if ((argc != 2) && (argc != 3)) { + printf("Usage: %s sock [rate in frame/s]\n", argv[0]); + exit(1); + } + + if (argc == 3) { + rate = atoi(argv[2]); + if (rate < 1) { + printf("Invalid frame rate %s\n", argv[2]); + exit(1); + } + interval = 1000000 / rate; + if (interval < 1) { + printf("Warning: frame rate %s is too high, framerate is unlimited.\n", argv[2]); + } else { + printf ("Inter-frame interval %llu μs\n", interval); + } + } + + + plug = vde_open(argv[1], "test_send", NULL); + if (!plug) { + perror("vde_open"); + exit(2); + } + randomfd=open("/dev/urandom", O_RDONLY); + if (randomfd < 0) + exit(3); + + n = read(randomfd, buf, BUFSIZE); + memcpy(buf, eth_hdr, 14); + count = (unsigned long long *)(&buf[14]); + *count = 0; + signal(SIGALRM, exiting); + alarm(30); + while(1) { + vde_send(plug, buf, n, 0); + (*count)++; + if (interval) + usleep(interval); + } +} + + diff --git a/tests/speedtest_recv.c b/tests/speedtest_recv.c new file mode 100644 index 0000000..d2ff37a --- /dev/null +++ b/tests/speedtest_recv.c @@ -0,0 +1,111 @@ +/* Test for vde_switch */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include + +static inline unsigned long long +gettimeofdayms(void) { + struct timeval tv; + gettimeofday(&tv, 0); + return (unsigned long long) tv.tv_sec * 1000ULL + (unsigned long long) tv.tv_usec / 1000; +} + +#define BUFSIZE 1540ULL + +static unsigned long + long t_start, t_end, counter, reordered, lost; + + +void print_statistics(int signo) +{ + static int test = 0; + t_end = gettimeofdayms(); + printf("Sent %llu packets in %llu seconds, Bandwidth: %lld MB/s - out of order: %llu, lost: %llu\n", counter, + (t_end - t_start)/1000, + ((counter*BUFSIZE)/(1000*(t_end - t_start))), + reordered, lost); + t_start = t_end; + counter = 0; + if (test++ == 5) + exit(0); + else + alarm(5); +} + +int main (int argc, char **argv) { + + int n, p; + char buf[BUFSIZE]; + VDECONN *plug; + struct pollfd pfd[1]= { + [0]={.fd=-1} + }; + unsigned long long *pkt, last = 0; + if (argc != 2) { + printf("Usage: %s sock\n", argv[0]); + exit(1); + } + + + plug = vde_open(argv[1], "test_recv", NULL); + if (!plug) { + perror("vde_open"); + exit(2); + } + + pfd[0].fd=vde_datafd(plug); + pfd[0].events=POLLIN | POLLHUP; + signal(SIGALRM, print_statistics); + p = poll(pfd, 1, -1); + if (pfd[0].revents & POLLIN) { + alarm(5); + } else { + exit(0); + } + t_start=gettimeofdayms(); + + while(1) { + p = poll(pfd, 1, 1); + if (pfd[0].revents & POLLHUP) + exit(0); + if (pfd[0].revents & POLLIN) { + n=vde_recv(plug, buf, BUFSIZE, 0); + pkt = (unsigned long long *)(&buf[14]); + //printf ("Received pkt %llu\n", *pkt); + if (!last) + last = *pkt; + else { + if (*pkt > last + 1) + lost++; + if (*pkt < last) { + reordered++; + lost--; + } + last = *pkt; + } + counter++; + } + } +} + From a75e45e369c5915c13a5e9fe46641f2af4697f04 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 23 Feb 2012 09:41:20 +0100 Subject: [PATCH 2/3] speedtest: switched displayed speed to Mbit/s --- tests/speedtest_recv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/speedtest_recv.c b/tests/speedtest_recv.c index d2ff37a..ea47c83 100644 --- a/tests/speedtest_recv.c +++ b/tests/speedtest_recv.c @@ -41,9 +41,9 @@ void print_statistics(int signo) { static int test = 0; t_end = gettimeofdayms(); - printf("Sent %llu packets in %llu seconds, Bandwidth: %lld MB/s - out of order: %llu, lost: %llu\n", counter, + printf("Sent %llu packets in %llu seconds, Bandwidth: %lld Mbit/s - out of order: %llu, lost: %llu\n", counter, (t_end - t_start)/1000, - ((counter*BUFSIZE)/(1000*(t_end - t_start))), + (((counter*BUFSIZE) << 3)/(1000*(t_end - t_start))), reordered, lost); t_start = t_end; counter = 0; From a7277f1a7cb8fe29e56dc766e04c0f7d38a3df2f Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 23 Feb 2012 10:35:21 +0100 Subject: [PATCH 3/3] Modified speedtest to have bursts of packets --- tests/speedtest.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/speedtest.c b/tests/speedtest.c index a3a4286..69bd40f 100644 --- a/tests/speedtest.c +++ b/tests/speedtest.c @@ -38,6 +38,7 @@ int main (int argc, char **argv) { unsigned long long *count; int rate = 0; unsigned long long interval = 0; + unsigned long long burst = 1, f; if ((argc != 2) && (argc != 3)) { printf("Usage: %s sock [rate in frame/s]\n", argv[0]); @@ -51,11 +52,12 @@ int main (int argc, char **argv) { exit(1); } interval = 1000000 / rate; - if (interval < 1) { - printf("Warning: frame rate %s is too high, framerate is unlimited.\n", argv[2]); - } else { - printf ("Inter-frame interval %llu μs\n", interval); + if (interval < 1000) { + burst = rate / 1000; + interval = 1000; } + printf ("Inter-frame interval %llu μs\n", interval); + printf ("Frame burst: %llu\n", burst); } @@ -75,8 +77,10 @@ int main (int argc, char **argv) { signal(SIGALRM, exiting); alarm(30); while(1) { - vde_send(plug, buf, n, 0); - (*count)++; + for (f = 0; f < burst; f++) { + vde_send(plug, buf, n, 0); + (*count)++; + } if (interval) usleep(interval); }