X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-reconnect.c;h=14569dbadec3abcf93a4e6bad3f768b7bcf692bb;hb=372d58a4e3d735a269856d1f285b5ed1b99f6dce;hp=8441fadd3bcacffd62ea71d07733818409e17c5c;hpb=a85c0bbcfd19fcd88ee9966a86dd83107dfd6603;p=sliver-openvswitch.git diff --git a/tests/test-reconnect.c b/tests/test-reconnect.c index 8441fadd3..14569dbad 100644 --- a/tests/test-reconnect.c +++ b/tests/test-reconnect.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Nicira Networks. + * Copyright (c) 2009, 2010, 2011 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ #include "compiler.h" #include "svec.h" #include "util.h" +#include "vlog.h" static struct reconnect *reconnect; static int now; @@ -34,16 +35,20 @@ static int now; static const struct command commands[]; static void diff_stats(const struct reconnect_stats *old, - const struct reconnect_stats *new); + const struct reconnect_stats *new, + int delta); int main(void) { + extern struct vlog_module VLM_reconnect; struct reconnect_stats prev; unsigned int old_max_tries; int old_time; char line[128]; + vlog_set_levels(&VLM_reconnect, VLF_ANY_FACILITY, VLL_OFF); + now = 1000; reconnect = reconnect_create(now); reconnect_set_name(reconnect, "remote"); @@ -70,35 +75,36 @@ main(void) if (old_time != now) { printf("\n### t=%d ###\n", now); - old_time = now; } reconnect_get_stats(reconnect, now, &cur); - diff_stats(&prev, &cur); + diff_stats(&prev, &cur, now - old_time); prev = cur; if (reconnect_get_max_tries(reconnect) != old_max_tries) { old_max_tries = reconnect_get_max_tries(reconnect); printf(" %u tries left\n", old_max_tries); } + + old_time = now; } return 0; } static void -do_enable(int argc UNUSED, char *argv[] UNUSED) +do_enable(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { reconnect_enable(reconnect, now); } static void -do_disable(int argc UNUSED, char *argv[] UNUSED) +do_disable(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { reconnect_disable(reconnect, now); } static void -do_force_reconnect(int argc UNUSED, char *argv[] UNUSED) +do_force_reconnect(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { reconnect_force_reconnect(reconnect, now); } @@ -118,31 +124,31 @@ error_from_string(const char *s) } static void -do_disconnected(int argc UNUSED, char *argv[]) +do_disconnected(int argc OVS_UNUSED, char *argv[]) { reconnect_disconnected(reconnect, now, error_from_string(argv[1])); } static void -do_connecting(int argc UNUSED, char *argv[] UNUSED) +do_connecting(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { reconnect_connecting(reconnect, now); } static void -do_connect_failed(int argc UNUSED, char *argv[]) +do_connect_failed(int argc OVS_UNUSED, char *argv[]) { reconnect_connect_failed(reconnect, now, error_from_string(argv[1])); } static void -do_connected(int argc UNUSED, char *argv[] UNUSED) +do_connected(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { reconnect_connected(reconnect, now); } static void -do_received(int argc UNUSED, char *argv[] UNUSED) +do_received(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { reconnect_received(reconnect, now); } @@ -179,13 +185,13 @@ do_run(int argc, char *argv[]) } static void -do_advance(int argc UNUSED, char *argv[]) +do_advance(int argc OVS_UNUSED, char *argv[]) { now += atoi(argv[1]); } static void -do_timeout(int argc UNUSED, char *argv[] UNUSED) +do_timeout(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { int timeout = reconnect_timeout(reconnect, now); if (timeout >= 0) { @@ -197,14 +203,15 @@ do_timeout(int argc UNUSED, char *argv[] UNUSED) } static void -do_set_max_tries(int argc UNUSED, char *argv[]) +do_set_max_tries(int argc OVS_UNUSED, char *argv[]) { reconnect_set_max_tries(reconnect, atoi(argv[1])); } static void diff_stats(const struct reconnect_stats *old, - const struct reconnect_stats *new) + const struct reconnect_stats *new, + int delta) { if (old->state != new->state || old->state_elapsed != new->state_elapsed @@ -225,16 +232,46 @@ diff_stats(const struct reconnect_stats *old, new->n_successful_connections, new->n_attempted_connections, new->seqno); } - if (old->is_connected != new->is_connected - || old->current_connection_duration != new->current_connection_duration - || old->total_connected_duration != new->total_connected_duration) { - printf(" %sconnected (%u ms), total %u ms connected\n", - new->is_connected ? "" : "not ", - new->current_connection_duration, - new->total_connected_duration); + if (old->is_connected != new->is_connected) { + printf(" %sconnected\n", new->is_connected ? "" : "dis"); + } + if (old->last_connected != new->last_connected + || (old->msec_since_connect != new->msec_since_connect - delta + && !(old->msec_since_connect == UINT_MAX + && new->msec_since_connect == UINT_MAX)) + || (old->total_connected_duration != new->total_connected_duration - delta + && !(old->total_connected_duration == 0 + && new->total_connected_duration == 0))) { + printf(" last connected %u ms ago, connected %u ms total\n", + new->msec_since_connect, new->total_connected_duration); + } + if (old->last_disconnected != new->last_disconnected + || (old->msec_since_disconnect != new->msec_since_disconnect - delta + && !(old->msec_since_disconnect == UINT_MAX + && new->msec_since_disconnect == UINT_MAX))) { + printf(" disconnected at %llu ms (%u ms ago)\n", + new->last_disconnected, new->msec_since_disconnect); } } +static void +do_set_passive(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) +{ + reconnect_set_passive(reconnect, true, now); +} + +static void +do_listening(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) +{ + reconnect_listening(reconnect, now); +} + +static void +do_listen_error(int argc OVS_UNUSED, char *argv[]) +{ + reconnect_listen_error(reconnect, now, atoi(argv[1])); +} + static const struct command commands[] = { { "enable", 0, 0, do_enable }, { "disable", 0, 0, do_disable }, @@ -248,6 +285,8 @@ static const struct command commands[] = { { "advance", 1, 1, do_advance }, { "timeout", 0, 0, do_timeout }, { "set-max-tries", 1, 1, do_set_max_tries }, + { "passive", 0, 0, do_set_passive }, + { "listening", 0, 0, do_listening }, + { "listen-error", 1, 1, do_listen_error }, { NULL, 0, 0, NULL }, }; -