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 MGMTSOCK=/var/run/$NAME.socket
31 DHCLIENT_PIDFILE=/var/run/dhclient.of0.pid
32 DODTIME=1 # Time to wait for the server to die, in seconds
33 # If this value is set too low you might not
34 # let some servers to die gracefully and
35 # 'restart' will not work
37 # Include secchan defaults if available
38 default=/etc/default/openflow-switch
39 if [ -f $default ] ; then
47 # Check if a given process pid's cmdline matches a given name
50 [ -z "$pid" ] && return 1
51 [ ! -d /proc/$pid ] && return 1
52 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
53 # Is this the expected child?
66 # Check if the process is running looking at /proc
67 # (works for all users)
69 # No pidfile, probably no daemon present
70 [ ! -f "$PIDFILE" ] && return 1
71 # Obtain the pid and check it against the binary name
73 running_pid $pid $NAME || return 1
78 # Forcefully kill the process
79 [ ! -f "$PIDFILE" ] && return
83 [ -n "$DODTIME" ] && sleep "$DODTIME"s
86 [ -n "$DODTIME" ] && sleep "$DODTIME"s
88 echo "Cannot kill $LABEL (pid=$pid)!"
119 if test ! -e "$PRIVKEY" || test ! -e "$CERT" || test ! -e "$CACERT"; then
120 if test ! -e "$PRIVKEY"; then
121 echo "$PRIVKEY: private key missing" >&2
123 if test ! -e "$CERT"; then
124 echo "$CERT: certificate for private key missing" >&2
126 if test ! -e "$CACERT"; then
127 echo "$CACERT: CA certificate missing" >&2
129 echo "Run ofp-switch-setup or edit /etc/default/openflow-switch to configure" >&2
130 if test "$MODE" = discovery; then
131 echo "You may also delete or rename $PRIVKEY to disable SSL requirement" >&2
135 SSL_OPTS="--private-key=$PRIVKEY --certificate=$CERT --ca-cert=$CACERT"
140 if test -z "$NETDEVS"; then
141 echo "$default: No network devices configured, switch disabled" >&2
142 echo "Run ofp-switch-setup or edit /etc/default/openflow-switch to configure" >&2
145 if test "$MODE" = discovery; then
147 elif test "$MODE" = in-band || test "$MODE" = out-of-band; then
148 if test -z "$CONTROLLER"; then
149 echo "$default: No controller configured and not configured for discovery, switch disabled" >&2
150 echo "Run ofp-switch-setup or edit /etc/default/openflow-switch to configure" >&2
154 echo "$default: MODE must set to 'discovery', 'in-band', or 'out-of-band'" >&2
155 echo "Run ofp-switch-setup or edit /etc/default/openflow-switch to configure" >&2
158 : ${PRIVKEY:=/etc/openflow-switch/of0-privkey.pem}
159 : ${CERT:=/etc/openflow-switch/of0-cert.pem}
160 : ${CACERT:=/etc/openflow-switch/cacert.pem}
164 if test -e "$PRIVKEY"; then
174 echo "$default: CONTROLLER must be in the form 'ssl:HOST[:PORT]' or 'tcp:HOST[:PORT]' when not in discovery mode" >&2
175 echo "Run ofp-switch-setup or edit /etc/default/openflow-switch to configure" >&2
179 echo -n "Loading openflow_mod: "
180 if modprobe openflow_mod; then
184 echo "openflow_mod has probably not been built for this kernel."
185 if ! test -d /usr/share/doc/openflow-datapath-source; then
186 echo "Install the openflow-datapath-source package, then read"
187 echo "/usr/share/doc/openflow-datapath-source/README.Debian"
189 echo "For instructions, read"
190 echo "/usr/share/doc/openflow-datapath-source/README.Debian"
195 must_succeed "Adding datapath" dpctl adddp nl:0
196 for netdev in $NETDEVS; do
197 must_succeed "Adding $netdev to datapath" dpctl addif nl:0 $netdev
200 if test "$MODE" = in-band; then
201 if test "$SWITCH_IP" = dhcp; then
202 must_succeed "Temporarily disabling of0" ifconfig of0 down
204 must_succeed "Configuring of0 as $SWITCH_IP" ifconfig of0 $SWITCH_IP
207 must_succeed "Disabling of0" ifconfig of0 down
210 echo -n "Starting $DESC: "
211 start-stop-daemon --start --quiet --pidfile $PIDFILE \
212 --exec $DAEMON -- nl:0 $CONTROLLER --detach --pidfile=$PIDFILE \
213 --verbose=ANY:console:emer --listen=punix:$MGMTSOCK \
214 $DAEMON_OPTS $SSL_OPTS
221 if test "$MODE" = in-band && test "$SWITCH_IP" = dhcp; then
222 echo -n "Starting dhclient on of0: "
223 start-stop-daemon --start --quiet --pidfile $DHCLIENT_PIDFILE \
224 --exec /sbin/dhclient -- -q -pf $DHCLIENT_PIDFILE of0
233 if test -e /var/run/dhclient.of0.pid; then
234 echo -n "Stopping dhclient on of0: "
235 start-stop-daemon --stop --quiet --oknodo \
236 --pidfile $DHCLIENT_PIDFILE --exec /sbin/dhclient
240 echo -n "Stopping $DESC: "
241 start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE \
245 for netdev in $NETDEVS; do
246 check_op "Removing $netdev from datapath" dpctl delif nl:0 $netdev
248 check_op "Deleting datapath" dpctl deldp nl:0
251 echo -n "Forcefully stopping $DESC: "
262 start-stop-daemon --stop --test --quiet --pidfile \
263 $PIDFILE --exec $DAEMON \
282 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2