Skip to content

Commit

Permalink
reconnect: Rename reconnect_received() to reconnect_activity().
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
blp committed Sep 7, 2012
1 parent e0f3585 commit a6f639f
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 83 deletions.
2 changes: 1 addition & 1 deletion lib/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 16 additions & 16 deletions lib/reconnect.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()). */
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions lib/reconnect.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion python/ovs/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def recv(self):
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))
Expand Down
29 changes: 15 additions & 14 deletions python/ovs/reconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ class Active(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

@staticmethod
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

Expand Down Expand Up @@ -150,7 +150,7 @@ def __init__(self, now):
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
Expand Down Expand Up @@ -204,8 +204,8 @@ def get_probe_interval(self):
"""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

Expand Down Expand Up @@ -246,9 +246,9 @@ def set_probe_interval(self, probe_interval):
"""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
Expand Down Expand Up @@ -354,7 +354,7 @@ def disconnected(self, now, error):

# 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
Expand Down Expand Up @@ -426,7 +426,7 @@ def connected(self, now):
"""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()."""
Expand All @@ -444,12 +444,13 @@ def connect_failed(self, now, error):
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:
Expand Down Expand Up @@ -561,7 +562,7 @@ class Stats(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()
Expand Down
Loading

0 comments on commit a6f639f

Please sign in to comment.