/*
- * Copyright (c) 2009, 2010 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.
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)
int old_time;
char line[128];
- vlog_set_levels(&VLM_reconnect, VLF_ANY_FACILITY, VLL_EMER);
+ vlog_set_levels(&VLM_reconnect, VLF_ANY_FACILITY, VLL_OFF);
now = 1000;
reconnect = reconnect_create(now);
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
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
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_disconnected != new->last_disconnected) {
- printf(" disconnected at %llu ms (%u ms ago)\n",
- new->last_disconnected, new->current_disconnect_duration);
+ 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->current_disconnect_duration != new->current_disconnect_duration) {
- printf(" disconnected for %llu ms\n", new->current_disconnect_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);
}
}
{ "listen-error", 1, 1, do_listen_error },
{ NULL, 0, 0, NULL },
};
-