From 3c5ac64f3e6b8636e510016f185b98acfa3ba90e Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 2 Mar 2009 14:27:10 -0800 Subject: [PATCH] secchan: Make secchan into a library. --- secchan/automake.mk | 20 +++----- secchan/discovery.c | 1 - secchan/executer.c | 1 - secchan/{secchan.c => main.c} | 7 ++- secchan/netflow.c | 1 - secchan/ofproto.c | 3 +- secchan/ofproto.h | 62 ++++++++++++++++++++-- secchan/pinsched.c | 1 - secchan/secchan.h | 96 ----------------------------------- secchan/status.c | 6 +-- secchan/status.h | 4 +- 11 files changed, 74 insertions(+), 128 deletions(-) rename secchan/{secchan.c => main.c} (98%) delete mode 100644 secchan/secchan.h diff --git a/secchan/automake.mk b/secchan/automake.mk index 76a279dd..d3e4e819 100644 --- a/secchan/automake.mk +++ b/secchan/automake.mk @@ -1,11 +1,15 @@ bin_PROGRAMS += secchan/secchan man_MANS += secchan/secchan.8 -# secchan/stp-secchan.c \ -# secchan/stp-secchan.h -# +secchan_secchan_SOURCES = secchan/main.c +secchan_secchan_LDADD = \ + secchan/libsecchan.a \ + lib/libopenflow.a \ + $(FAULT_LIBS) \ + $(SSL_LIBS) -secchan_secchan_SOURCES = \ +noinst_LIBRARIES += secchan/libsecchan.a +secchan_libsecchan_a_SOURCES = \ secchan/discovery.c \ secchan/discovery.h \ secchan/executer.c \ @@ -22,16 +26,8 @@ secchan_secchan_SOURCES = \ secchan/pktbuf.h \ secchan/pinsched.c \ secchan/pinsched.h \ - secchan/secchan.c \ - secchan/secchan.h \ secchan/status.c \ secchan/status.h -#if SUPPORT_SNAT -#secchan_secchan_SOURCES += \ -# secchan/snat.c \ -# secchan/snat.h -#endif -secchan_secchan_LDADD = lib/libopenflow.a $(FAULT_LIBS) $(SSL_LIBS) EXTRA_DIST += secchan/secchan.8.in DISTCLEANFILES += secchan/secchan.8 diff --git a/secchan/discovery.c b/secchan/discovery.c index 105614ff..42f40f14 100644 --- a/secchan/discovery.c +++ b/secchan/discovery.c @@ -43,7 +43,6 @@ #include "netdev.h" #include "openflow/openflow.h" #include "packets.h" -#include "secchan.h" #include "status.h" #define THIS_MODULE VLM_discovery diff --git a/secchan/executer.c b/secchan/executer.c index b235862b..5f59832c 100644 --- a/secchan/executer.c +++ b/secchan/executer.c @@ -50,7 +50,6 @@ #include "openflow/openflow.h" #include "poll-loop.h" #include "rconn.h" -#include "secchan.h" #include "socket-util.h" #include "util.h" #include "vconn.h" diff --git a/secchan/secchan.c b/secchan/main.c similarity index 98% rename from secchan/secchan.c rename to secchan/main.c index 3411e4ea..18a591fb 100644 --- a/secchan/secchan.c +++ b/secchan/main.c @@ -32,7 +32,6 @@ */ #include -#include "secchan.h" #include #include #include @@ -73,7 +72,7 @@ #define THIS_MODULE VLM_secchan static void reconfigure(struct ofproto *); -static void parse_options(int argc, char *argv[], struct settings *); +static void parse_options(int argc, char *argv[], struct ofsettings *); static void usage(void) NO_RETURN; int @@ -81,7 +80,7 @@ main(int argc, char *argv[]) { struct signal *sighup; struct ofproto *ofproto; - struct settings s; + struct ofsettings s; int retval; set_program_name(argv[0]); @@ -135,7 +134,7 @@ reconfigure(struct ofproto *ofproto) /* User interface. */ static void -parse_options(int argc, char *argv[], struct settings *s) +parse_options(int argc, char *argv[], struct ofsettings *s) { enum { OPT_DATAPATH_ID = UCHAR_MAX + 1, diff --git a/secchan/netflow.c b/secchan/netflow.c index 193109c4..c08b3d8c 100644 --- a/secchan/netflow.c +++ b/secchan/netflow.c @@ -41,7 +41,6 @@ #include "flow.h" #include "netflow.h" #include "packets.h" -#include "secchan.h" #include "socket-util.h" #include "svec.h" #include "timeval.h" diff --git a/secchan/ofproto.c b/secchan/ofproto.c index 1485e453..f61a35f1 100644 --- a/secchan/ofproto.c +++ b/secchan/ofproto.c @@ -57,7 +57,6 @@ #include "poll-loop.h" #include "port-array.h" #include "rconn.h" -#include "secchan.h" #include "shash.h" #include "status.h" #include "svec.h" @@ -194,7 +193,7 @@ static uint16_t odp_port_to_ofp_port(uint16_t odp_port); static uint16_t ofp_port_to_odp_port(uint16_t ofp_port); struct ofproto * -ofproto_create(const struct settings *settings) +ofproto_create(const struct ofsettings *settings) { struct dpifmon *dpifmon; struct rconn *controller; diff --git a/secchan/ofproto.h b/secchan/ofproto.h index df0acd8b..a9351c92 100644 --- a/secchan/ofproto.h +++ b/secchan/ofproto.h @@ -34,14 +34,66 @@ #ifndef OFPROTO_H #define OFPROTO_H 1 +#include +#include #include "flow.h" -struct dpif; -struct ofproto; -struct settings; -struct switch_status; +/* Behavior when the connection to the controller fails. */ +enum fail_mode { + FAIL_OPEN, /* Act as learning switch. */ + FAIL_CLOSED /* Drop all packets. */ +}; -struct ofproto *ofproto_create(const struct settings *); +/* Maximum number of management connection listeners. */ +#define MAX_MGMT 8 + +/* Settings that may be configured by the user. */ +struct ofsettings { + /* Configuration. */ + const char *br_name; /* Bridge name to use for configuration lookup */ + + /* Overall mode of operation. */ + bool discovery; /* Discover the controller automatically? */ + bool in_band; /* Connect to controller in-band? */ + + /* Datapath. */ + uint64_t datapath_id; /* Datapath ID. */ + const char *dp_name; /* Name of local datapath. */ + + /* Description strings. */ + const char *mfr_desc; /* Manufacturer. */ + const char *hw_desc; /* Hardware. */ + const char *sw_desc; /* Software version. */ + const char *serial_desc; /* Serial number. */ + + /* Related vconns and network devices. */ + const char *controller_name; /* Controller (if not discovery mode). */ + const char *listener_names[MAX_MGMT]; /* Listen for mgmt connections. */ + size_t n_listeners; /* Number of mgmt connection listeners. */ + + /* Failure behavior. */ + enum fail_mode fail_mode; /* Act as learning switch if no controller? */ + int max_idle; /* Idle time for flows in fail-open mode. */ + int probe_interval; /* # seconds idle before sending echo request. */ + int max_backoff; /* Max # seconds between connection attempts. */ + + /* Packet-in rate-limiting. */ + int rate_limit; /* Tokens added to bucket per second. */ + int burst_limit; /* Maximum number token bucket size. */ + + /* Discovery behavior. */ + const char *accept_controller_re; /* Controller vconns to accept. */ + bool update_resolv_conf; /* Update /etc/resolv.conf? */ + + /* Spanning tree protocol. */ + bool enable_stp; + + /* Remote command execution. */ + char *command_acl; /* Command white/blacklist, as shell globs. */ + char *command_dir; /* Directory that contains commands. */ +}; + +struct ofproto *ofproto_create(const struct ofsettings *); void ofproto_reconfigure(struct ofproto *); void ofproto_run(struct ofproto *); void ofproto_wait(struct ofproto *); diff --git a/secchan/pinsched.c b/secchan/pinsched.c index fd877e43..31254fb9 100644 --- a/secchan/pinsched.c +++ b/secchan/pinsched.c @@ -42,7 +42,6 @@ #include "queue.h" #include "random.h" #include "rconn.h" -#include "secchan.h" #include "status.h" #include "timeval.h" #include "vconn.h" diff --git a/secchan/secchan.h b/secchan/secchan.h deleted file mode 100644 index a8564b86..00000000 --- a/secchan/secchan.h +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright (c) 2008, 2009 The Board of Trustees of The Leland Stanford - * Junior University - * - * We are making the OpenFlow specification and associated documentation - * (Software) available for public use and benefit with the expectation - * that others will use, modify and enhance the Software and contribute - * those enhancements back to the community. However, since we would - * like to make the Software available for broadest use, with as few - * restrictions as possible permission is hereby granted, free of - * charge, to any person obtaining a copy of this Software to deal in - * the Software under the copyrights without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * The name and trademarks of copyright holder(s) may NOT be used in - * advertising or publicity pertaining to the Software or any - * derivatives without specific, written prior permission. - */ - -#ifndef SECCHAN_H -#define SECCHAN_H 1 - -#include -#include -#include "list.h" - -/* Behavior when the connection to the controller fails. */ -enum fail_mode { - FAIL_OPEN, /* Act as learning switch. */ - FAIL_CLOSED /* Drop all packets. */ -}; - -/* Maximum number of management connection listeners. */ -#define MAX_MGMT 8 - -/* Settings that may be configured by the user. */ -struct settings { - /* Configuration. */ - const char *br_name; /* Bridge name to use for configuration lookup */ - - /* Overall mode of operation. */ - bool discovery; /* Discover the controller automatically? */ - bool in_band; /* Connect to controller in-band? */ - - /* Datapath. */ - uint64_t datapath_id; /* Datapath ID. */ - const char *dp_name; /* Name of local datapath. */ - - /* Description strings. */ - const char *mfr_desc; /* Manufacturer. */ - const char *hw_desc; /* Hardware. */ - const char *sw_desc; /* Software version. */ - const char *serial_desc; /* Serial number. */ - - /* Related vconns and network devices. */ - const char *controller_name; /* Controller (if not discovery mode). */ - const char *listener_names[MAX_MGMT]; /* Listen for mgmt connections. */ - size_t n_listeners; /* Number of mgmt connection listeners. */ - - /* Failure behavior. */ - enum fail_mode fail_mode; /* Act as learning switch if no controller? */ - int max_idle; /* Idle time for flows in fail-open mode. */ - int probe_interval; /* # seconds idle before sending echo request. */ - int max_backoff; /* Max # seconds between connection attempts. */ - - /* Packet-in rate-limiting. */ - int rate_limit; /* Tokens added to bucket per second. */ - int burst_limit; /* Maximum number token bucket size. */ - - /* Discovery behavior. */ - const char *accept_controller_re; /* Controller vconns to accept. */ - bool update_resolv_conf; /* Update /etc/resolv.conf? */ - - /* Spanning tree protocol. */ - bool enable_stp; - - /* Remote command execution. */ - char *command_acl; /* Command white/blacklist, as shell globs. */ - char *command_dir; /* Directory that contains commands. */ -}; - -#endif /* secchan.h */ diff --git a/secchan/status.c b/secchan/status.c index fd57e514..3f9b0f4b 100644 --- a/secchan/status.c +++ b/secchan/status.c @@ -39,9 +39,9 @@ #include #include "dynamic-string.h" #include "ofpbuf.h" +#include "ofproto.h" #include "openflow/nicira-ext.h" #include "rconn.h" -#include "secchan.h" #include "timeval.h" #include "vconn.h" @@ -126,7 +126,7 @@ rconn_status_cb(struct status_reply *sr, void *rconn_) static void config_status_cb(struct status_reply *sr, void *s_) { - const struct settings *s = s_; + const struct ofsettings *s = s_; size_t i; for (i = 0; i < s->n_listeners; i++) { @@ -152,7 +152,7 @@ switch_status_cb(struct status_reply *sr, void *ss_) } struct switch_status * -switch_status_create(const struct settings *settings) +switch_status_create(const struct ofsettings *settings) { struct switch_status *ss = xcalloc(1, sizeof *ss); ss->booted = time_now(); diff --git a/secchan/status.h b/secchan/status.h index dbb0300a..f8766206 100644 --- a/secchan/status.h +++ b/secchan/status.h @@ -39,10 +39,10 @@ struct nicira_header; struct rconn; struct secchan; -struct settings; +struct ofsettings; struct status_reply; -struct switch_status *switch_status_create(const struct settings *); +struct switch_status *switch_status_create(const struct ofsettings *); int switch_status_handle_request(struct switch_status *, struct rconn *, struct nicira_header *); -- 2.30.2