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
37 default=/etc/default/openflow-switch
38 if [ -f $default ] ; then
46 # Check if a given process pid's cmdline matches a given name
49 [ -z "$pid" ] && return 1
50 [ ! -d /proc/$pid ] && return 1
51 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
52 # Is this the expected child?
65 # Check if the process is running looking at /proc
66 # (works for all users)
68 # No pidfile, probably no daemon present
69 [ ! -f "$PIDFILE" ] && return 1
70 # Obtain the pid and check it against the binary name
72 running_pid $pid $NAME || return 1
77 # Forcefully kill the process
78 [ ! -f "$PIDFILE" ] && return
82 [ -n "$DODTIME" ] && sleep "$DODTIME"s
85 [ -n "$DODTIME" ] && sleep "$DODTIME"s
87 echo "Cannot kill $LABEL (pid=$pid)!"
118 if test ! -e "$PRIVKEY" || test ! -e "$CERT" || test ! -e "$CACERT"; then
119 if test ! -e "$PRIVKEY"; then
120 echo "$PRIVKEY: private key missing" >&2
122 if test ! -e "$CERT"; then
123 echo "$CERT: certificate for private key missing" >&2
125 if test ! -e "$CACERT"; then
126 echo "$CACERT: CA certificate missing" >&2
128 echo "Run ofp-switch-setup or edit /etc/default/openflow-switch to configure" >&2
129 if test "$MODE" = discovery; then
130 echo "You may also delete or rename $PRIVKEY to disable SSL requirement" >&2
134 SSL_OPTS="--private-key=$PRIVKEY --certificate=$CERT --ca-cert=$CACERT"
139 if test -z "$NETDEVS"; then
140 echo "$default: No network devices configured, switch disabled" >&2
141 echo "Run ofp-switch-setup or edit /etc/default/openflow-switch to configure" >&2
144 if test "$MODE" = discovery; then
146 elif test "$MODE" = in-band || test "$MODE" = out-of-band; then
147 if test -z "$CONTROLLER"; then
148 echo "$default: No controller configured and not configured for discovery, switch disabled" >&2
149 echo "Run ofp-switch-setup or edit /etc/default/openflow-switch to configure" >&2
153 echo "$default: MODE must set to 'discovery', 'in-band', or 'out-of-band'" >&2
154 echo "Run ofp-switch-setup or edit /etc/default/openflow-switch to configure" >&2
157 : ${PRIVKEY:=/etc/openflow-switch/of0-privkey.pem}
158 : ${CERT:=/etc/openflow-switch/of0-cert.pem}
159 : ${CACERT:=/etc/openflow-switch/cacert.pem}
163 if test -e "$PRIVKEY"; then
173 echo "$default: CONTROLLER must be in the form 'ssl:HOST[:PORT]' or 'tcp:HOST[:PORT]' when not in discovery mode" >&2
174 echo "Run ofp-switch-setup or edit /etc/default/openflow-switch to configure" >&2
178 echo -n "Loading openflow_mod: "
179 if modprobe openflow_mod; then
183 echo "openflow_mod has probably not been built for this kernel."
184 if ! test -d /usr/share/doc/openflow-datapath-source; then
185 echo "Install the openflow-datapath-source package, then read"
186 echo "/usr/share/doc/openflow-datapath-source/README.Debian"
188 echo "For instructions, read"
189 echo "/usr/share/doc/openflow-datapath-source/README.Debian"
194 must_succeed "Adding datapath" dpctl adddp nl:0
195 for netdev in $NETDEVS; do
196 must_succeed "Adding $netdev to datapath" dpctl addif nl:0 $netdev
199 if test "$MODE" = in-band; then
200 if test "$SWITCH_IP" = dhcp; then
201 must_succeed "Temporarily disabling of0" ifconfig of0 down
203 must_succeed "Configuring of0 as $SWITCH_IP" ifconfig of0 $SWITCH_IP
206 must_succeed "Disabling of0" ifconfig of0 down
209 echo -n "Starting $DESC: "
210 start-stop-daemon --start --quiet --pidfile $PIDFILE \
211 --exec $DAEMON -- nl:0 $CONTROLLER --detach --pidfile=$PIDFILE \
212 --verbose=ANY:console:emer $DAEMON_OPTS $SSL_OPTS
219 if test "$MODE" = in-band && test "$SWITCH_IP" = dhcp; then
220 echo -n "Starting dhclient on of0: "
221 start-stop-daemon --start --quiet --pidfile $DHCLIENT_PIDFILE \
222 --exec /sbin/dhclient -- -q -pf $DHCLIENT_PIDFILE of0
231 if test -e /var/run/dhclient.of0.pid; then
232 echo -n "Stopping dhclient on of0: "
233 start-stop-daemon --stop --quiet --oknodo \
234 --pidfile $DHCLIENT_PIDFILE --exec /sbin/dhclient
238 echo -n "Stopping $DESC: "
239 start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE \
243 for netdev in $NETDEVS; do
244 check_op "Removing $netdev from datapath" dpctl delif nl:0 $netdev
246 check_op "Deleting datapath" dpctl deldp nl:0
249 echo -n "Forcefully stopping $DESC: "
260 start-stop-daemon --stop --test --quiet --pidfile \
261 $PIDFILE --exec $DAEMON \
280 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2