From a6f639f8080fe18120bb205609c6e364f6de7e70 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 8 Aug 2012 13:32:57 -0700 Subject: [PATCH] reconnect: Rename reconnect_received() to reconnect_activity(). Receiving data is not the only reasonable way to verify that a connection is up. For example, on a TCP connection, receiving an acknowledgment that the remote side has accepted data that we sent is also a reasonable means. Therefore, this commit generalizes the naming. Also, similarly for the Python implementation: Reconnect.received() becomes Reconnect.activity(). Signed-off-by: Ben Pfaff --- lib/jsonrpc.c | 2 +- lib/reconnect.c | 32 +++++++++---------- lib/reconnect.h | 6 ++-- python/ovs/jsonrpc.py | 2 +- python/ovs/reconnect.py | 29 +++++++++--------- tests/reconnect.at | 68 ++++++++++++++++++++--------------------- tests/test-reconnect.c | 14 ++++----- tests/test-reconnect.py | 14 ++++----- 8 files changed, 84 insertions(+), 83 deletions(-) diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c index 57613697..c4d7dd2c 100644 --- a/lib/jsonrpc.c +++ b/lib/jsonrpc.c @@ -977,7 +977,7 @@ jsonrpc_session_recv(struct jsonrpc_session *s) struct jsonrpc_msg *msg; jsonrpc_recv(s->rpc, &msg); if (msg) { - reconnect_received(s->reconnect, time_msec()); + reconnect_activity(s->reconnect, time_msec()); if (msg->type == JSONRPC_REQUEST && !strcmp(msg->method, "echo")) { /* Echo request. Send reply. */ struct jsonrpc_msg *reply; diff --git a/lib/reconnect.c b/lib/reconnect.c index 0333d962..0f1e0627 100644 --- a/lib/reconnect.c +++ b/lib/reconnect.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010 Nicira, Inc. + * Copyright (c) 2008, 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. @@ -58,7 +58,7 @@ struct reconnect { enum state state; long long int state_entered; int backoff; - long long int last_received; + long long int last_activity; long long int last_connected; long long int last_disconnected; unsigned int max_tries; @@ -105,7 +105,7 @@ reconnect_create(long long int now) fsm->state = S_VOID; fsm->state_entered = now; fsm->backoff = 0; - fsm->last_received = now; + fsm->last_activity = now; fsm->last_connected = LLONG_MAX; fsm->last_disconnected = LLONG_MAX; fsm->max_tries = UINT_MAX; @@ -176,9 +176,9 @@ reconnect_get_max_backoff(const struct reconnect *fsm) /* Returns the "probe interval" for 'fsm' in milliseconds. If this is zero, it * disables the connection keepalive feature. If it is nonzero, then if the - * interval passes while 'fsm' is connected and without reconnect_received() + * interval passes while 'fsm' is connected and without reconnect_activity() * being called for 'fsm', reconnect_run() returns RECONNECT_PROBE. If the - * interval passes again without reconnect_received() being called, + * interval passes again without reconnect_activity() being called, * reconnect_run() returns RECONNECT_DISCONNECT for 'fsm'. */ int reconnect_get_probe_interval(const struct reconnect *fsm) @@ -233,8 +233,8 @@ reconnect_set_backoff(struct reconnect *fsm, int min_backoff, int max_backoff) /* Sets the "probe interval" for 'fsm' to 'probe_interval', in milliseconds. * If this is zero, it disables the connection keepalive feature. If it is * nonzero, then if the interval passes while 'fsm' is connected and without - * reconnect_received() being called for 'fsm', reconnect_run() returns - * RECONNECT_PROBE. If the interval passes again without reconnect_received() + * reconnect_activity() being called for 'fsm', reconnect_run() returns + * RECONNECT_PROBE. If the interval passes again without reconnect_activity() * being called, reconnect_run() returns RECONNECT_DISCONNECT for 'fsm'. * * If 'probe_interval' is nonzero, then it will be forced to a value of at @@ -360,7 +360,7 @@ reconnect_disconnected(struct reconnect *fsm, long long int now, int error) } /* Back off. */ if (fsm->state & (S_ACTIVE | S_IDLE) - && (fsm->last_received - fsm->last_connected >= fsm->backoff + && (fsm->last_activity - fsm->last_connected >= fsm->backoff || fsm->passive)) { fsm->backoff = fsm->passive ? 0 : fsm->min_backoff; } else { @@ -441,7 +441,7 @@ reconnect_listen_error(struct reconnect *fsm, long long int now, int error) /* Tell 'fsm' that the connection was successful. * * The FSM will start the probe interval timer, which is reset by - * reconnect_received(). If the timer expires, a probe will be sent (by + * reconnect_activity(). If the timer expires, a probe will be sent (by * returning RECONNECT_PROBE from reconnect_run()). If the timer expires * again without being reset, the connection will be aborted (by returning * RECONNECT_DISCONNECT from reconnect_run()). */ @@ -467,15 +467,15 @@ reconnect_connect_failed(struct reconnect *fsm, long long int now, int error) reconnect_disconnected(fsm, now, error); } -/* Tell 'fsm' that some data was received. This resets the probe interval - * timer, so that the connection is known not to be idle. */ +/* Tell 'fsm' that some activity has occurred on the connection. This resets + * the probe interval timer, so that the connection is known not to be idle. */ void -reconnect_received(struct reconnect *fsm, long long int now) +reconnect_activity(struct reconnect *fsm, long long int now) { if (fsm->state != S_ACTIVE) { reconnect_transition__(fsm, now, S_ACTIVE); } - fsm->last_received = now; + fsm->last_activity = now; } static void @@ -517,7 +517,7 @@ reconnect_deadline__(const struct reconnect *fsm) case S_ACTIVE: if (fsm->probe_interval) { - long long int base = MAX(fsm->last_received, fsm->state_entered); + long long int base = MAX(fsm->last_activity, fsm->state_entered); return base + fsm->probe_interval; } return LLONG_MAX; @@ -587,7 +587,7 @@ reconnect_run(struct reconnect *fsm, long long int now) case S_ACTIVE: VLOG_DBG("%s: idle %lld ms, sending inactivity probe", fsm->name, - now - MAX(fsm->last_received, fsm->state_entered)); + now - MAX(fsm->last_activity, fsm->state_entered)); reconnect_transition__(fsm, now, S_IDLE); return RECONNECT_PROBE; @@ -673,7 +673,7 @@ reconnect_get_stats(const struct reconnect *fsm, long long int now, struct reconnect_stats *stats) { stats->creation_time = fsm->creation_time; - stats->last_received = fsm->last_received; + stats->last_activity = fsm->last_activity; stats->last_connected = fsm->last_connected; stats->last_disconnected = fsm->last_disconnected; stats->backoff = fsm->backoff; diff --git a/lib/reconnect.h b/lib/reconnect.h index e935d0af..4446713c 100644 --- a/lib/reconnect.h +++ b/lib/reconnect.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 Nicira, Inc. + * 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. @@ -79,7 +79,7 @@ void reconnect_listen_error(struct reconnect *, long long int now, int error); void reconnect_connected(struct reconnect *, long long int now); void reconnect_connect_failed(struct reconnect *, long long int now, int error); -void reconnect_received(struct reconnect *, long long int now); +void reconnect_activity(struct reconnect *, long long int now); enum reconnect_action { RECONNECT_CONNECT = 1, @@ -93,7 +93,7 @@ int reconnect_timeout(struct reconnect *, long long int now); struct reconnect_stats { /* All times and durations in this structure are in milliseconds. */ long long int creation_time; /* Time reconnect_create() called. */ - long long int last_received; /* Last call to reconnect_received(). */ + long long int last_activity; /* Last call to reconnect_activity(). */ long long int last_connected; /* Last call to reconnect_connected(). */ long long int last_disconnected; /* Last call to reconnect_disconnected(). */ int backoff; /* Current backoff duration. */ diff --git a/python/ovs/jsonrpc.py b/python/ovs/jsonrpc.py index a054401b..cb471cb5 100644 --- a/python/ovs/jsonrpc.py +++ b/python/ovs/jsonrpc.py @@ -504,7 +504,7 @@ class Session(object): if self.rpc is not None: error, msg = self.rpc.recv() if not error: - self.reconnect.received(ovs.timeval.msec()) + self.reconnect.activity(ovs.timeval.msec()) if msg.type == Message.T_REQUEST and msg.method == "echo": # Echo request. Send reply. self.send(Message.create_reply(msg.params, msg.id)) diff --git a/python/ovs/reconnect.py b/python/ovs/reconnect.py index 45995730..39dd556d 100644 --- a/python/ovs/reconnect.py +++ b/python/ovs/reconnect.py @@ -94,7 +94,7 @@ class Reconnect(object): @staticmethod def deadline(fsm): if fsm.probe_interval: - base = max(fsm.last_received, fsm.state_entered) + base = max(fsm.last_activity, fsm.state_entered) return base + fsm.probe_interval return None @@ -102,7 +102,7 @@ class Reconnect(object): def run(fsm, now): vlog.dbg("%s: idle %d ms, sending inactivity probe" % (fsm.name, - now - max(fsm.last_received, fsm.state_entered))) + now - max(fsm.last_activity, fsm.state_entered))) fsm._transition(now, Reconnect.Idle) return PROBE @@ -150,7 +150,7 @@ class Reconnect(object): self.state = Reconnect.Void self.state_entered = now self.backoff = 0 - self.last_received = now + self.last_activity = now self.last_connected = None self.last_disconnected = None self.max_tries = None @@ -204,8 +204,8 @@ class Reconnect(object): """Returns the "probe interval" in milliseconds. If this is zero, it disables the connection keepalive feature. If it is nonzero, then if the interval passes while the FSM is connected and without - self.received() being called, self.run() returns ovs.reconnect.PROBE. - If the interval passes again without self.received() being called, + self.activity() being called, self.run() returns ovs.reconnect.PROBE. + If the interval passes again without self.activity() being called, self.run() returns ovs.reconnect.DISCONNECT.""" return self.probe_interval @@ -246,9 +246,9 @@ class Reconnect(object): """Sets the "probe interval" to 'probe_interval', in milliseconds. If this is zero, it disables the connection keepalive feature. If it is nonzero, then if the interval passes while this FSM is connected and - without self.received() being called, self.run() returns + without self.activity() being called, self.run() returns ovs.reconnect.PROBE. If the interval passes again without - self.received() being called, self.run() returns + self.activity() being called, self.run() returns ovs.reconnect.DISCONNECT. If 'probe_interval' is nonzero, then it will be forced to a value of at @@ -354,7 +354,7 @@ class Reconnect(object): # Back off if (self.state in (Reconnect.Active, Reconnect.Idle) and - (self.last_received - self.last_connected >= self.backoff or + (self.last_activity - self.last_connected >= self.backoff or self.passive)): if self.passive: self.backoff = 0 @@ -426,7 +426,7 @@ class Reconnect(object): """Tell this FSM that the connection was successful. The FSM will start the probe interval timer, which is reset by - self.received(). If the timer expires, a probe will be sent (by + self.activity(). If the timer expires, a probe will be sent (by returning ovs.reconnect.PROBE from self.run(). If the timer expires again without being reset, the connection will be aborted (by returning ovs.reconnect.DISCONNECT from self.run().""" @@ -444,12 +444,13 @@ class Reconnect(object): self.connecting(now) self.disconnected(now, error) - def received(self, now): - """Tell this FSM that some data was received. This resets the probe - interval timer, so that the connection is known not to be idle.""" + def activity(self, now): + """Tell this FSM that some activity occurred on the connection. This + resets the probe interval timer, so that the connection is known not to + be idle.""" if self.state != Reconnect.Active: self._transition(now, Reconnect.Active) - self.last_received = now + self.last_activity = now def _transition(self, now, state): if self.state == Reconnect.ConnectInProgress: @@ -561,7 +562,7 @@ class Reconnect(object): stats.creation_time = self.creation_time stats.last_connected = self.last_connected stats.last_disconnected = self.last_disconnected - stats.last_received = self.last_received + stats.last_activity = self.last_activity stats.backoff = self.backoff stats.seqno = self.seqno stats.is_connected = self.is_connected() diff --git a/tests/reconnect.at b/tests/reconnect.at index bb37170e..551e8a3e 100644 --- a/tests/reconnect.at +++ b/tests/reconnect.at @@ -59,7 +59,7 @@ run should connect connected in ACTIVE for 0 ms (0 ms backoff) - created 1000, last received 1000, last connected 1000 + created 1000, last activity 1000, last connected 1000 1 successful connections out of 1 attempts, seqno 1 connected last connected 0 ms ago, connected 0 ms total @@ -129,7 +129,7 @@ advance 500 run connected in ACTIVE for 0 ms (0 ms backoff) - created 1000, last received 1000, last connected 1500 + created 1000, last activity 1000, last connected 1500 1 successful connections out of 1 attempts, seqno 1 connected last connected 0 ms ago, connected 0 ms total @@ -408,7 +408,7 @@ run should connect connected in ACTIVE for 0 ms (0 ms backoff) - created 1000, last received 1000, last connected 1000 + created 1000, last activity 1000, last connected 1000 1 successful connections out of 1 attempts, seqno 1 connected last connected 0 ms ago, connected 0 ms total @@ -448,7 +448,7 @@ run should connect connected in ACTIVE for 0 ms (1000 ms backoff) - created 1000, last received 1000, last connected 12000 + created 1000, last activity 1000, last connected 12000 2 successful connections out of 2 attempts, seqno 3 connected last connected 0 ms ago, connected 10000 ms total @@ -488,7 +488,7 @@ run should connect connected in ACTIVE for 0 ms (2000 ms backoff) - created 1000, last received 1000, last connected 24000 + created 1000, last activity 1000, last connected 24000 3 successful connections out of 3 attempts, seqno 5 connected last connected 0 ms ago, connected 20000 ms total @@ -625,7 +625,7 @@ advance 500 run connected in ACTIVE for 0 ms (2000 ms backoff) - created 1000, last received 1000, last connected 6500 + created 1000, last activity 1000, last connected 6500 1 successful connections out of 3 attempts, seqno 1 connected last connected 0 ms ago, connected 0 ms total @@ -688,13 +688,13 @@ connected # Connection receives 3 chunks of data spaced 250 ms apart. advance 250 run -received +activity advance 250 run -received +activity advance 250 run -received +activity # Connection drops. disconnected @@ -767,7 +767,7 @@ advance 500 run connected in ACTIVE for 0 ms (2000 ms backoff) - created 1000, last received 1000, last connected 6500 + created 1000, last activity 1000, last connected 6500 1 successful connections out of 3 attempts, seqno 1 connected last connected 0 ms ago, connected 0 ms total @@ -778,22 +778,22 @@ advance 250 ### t=6750 ### in ACTIVE for 250 ms (2000 ms backoff) run -received - created 1000, last received 6750, last connected 6500 +activity + created 1000, last activity 6750, last connected 6500 advance 250 ### t=7000 ### in ACTIVE for 500 ms (2000 ms backoff) run -received - created 1000, last received 7000, last connected 6500 +activity + created 1000, last activity 7000, last connected 6500 advance 250 ### t=7250 ### in ACTIVE for 750 ms (2000 ms backoff) run -received - created 1000, last received 7250, last connected 6500 +activity + created 1000, last activity 7250, last connected 6500 # Connection drops. disconnected @@ -849,13 +849,13 @@ connected # Connection receives 3 chunks of data spaced 2000 ms apart. advance 2000 run -received +activity advance 2000 run -received +activity advance 2000 run -received +activity # Connection drops. disconnected @@ -928,7 +928,7 @@ advance 500 run connected in ACTIVE for 0 ms (2000 ms backoff) - created 1000, last received 1000, last connected 6500 + created 1000, last activity 1000, last connected 6500 1 successful connections out of 3 attempts, seqno 1 connected last connected 0 ms ago, connected 0 ms total @@ -939,22 +939,22 @@ advance 2000 ### t=8500 ### in ACTIVE for 2000 ms (2000 ms backoff) run -received - created 1000, last received 8500, last connected 6500 +activity + created 1000, last activity 8500, last connected 6500 advance 2000 ### t=10500 ### in ACTIVE for 4000 ms (2000 ms backoff) run -received - created 1000, last received 10500, last connected 6500 +activity + created 1000, last activity 10500, last connected 6500 advance 2000 ### t=12500 ### in ACTIVE for 6000 ms (2000 ms backoff) run -received - created 1000, last received 12500, last connected 6500 +activity + created 1000, last activity 12500, last connected 6500 # Connection drops. disconnected @@ -1060,7 +1060,7 @@ run should connect connected in ACTIVE for 0 ms (0 ms backoff) - created 1000, last received 1000, last connected 1000 + created 1000, last activity 1000, last connected 1000 1 successful connections out of 1 attempts, seqno 1 connected last connected 0 ms ago, connected 0 ms total @@ -1128,9 +1128,9 @@ listening # Connection accepted. connected -received +activity advance 1000 -received +activity # Connection times out. timeout @@ -1178,18 +1178,18 @@ listening # Connection accepted. connected in ACTIVE for 0 ms (1000 ms backoff) - created 1000, last received 1000, last connected 2000 + created 1000, last activity 1000, last connected 2000 1 successful connections out of 1 attempts, seqno 1 connected last connected 0 ms ago, connected 0 ms total -received - created 1000, last received 2000, last connected 2000 +activity + created 1000, last activity 2000, last connected 2000 advance 1000 ### t=3000 ### in ACTIVE for 1000 ms (1000 ms backoff) -received - created 1000, last received 3000, last connected 2000 +activity + created 1000, last activity 3000, last connected 2000 # Connection times out. timeout diff --git a/tests/test-reconnect.c b/tests/test-reconnect.c index 14569dba..020ae482 100644 --- a/tests/test-reconnect.c +++ b/tests/test-reconnect.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011 Nicira, Inc. + * Copyright (c) 2009, 2010, 2011, 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. @@ -148,9 +148,9 @@ do_connected(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) } static void -do_received(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) +do_activity(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { - reconnect_received(reconnect, now); + reconnect_activity(reconnect, now); } static void @@ -220,10 +220,10 @@ diff_stats(const struct reconnect_stats *old, new->state, new->state_elapsed, new->backoff); } if (old->creation_time != new->creation_time - || old->last_received != new->last_received + || old->last_activity != new->last_activity || old->last_connected != new->last_connected) { - printf(" created %lld, last received %lld, last connected %lld\n", - new->creation_time, new->last_received, new->last_connected); + printf(" created %lld, last activity %lld, last connected %lld\n", + new->creation_time, new->last_activity, new->last_connected); } if (old->n_successful_connections != new->n_successful_connections || old->n_attempted_connections != new->n_attempted_connections @@ -280,7 +280,7 @@ static const struct command commands[] = { { "connecting", 0, 0, do_connecting }, { "connect-failed", 0, 1, do_connect_failed }, { "connected", 0, 0, do_connected }, - { "received", 0, 0, do_received }, + { "activity", 0, 0, do_activity }, { "run", 0, 1, do_run }, { "advance", 1, 1, do_advance }, { "timeout", 0, 0, do_timeout }, diff --git a/tests/test-reconnect.py b/tests/test-reconnect.py index 44b4723a..c478c2a9 100644 --- a/tests/test-reconnect.py +++ b/tests/test-reconnect.py @@ -1,4 +1,4 @@ -# Copyright (c) 2009, 2010 Nicira, Inc. +# 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. @@ -61,8 +61,8 @@ def do_connected(_): r.connected(now) -def do_received(_): - r.received(now) +def do_activity(_): + r.activity(now) def do_run(arg): @@ -110,10 +110,10 @@ def diff_stats(old, new, delta): % (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 @@ -166,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, -- 2.30.2