3 # /etc/init.d/openflow-switch
5 # Written by Miquel van Smoorenburg <miquels@cistron.nl>.
6 # Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>.
7 # Further changes by Javier Fernandez-Sanguino <jfs@debian.org>
8 # Modified for openflow-switch.
10 # Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
13 # Provides: openflow-switch
14 # Required-Start: $network $named $remote_fs $syslog
16 # Default-Start: 2 3 4 5
18 # Short-Description: OpenFlow switch
21 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
22 DAEMON=/usr/sbin/secchan
26 test -x $DAEMON || exit 0
28 LOGDIR=/var/log/openflow
29 PIDFILE=/var/run/$NAME.pid
30 DHCLIENT_PIDFILE=/var/run/dhclient.of0.pid
31 DODTIME=1 # Time to wait for the server to die, in seconds
32 # If this value is set too low you might not
33 # let some servers to die gracefully and
34 # 'restart' will not work
36 # Include secchan defaults if available
48 default=/etc/default/openflow-switch
49 if [ -f $default ] ; then
57 # Check if a given process pid's cmdline matches a given name
60 [ -z "$pid" ] && return 1
61 [ ! -d /proc/$pid ] && return 1
62 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
63 # Is this the expected child?
76 # Check if the process is running looking at /proc
77 # (works for all users)
79 # No pidfile, probably no daemon present
80 [ ! -f "$PIDFILE" ] && return 1
81 # Obtain the pid and check it against the binary name
83 running_pid $pid $NAME || return 1
88 # Forcefully kill the process
89 [ ! -f "$PIDFILE" ] && return
93 [ -n "$DODTIME" ] && sleep "$DODTIME"s
96 [ -n "$DODTIME" ] && sleep "$DODTIME"s
98 echo "Cannot kill $LABEL (pid=$pid)!"
129 if (test "$CACERT_MODE" != secure && test "$CACERT_MODE" != bootstrap) \
130 || test ! -e "$PRIVKEY" || test ! -e "$CERT" \
131 || (test ! -e "$CACERT" && test "$CACERT_MODE" != bootstrap); then
132 if test "$CACERT_MODE" != secure && test "$CACERT_MODE" != bootstrap
134 echo "CACERT_MODE is not set to 'secure' or 'bootstrap'"
136 if test ! -e "$PRIVKEY"; then
137 echo "$PRIVKEY: private key missing" >&2
139 if test ! -e "$CERT"; then
140 echo "$CERT: certificate for private key missing" >&2
142 if test ! -e "$CACERT" && test "$CACERT_MODE" != bootstrap; then
143 echo "$CACERT: CA certificate missing (and CA certificate bootstrapping not enabled)" >&2
145 echo "Run ofp-switch-setup (in the openflow-switch-config package) or edit /etc/default/openflow-switch to configure" >&2
146 if test "$MODE" = discovery; then
147 echo "You may also delete or rename $PRIVKEY to disable SSL requirement" >&2
152 SSL_OPTS="--private-key=$PRIVKEY --certificate=$CERT"
153 if test ! -e "$CACERT" && test "$CACERT_MODE" = bootstrap; then
154 SSL_OPTS="$SSL_OPTS --bootstrap-ca-cert=$CACERT"
156 SSL_OPTS="$SSL_OPTS --ca-cert=$CACERT"
162 if test -z "$NETDEVS"; then
163 echo "$default: No network devices configured, switch disabled" >&2
164 echo "Run ofp-switch-setup (in the openflow-switch-config package) or edit /etc/default/openflow-switch to configure" >&2
167 if test "$MODE" = discovery; then
169 elif test "$MODE" = in-band || test "$MODE" = out-of-band; then
170 if test -z "$CONTROLLER"; then
171 echo "$default: No controller configured and not configured for discovery, switch disabled" >&2
172 echo "Run ofp-switch-setup (in the openflow-switch-config package) or edit /etc/default/openflow-switch to configure" >&2
176 echo "$default: MODE must set to 'discovery', 'in-band', or 'out-of-band'" >&2
177 echo "Run ofp-switch-setup (in the openflow-switch-config package) or edit /etc/default/openflow-switch to configure" >&2
180 : ${PRIVKEY:=/etc/openflow-switch/of0-privkey.pem}
181 : ${CERT:=/etc/openflow-switch/of0-cert.pem}
182 : ${CACERT:=/etc/openflow-switch/cacert.pem}
186 if test -e "$PRIVKEY"; then
196 echo "$default: CONTROLLER must be in the form 'ssl:HOST[:PORT]' or 'tcp:HOST[:PORT]' when not in discovery mode" >&2
197 echo "Run ofp-switch-setup (in the openflow-switch-config package) or edit /etc/default/openflow-switch to configure" >&2
201 echo -n "Loading openflow_mod: "
202 if grep -q '^openflow_mod$' /proc/modules; then
203 echo "already loaded, nothing to do."
204 elif modprobe openflow_mod; then
208 echo "openflow_mod has probably not been built for this kernel."
209 if ! test -d /usr/share/doc/openflow-datapath-source; then
210 echo "Install the openflow-datapath-source package, then read"
211 echo "/usr/share/doc/openflow-datapath-source/README.Debian"
213 echo "For instructions, read"
214 echo "/usr/share/doc/openflow-datapath-source/README.Debian"
219 must_succeed "Adding datapath" dpctl adddp nl:0
220 for netdev in $NETDEVS; do
221 must_succeed "Adding $netdev to datapath" dpctl addif nl:0 $netdev
224 if test "$MODE" = in-band; then
225 if test "$SWITCH_IP" = dhcp; then
226 must_succeed "Temporarily disabling of0" ifconfig of0 down
228 COMMAND="ifconfig of0 $SWITCH_IP"
229 if test -n "$SWITCH_NETMASK"; then
230 COMMAND="$COMMAND netmask $SWITCH_NETMASK"
232 must_succeed "Configuring of0: $COMMAND" $COMMAND
233 if test -n "$SWITCH_GATEWAY"; then
234 # This can fail because the route already exists,
235 # so we don't insist that it succeed.
236 COMMAND="route add default gw $SWITCH_GATEWAY"
237 check_op "Adding default route: $COMMAND" $COMMAND
241 must_succeed "Disabling of0" ifconfig of0 down
245 for vconn in $MGMT_VCONNS; do
246 MGMT_OPTS="$MGMT_OPTS --listen=$vconn"
250 if test -n "$COMMANDS"; then
251 COMMAND_OPT="--command-acl=$COMMANDS"
254 if test "$MODE" = out-of-band; then
255 DAEMON_OPTS="$DAEMON_OPTS --out-of-band"
258 echo -n "Starting $DESC: "
259 start-stop-daemon --start --quiet --pidfile $PIDFILE \
260 --exec $DAEMON -- nl:0 $CONTROLLER --detach --pidfile=$PIDFILE \
261 --verbose=ANY:console:emer --verbose=ANY:syslog:err --log-file \
262 $DAEMON_OPTS $MGMT_OPTS $SSL_OPTS "$COMMAND_OPT"
269 if test "$MODE" = in-band && test "$SWITCH_IP" = dhcp; then
270 echo -n "Starting dhclient on of0: "
271 start-stop-daemon --start --quiet --pidfile $DHCLIENT_PIDFILE \
272 --exec /sbin/dhclient -- -q -pf $DHCLIENT_PIDFILE of0
281 if test -e /var/run/dhclient.of0.pid; then
282 echo -n "Stopping dhclient on of0: "
283 start-stop-daemon --stop --quiet --oknodo \
284 --pidfile $DHCLIENT_PIDFILE --exec /sbin/dhclient
288 echo -n "Stopping $DESC: "
289 start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE \
293 for netdev in $NETDEVS; do
294 check_op "Removing $netdev from datapath" dpctl delif nl:0 $netdev
296 check_op "Deleting datapath" dpctl deldp nl:0
299 echo -n "Forcefully stopping $DESC: "
310 start-stop-daemon --stop --test --quiet --pidfile \
311 $PIDFILE --exec $DAEMON \
330 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2