X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-reconnect.py;h=c478c2a9b2f529faf466939a101540adbb7f14f3;hb=003ce655b7116d18c86a74c50391e54990346931;hp=0c467564c1b6b0e8c7932d3bad009876f70091b0;hpb=eba18f0044cbe3654b4c796bbe7c056ca1793c70;p=sliver-openvswitch.git diff --git a/tests/test-reconnect.py b/tests/test-reconnect.py index 0c467564c..c478c2a9b 100644 --- a/tests/test-reconnect.py +++ b/tests/test-reconnect.py @@ -1,11 +1,11 @@ -# Copyright (c) 2009, 2010 Nicira Networks. -# +# Copyright (c) 2009, 2010, 2012 Nicira, Inc. +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -13,45 +13,57 @@ # limitations under the License. import errno -import logging import sys import ovs.reconnect -def do_enable(arg): +now = 0 +r = None + + +def do_enable(_): r.enable(now) -def do_disable(arg): + +def do_disable(_): r.disable(now) -def do_force_reconnect(arg): + +def do_force_reconnect(_): r.force_reconnect(now) + def error_from_string(s): if not s: return 0 elif s == "ECONNREFUSED": return errno.ECONNREFUSED elif s == "EOF": - return EOF + return ovs.reconnect.EOF else: sys.stderr.write("unknown error '%s'\n" % s) sys.exit(1) + def do_disconnected(arg): r.disconnected(now, error_from_string(arg)) - -def do_connecting(arg): + + +def do_connecting(_): r.connecting(now) + def do_connect_failed(arg): r.connect_failed(now, error_from_string(arg)) -def do_connected(arg): + +def do_connected(_): r.connected(now) -def do_received(arg): - r.received(now) + +def do_activity(_): + r.activity(now) + def do_run(arg): global now @@ -70,11 +82,13 @@ def do_run(arg): else: assert False + def do_advance(arg): global now now += int(arg) -def do_timeout(arg): + +def do_timeout(_): global now timeout = r.timeout(now) if timeout >= 0: @@ -83,10 +97,12 @@ def do_timeout(arg): else: print " no timeout" + def do_set_max_tries(arg): r.set_max_tries(int(arg)) -def diff_stats(old, new): + +def diff_stats(old, new, delta): if (old.state != new.state or old.state_elapsed != new.state_elapsed or old.backoff != new.backoff): @@ -94,10 +110,10 @@ def diff_stats(old, new): % (new.state, new.state_elapsed, new.backoff)) if (old.creation_time != new.creation_time or - old.last_received != new.last_received or + old.last_activity != new.last_activity or old.last_connected != new.last_connected): - print(" created %d, last received %d, last connected %d" - % (new.creation_time, new.last_received, new.last_connected)) + print(" created %d, last activity %d, last connected %d" + % (new.creation_time, new.last_activity, new.last_connected)) if (old.n_successful_connections != new.n_successful_connections or old.n_attempted_connections != new.n_attempted_connections or @@ -106,33 +122,41 @@ def diff_stats(old, new): % (new.n_successful_connections, new.n_attempted_connections, new.seqno)) - if (old.is_connected != new.is_connected or - old.current_connection_duration != new.current_connection_duration or - old.total_connected_duration != new.total_connected_duration): + if (old.is_connected != new.is_connected): if new.is_connected: negate = "" else: - negate = "not " - print(" %sconnected (%d ms), total %d ms connected" - % (negate, new.current_connection_duration, - new.total_connected_duration)) - - if (old.last_disconnected != new.last_disconnected): + negate = "dis" + print(" %sconnected" % negate) + + if (old.last_connected != new.last_connected or + (new.msec_since_connect != None and + old.msec_since_connect != new.msec_since_connect - delta) or + (old.total_connected_duration != new.total_connected_duration - delta + and not (old.total_connected_duration == 0 and + new.total_connected_duration == 0))): + print(" last connected %d ms ago, connected %d ms total" + % (new.msec_since_connect, new.total_connected_duration)) + + if (old.last_disconnected != new.last_disconnected or + (new.msec_since_disconnect != None and + old.msec_since_disconnect != new.msec_since_disconnect - delta)): print(" disconnected at %d ms (%d ms ago)" - % (new.last_disconnected, new.current_disconnect_duration)) + % (new.last_disconnected, new.msec_since_disconnect)) - if (old.current_disconnect_duration != new.current_disconnect_duration): - print(" disconnected for %d ms" % (new.current_disconnect_duration)) -def do_set_passive(arg): +def do_set_passive(_): r.set_passive(True, now) -def do_listening(arg): + +def do_listening(_): r.listening(now) + def do_listen_error(arg): r.listen_error(now, int(arg)) + def main(): commands = { "enable": do_enable, @@ -142,7 +166,7 @@ def main(): "connecting": do_connecting, "connect-failed": do_connect_failed, "connected": do_connected, - "received": do_received, + "activity": do_activity, "run": do_run, "advance": do_advance, "timeout": do_timeout, @@ -152,8 +176,6 @@ def main(): "listen-error": do_listen_error } - logging.basicConfig(level=logging.CRITICAL) - global now global r @@ -187,16 +209,16 @@ def main(): if old_time != now: print print "### t=%d ###" % now - old_time = now cur = r.get_stats(now) - diff_stats(prev, cur) + diff_stats(prev, cur, now - old_time) prev = cur if r.get_max_tries() != old_max_tries: old_max_tries = r.get_max_tries() print " %d tries left" % old_max_tries -if __name__ == '__main__': - main() + old_time = now +if __name__ == '__main__': + main()