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
50 default=/etc/default/openflow-switch
51 if [ -f $default ] ; then
59 # Check if a given process pid's cmdline matches a given name
62 [ -z "$pid" ] && return 1
63 [ ! -d /proc/$pid ] && return 1
64 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
65 # Is this the expected child?
78 # Check if the process is running looking at /proc
79 # (works for all users)
81 # No pidfile, probably no daemon present
82 [ ! -f "$PIDFILE" ] && return 1
83 # Obtain the pid and check it against the binary name
85 running_pid $pid $NAME || return 1
90 # Forcefully kill the process
91 [ ! -f "$PIDFILE" ] && return
95 [ -n "$DODTIME" ] && sleep "$DODTIME"s
98 [ -n "$DODTIME" ] && sleep "$DODTIME"s
100 echo "Cannot kill $NAME (pid=$pid)!"
131 if (test "$CACERT_MODE" != secure && test "$CACERT_MODE" != bootstrap) \
132 || test ! -e "$PRIVKEY" || test ! -e "$CERT" \
133 || (test ! -e "$CACERT" && test "$CACERT_MODE" != bootstrap); then
134 if test "$CACERT_MODE" != secure && test "$CACERT_MODE" != bootstrap
136 echo "CACERT_MODE is not set to 'secure' or 'bootstrap'"
138 if test ! -e "$PRIVKEY"; then
139 echo "$PRIVKEY: private key missing" >&2
141 if test ! -e "$CERT"; then
142 echo "$CERT: certificate for private key missing" >&2
144 if test ! -e "$CACERT" && test "$CACERT_MODE" != bootstrap; then
145 echo "$CACERT: CA certificate missing (and CA certificate bootstrapping not enabled)" >&2
147 echo "Run ofp-switch-setup (in the openflow-switch-config package) or edit /etc/default/openflow-switch to configure" >&2
148 if test "$MODE" = discovery; then
149 echo "You may also delete or rename $PRIVKEY to disable SSL requirement" >&2
154 SSL_OPTS="--private-key=$PRIVKEY --certificate=$CERT"
155 if test ! -e "$CACERT" && test "$CACERT_MODE" = bootstrap; then
156 SSL_OPTS="$SSL_OPTS --bootstrap-ca-cert=$CACERT"
158 SSL_OPTS="$SSL_OPTS --ca-cert=$CACERT"
164 if test -z "$NETDEVS"; then
165 echo "$default: No network devices configured, switch disabled" >&2
166 echo "Run ofp-switch-setup (in the openflow-switch-config package) or edit /etc/default/openflow-switch to configure" >&2
169 if test "$MODE" = discovery; then
171 elif test "$MODE" = in-band || test "$MODE" = out-of-band; then
172 if test -z "$CONTROLLER"; then
173 echo "$default: No controller configured and not configured for discovery, switch disabled" >&2
174 echo "Run ofp-switch-setup (in the openflow-switch-config package) or edit /etc/default/openflow-switch to configure" >&2
178 echo "$default: MODE must set to 'discovery', 'in-band', or 'out-of-band'" >&2
179 echo "Run ofp-switch-setup (in the openflow-switch-config package) or edit /etc/default/openflow-switch to configure" >&2
182 : ${PRIVKEY:=/etc/openflow-switch/of0-privkey.pem}
183 : ${CERT:=/etc/openflow-switch/of0-cert.pem}
184 : ${CACERT:=/etc/openflow-switch/cacert.pem}
188 if test -e "$PRIVKEY"; then
198 echo "$default: CONTROLLER must be in the form 'ssl:HOST[:PORT]' or 'tcp:HOST[:PORT]' when not in discovery mode" >&2
199 echo "Run ofp-switch-setup (in the openflow-switch-config package) or edit /etc/default/openflow-switch to configure" >&2
203 echo -n "Loading openflow_mod: "
204 if grep -q '^openflow_mod$' /proc/modules; then
205 echo "already loaded, nothing to do."
206 elif modprobe openflow_mod; then
210 echo "openflow_mod has probably not been built for this kernel."
211 if ! test -d /usr/share/doc/openflow-datapath-source; then
212 echo "Install the openflow-datapath-source package, then read"
213 echo "/usr/share/doc/openflow-datapath-source/README.Debian"
215 echo "For instructions, read"
216 echo "/usr/share/doc/openflow-datapath-source/README.Debian"
221 must_succeed "Adding datapath" dpctl adddp nl:0
222 for netdev in $NETDEVS; do
223 must_succeed "Adding $netdev to datapath" dpctl addif nl:0 $netdev
226 xx='[0-9abcdefABCDEF][0-9abcdefABCDEF]'
230 $xx:$xx:$xx:$xx:$xx:$xx)
232 must_succeed "Setting of0 MAC address to $DATAPATH_ID" ifconfig of0 hw ether $DATAPATH_ID
236 echo "DATAPATH_ID is not a valid MAC address in the form XX:XX:XX:XX:XX:XX, ignoring" >&2
240 if test "$MODE" = in-band; then
241 if test "$SWITCH_IP" = dhcp; then
242 must_succeed "Temporarily disabling of0" ifconfig of0 down
244 COMMAND="ifconfig of0 $SWITCH_IP"
245 if test -n "$SWITCH_NETMASK"; then
246 COMMAND="$COMMAND netmask $SWITCH_NETMASK"
248 must_succeed "Configuring of0: $COMMAND" $COMMAND
249 if test -n "$SWITCH_GATEWAY"; then
250 # This can fail because the route already exists,
251 # so we don't insist that it succeed.
252 COMMAND="route add default gw $SWITCH_GATEWAY"
253 check_op "Adding default route: $COMMAND" $COMMAND
257 must_succeed "Disabling of0" ifconfig of0 down
261 for vconn in $MGMT_VCONNS; do
262 MGMT_OPTS="$MGMT_OPTS --listen=$vconn"
266 if test -n "$MONITOR_VCONN"; then
267 MONITOR_OPT="--monitor=$MONITOR_VCONN"
271 if test -n "$COMMANDS"; then
272 COMMAND_OPT="--command-acl=$COMMANDS"
275 if test "$MODE" = out-of-band; then
276 DAEMON_OPTS="$DAEMON_OPTS --out-of-band"
279 if test -n "$CORE_LIMIT"; then
280 check_op "Setting core limit to $CORE_LIMIT" ulimit -c "$CORE_LIMIT"
283 echo -n "Starting $DESC: "
284 start-stop-daemon --start --quiet --pidfile $PIDFILE \
285 --exec $DAEMON -- nl:0 $CONTROLLER --detach --pidfile=$PIDFILE \
286 --verbose=ANY:console:emer --verbose=ANY:syslog:err --log-file \
287 $DAEMON_OPTS $MGMT_OPTS $MONITOR_OPT $SSL_OPTS "$COMMAND_OPT"
294 if test "$MODE" = in-band && test "$SWITCH_IP" = dhcp; then
295 echo -n "Starting dhclient on of0: "
296 start-stop-daemon --start --quiet --pidfile $DHCLIENT_PIDFILE \
297 --exec /sbin/dhclient -- -q -pf $DHCLIENT_PIDFILE of0
306 if test -e /var/run/dhclient.of0.pid; then
307 echo -n "Stopping dhclient on of0: "
308 start-stop-daemon --stop --quiet --oknodo \
309 --pidfile $DHCLIENT_PIDFILE --exec /sbin/dhclient
313 echo -n "Stopping $DESC: "
314 start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE \
318 for netdev in $NETDEVS; do
319 check_op "Removing $netdev from datapath" dpctl delif nl:0 $netdev
321 check_op "Deleting datapath" dpctl deldp nl:0
322 check_op "Unloading kernel module" modprobe -r openflow_mod
325 echo -n "Forcefully stopping $DESC: "
336 start-stop-daemon --stop --test --quiet --pidfile \
337 $PIDFILE --exec $DAEMON \
356 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2