From 00a250d2a69ab369fb01054a8cf9b33f6be7bb0b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 29 Nov 2010 12:39:55 -0800 Subject: [PATCH] ovs-openflowd: Add "exit" unixctl command. This is useful for testing. --- utilities/ovs-openflowd.8.in | 4 ++++ utilities/ovs-openflowd.c | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/utilities/ovs-openflowd.8.in b/utilities/ovs-openflowd.8.in index 7be70273..fcca9810 100644 --- a/utilities/ovs-openflowd.8.in +++ b/utilities/ovs-openflowd.8.in @@ -442,6 +442,10 @@ switching. \fBovs\-appctl\fR(8) can send commands to a running \fBovs\-openflowd\fR process. The currently supported commands are described below. +.SS "OVS\-OPENFLOWD COMMANDS" +These commands are specific to \fBovs\-openflowd\fR. +.IP "\fBexit\fR" +Causes \fBovs\-openflowd\fR to gracefully terminate. .so lib/vlog-unixctl.man . .SH "SEE ALSO" diff --git a/utilities/ovs-openflowd.c b/utilities/ovs-openflowd.c index d0b90a09..153267f3 100644 --- a/utilities/ovs-openflowd.c +++ b/utilities/ovs-openflowd.c @@ -82,6 +82,8 @@ struct ofsettings { struct svec netflow; /* NetFlow targets. */ }; +static unixctl_cb_func ovs_openflowd_exit; + static void parse_options(int argc, char *argv[], struct ofsettings *); static void usage(void) NO_RETURN; @@ -94,6 +96,7 @@ main(int argc, char *argv[]) int error; struct dpif *dpif; struct netflow_options nf_options; + bool exiting; proctitle_init(argc, argv); set_program_name(argv[0]); @@ -109,6 +112,8 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } + unixctl_command_register("exit", ovs_openflowd_exit, &exiting); + VLOG_INFO("Open vSwitch version %s", VERSION BUILDNR); VLOG_INFO("OpenFlow protocol version 0x%02x", OFP_VERSION); @@ -156,7 +161,8 @@ main(int argc, char *argv[]) daemonize_complete(); - while (s.run_forever || ofproto_is_alive(ofproto)) { + exiting = false; + while (!exiting && (s.run_forever || ofproto_is_alive(ofproto))) { error = ofproto_run(ofproto); if (error) { ovs_fatal(error, "unrecoverable datapath error"); @@ -169,6 +175,9 @@ main(int argc, char *argv[]) unixctl_server_wait(unixctl); dp_wait(); netdev_wait(); + if (exiting) { + poll_immediate_wake(); + } poll_block(); } @@ -176,6 +185,15 @@ main(int argc, char *argv[]) return 0; } + +static void +ovs_openflowd_exit(struct unixctl_conn *conn, const char *args OVS_UNUSED, + void *exiting_) +{ + bool *exiting = exiting_; + *exiting = true; + unixctl_command_reply(conn, 200, NULL); +} /* User interface. */ -- 2.30.2