Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -89,7 +89,7 @@ lib_LTLIBRARIES = src/libvde.la
src_libvde_la_SOURCES = $(VDE_SRC)
# XXX consider adding -export-symbols <file.sym>
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}' \
Expand All @@ -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
Expand Down Expand Up @@ -172,4 +179,4 @@ install-data-local: doxygen-install

clean-local: doxygen-clean

uninstall-local: doxygen-uninstall

2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand Down
89 changes: 89 additions & 0 deletions tests/speedtest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* Test for vde_switch */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <errno.h>
#include <libgen.h>
#include <syslog.h>
#include <fcntl.h>
#include <time.h>
#include <signal.h>
#include <math.h>
#include <stdarg.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/poll.h>

#include <libvdeplug.h>
#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;
unsigned long long burst = 1, f;

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 < 1000) {
burst = rate / 1000;
interval = 1000;
}
printf ("Inter-frame interval %llu μs\n", interval);
printf ("Frame burst: %llu\n", burst);
}


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) {
for (f = 0; f < burst; f++) {
vde_send(plug, buf, n, 0);
(*count)++;
}
if (interval)
usleep(interval);
}
}


111 changes: 111 additions & 0 deletions tests/speedtest_recv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* Test for vde_switch */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <errno.h>
#include <libgen.h>
#include <syslog.h>
#include <fcntl.h>
#include <time.h>
#include <signal.h>
#include <math.h>
#include <stdarg.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>


#include <libvdeplug.h>
#include <sys/poll.h>

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 Mbit/s - out of order: %llu, lost: %llu\n", counter,
(t_end - t_start)/1000,
(((counter*BUFSIZE) << 3)/(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++;
}
}
}