mirror of
https://github.com/openvswitch/ovs
synced 2025-09-03 15:55:19 +00:00
netdev-dummy: Fix reconnecting.
The netdev-dummy unit test ran into the reconnect condition on Jarno's machine. With his test environment, we found and fixed the bugs in handling reconnect. Co-authored-by: Jarno Rajahalme <jrajahalme@nicira.com> Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Signed-off-by: Andy Zhou <azhou@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
This commit is contained in:
@@ -198,6 +198,7 @@ dummy_packet_stream_run(struct netdev_dummy *dev, struct dummy_packet_stream *s)
|
|||||||
|
|
||||||
txbuf = ofpbuf_from_list(list_front(&s->txq));
|
txbuf = ofpbuf_from_list(list_front(&s->txq));
|
||||||
retval = stream_send(s->stream, txbuf->data, txbuf->size);
|
retval = stream_send(s->stream, txbuf->data, txbuf->size);
|
||||||
|
|
||||||
if (retval > 0) {
|
if (retval > 0) {
|
||||||
ofpbuf_pull(txbuf, retval);
|
ofpbuf_pull(txbuf, retval);
|
||||||
if (!txbuf->size) {
|
if (!txbuf->size) {
|
||||||
@@ -229,6 +230,7 @@ dummy_packet_stream_run(struct netdev_dummy *dev, struct dummy_packet_stream *s)
|
|||||||
|
|
||||||
ofpbuf_prealloc_tailroom(&s->rxbuf, n);
|
ofpbuf_prealloc_tailroom(&s->rxbuf, n);
|
||||||
retval = stream_recv(s->stream, ofpbuf_tail(&s->rxbuf), n);
|
retval = stream_recv(s->stream, ofpbuf_tail(&s->rxbuf), n);
|
||||||
|
|
||||||
if (retval > 0) {
|
if (retval > 0) {
|
||||||
s->rxbuf.size += retval;
|
s->rxbuf.size += retval;
|
||||||
if (retval == n && s->rxbuf.size > 2) {
|
if (retval == n && s->rxbuf.size > 2) {
|
||||||
@@ -370,23 +372,24 @@ dummy_packet_conn_set_config(struct dummy_packet_conn *conn,
|
|||||||
reconnect_set_backoff(reconnect, 1000, INT_MAX);
|
reconnect_set_backoff(reconnect, 1000, INT_MAX);
|
||||||
reconnect_set_probe_interval(reconnect, 0);
|
reconnect_set_probe_interval(reconnect, 0);
|
||||||
conn->u.rconn.reconnect = reconnect;
|
conn->u.rconn.reconnect = reconnect;
|
||||||
|
conn->type = ACTIVE;
|
||||||
|
|
||||||
error = stream_open(stream, &active_stream, DSCP_DEFAULT);
|
error = stream_open(stream, &active_stream, DSCP_DEFAULT);
|
||||||
conn->u.rconn.rstream = dummy_packet_stream_create(active_stream);
|
conn->u.rconn.rstream = dummy_packet_stream_create(active_stream);
|
||||||
|
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case 0:
|
case 0:
|
||||||
reconnect_connected(conn->u.rconn.reconnect, time_msec());
|
reconnect_connected(reconnect, time_msec());
|
||||||
conn->type = ACTIVE;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EAGAIN:
|
case EAGAIN:
|
||||||
reconnect_connecting(conn->u.rconn.reconnect, time_msec());
|
reconnect_connecting(reconnect, time_msec());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
reconnect_connecting(conn->u.rconn.reconnect, time_msec());
|
reconnect_connect_failed(reconnect, time_msec(), error);
|
||||||
stream_close(active_stream);
|
stream_close(active_stream);
|
||||||
|
conn->u.rconn.rstream->stream = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -441,22 +444,29 @@ OVS_REQUIRES(dev->mutex)
|
|||||||
switch (reconnect_run(rconn->reconnect, time_msec())) {
|
switch (reconnect_run(rconn->reconnect, time_msec())) {
|
||||||
case RECONNECT_CONNECT:
|
case RECONNECT_CONNECT:
|
||||||
{
|
{
|
||||||
int err = stream_connect(rconn->rstream->stream);
|
int error;
|
||||||
|
|
||||||
switch (err) {
|
if (rconn->rstream->stream) {
|
||||||
case 0: /* Connected. */
|
error = stream_connect(rconn->rstream->stream);
|
||||||
|
} else {
|
||||||
|
error = stream_open(reconnect_get_name(rconn->reconnect),
|
||||||
|
&rconn->rstream->stream, DSCP_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (error) {
|
||||||
|
case 0:
|
||||||
reconnect_connected(rconn->reconnect, time_msec());
|
reconnect_connected(rconn->reconnect, time_msec());
|
||||||
dev->conn.type = ACTIVE;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EAGAIN:
|
case EAGAIN:
|
||||||
reconnect_connecting(rconn->reconnect, time_msec());
|
reconnect_connecting(rconn->reconnect, time_msec());
|
||||||
return;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
reconnect_connect_failed(rconn->reconnect, time_msec(), err);
|
reconnect_connect_failed(rconn->reconnect, time_msec(), error);
|
||||||
stream_close(rconn->rstream->stream);
|
stream_close(rconn->rstream->stream);
|
||||||
return;
|
rconn->rstream->stream = NULL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -475,6 +485,7 @@ OVS_REQUIRES(dev->mutex)
|
|||||||
if (err) {
|
if (err) {
|
||||||
reconnect_disconnected(rconn->reconnect, time_msec(), err);
|
reconnect_disconnected(rconn->reconnect, time_msec(), err);
|
||||||
stream_close(rconn->rstream->stream);
|
stream_close(rconn->rstream->stream);
|
||||||
|
rconn->rstream->stream = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -511,7 +522,9 @@ dummy_packet_conn_wait(struct dummy_packet_conn *conn)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ACTIVE:
|
case ACTIVE:
|
||||||
dummy_packet_stream_wait(conn->u.rconn.rstream);
|
if (reconnect_is_connected(conn->u.rconn.reconnect)) {
|
||||||
|
dummy_packet_stream_wait(conn->u.rconn.rstream);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NONE:
|
case NONE:
|
||||||
@@ -537,8 +550,10 @@ dummy_packet_conn_send(struct dummy_packet_conn *conn,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTIVE:
|
case ACTIVE:
|
||||||
dummy_packet_stream_send(conn->u.rconn.rstream, buffer, size);
|
if (reconnect_is_connected(conn->u.rconn.reconnect)) {
|
||||||
dummy_packet_stream_wait(conn->u.rconn.rstream);
|
dummy_packet_stream_send(conn->u.rconn.rstream, buffer, size);
|
||||||
|
dummy_packet_stream_wait(conn->u.rconn.rstream);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NONE:
|
case NONE:
|
||||||
|
@@ -348,7 +348,7 @@ reconnect_disconnected(struct reconnect *fsm, long long int now, int error)
|
|||||||
} else {
|
} else {
|
||||||
const char *type = fsm->passive ? "listen" : "connection";
|
const char *type = fsm->passive ? "listen" : "connection";
|
||||||
if (error > 0) {
|
if (error > 0) {
|
||||||
VLOG_WARN("%s: %s attempt failed (%s)",
|
VLOG_INFO("%s: %s attempt failed (%s)",
|
||||||
fsm->name, type, ovs_strerror(error));
|
fsm->name, type, ovs_strerror(error));
|
||||||
} else {
|
} else {
|
||||||
VLOG(fsm->info, "%s: %s attempt timed out", fsm->name, type);
|
VLOG(fsm->info, "%s: %s attempt timed out", fsm->name, type);
|
||||||
|
Reference in New Issue
Block a user