From fa05809b7238ad2db6046ef23d02007f8e7beefc Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 18 Jun 2010 13:58:42 -0700 Subject: [PATCH] vswitch: Implement unixctl command to reconnect OpenFlow connections. This feature may be useful for debugging. Feature #2222. --- ofproto/ofproto.c | 18 +++++++++++++----- ofproto/ofproto.h | 1 + vswitchd/bridge.c | 26 ++++++++++++++++++++++++++ vswitchd/ovs-vswitchd.8.in | 6 ++++++ 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 4c4df9493..481d50b84 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -414,15 +414,11 @@ ofproto_set_datapath_id(struct ofproto *p, uint64_t datapath_id) uint64_t old_dpid = p->datapath_id; p->datapath_id = datapath_id ? datapath_id : pick_datapath_id(p); if (p->datapath_id != old_dpid) { - struct ofconn *ofconn; - VLOG_INFO("datapath ID changed to %016"PRIx64, p->datapath_id); /* Force all active connections to reconnect, since there is no way to * notify a controller that the datapath ID has changed. */ - LIST_FOR_EACH (ofconn, struct ofconn, node, &p->all_conns) { - rconn_reconnect(ofconn->rconn); - } + ofproto_reconnect_controllers(p); } } @@ -667,6 +663,18 @@ ofproto_set_controllers(struct ofproto *p, } } +/* Drops the connections between 'ofproto' and all of its controllers, forcing + * them to reconnect. */ +void +ofproto_reconnect_controllers(struct ofproto *ofproto) +{ + struct ofconn *ofconn; + + LIST_FOR_EACH (ofconn, struct ofconn, node, &ofproto->all_conns) { + rconn_reconnect(ofconn->rconn); + } +} + static bool any_extras_changed(const struct ofproto *ofproto, const struct sockaddr_in *extras, size_t n) diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h index c3d71e8d1..9880e8250 100644 --- a/ofproto/ofproto.h +++ b/ofproto/ofproto.h @@ -104,6 +104,7 @@ bool ofproto_is_alive(const struct ofproto *); void ofproto_set_datapath_id(struct ofproto *, uint64_t datapath_id); void ofproto_set_controllers(struct ofproto *, const struct ofproto_controller *, size_t n); +void ofproto_reconnect_controllers(struct ofproto *); void ofproto_set_extra_in_band_remotes(struct ofproto *, const struct sockaddr_in *, size_t n); void ofproto_set_desc(struct ofproto *, diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 3768eb9c6..d4a08b92f 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -195,6 +195,7 @@ static struct bridge *bridge_create(const struct ovsrec_bridge *br_cfg); static void bridge_destroy(struct bridge *); static struct bridge *bridge_lookup(const char *name); static unixctl_cb_func bridge_unixctl_dump_flows; +static unixctl_cb_func bridge_unixctl_reconnect; static int bridge_run_one(struct bridge *); static size_t bridge_get_controllers(const struct ovsrec_open_vswitch *ovs_cfg, const struct bridge *br, @@ -272,6 +273,8 @@ bridge_init(const char *remote) unixctl_command_register("fdb/show", bridge_unixctl_fdb_show, NULL); unixctl_command_register("bridge/dump-flows", bridge_unixctl_dump_flows, NULL); + unixctl_command_register("bridge/reconnect", bridge_unixctl_reconnect, + NULL); bond_init(); } @@ -1353,6 +1356,29 @@ bridge_unixctl_dump_flows(struct unixctl_conn *conn, ds_destroy(&results); } +/* "bridge/reconnect [BRIDGE]": makes BRIDGE drop all of its controller + * connections and reconnect. If BRIDGE is not specified, then all bridges + * drop their controller connections and reconnect. */ +static void +bridge_unixctl_reconnect(struct unixctl_conn *conn, + const char *args, void *aux OVS_UNUSED) +{ + struct bridge *br; + if (args[0] != '\0') { + br = bridge_lookup(args); + if (!br) { + unixctl_command_reply(conn, 501, "Unknown bridge"); + return; + } + ofproto_reconnect_controllers(br->ofproto); + } else { + LIST_FOR_EACH (br, struct bridge, node, &all_bridges) { + ofproto_reconnect_controllers(br->ofproto); + } + } + unixctl_command_reply(conn, 200, NULL); +} + static int bridge_run_one(struct bridge *br) { diff --git a/vswitchd/ovs-vswitchd.8.in b/vswitchd/ovs-vswitchd.8.in index 0e5d3188e..79f17d3db 100644 --- a/vswitchd/ovs-vswitchd.8.in +++ b/vswitchd/ovs-vswitchd.8.in @@ -118,6 +118,12 @@ These commands manage bridges. Lists each MAC address/VLAN pair learned by the specified \fIbridge\fR, along with the port on which it was learned and the age of the entry, in seconds. +.IP "\fBbridge/reconnect\fR [\fIbridge\fR]" +Makes \fIbridge\fR drop all of its OpenFlow controller connections and +reconnect. If \fIbridge\fR is not specified, then all bridges drop +their controller connections and reconnect. +.IP +This command might be useful for debugging OpenFlow controller issues. . .IP "\fBbridge/dump-flows\fR \fIbridge\fR" Lists all flows in \fIbridge\fR, including those normally hidden to -- 2.43.0