Add settings for switch netmask and gateway for in-band mode to init script.
authorBen Pfaff <blp@nicira.com>
Fri, 31 Oct 2008 18:24:11 +0000 (11:24 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 31 Oct 2008 21:09:53 +0000 (14:09 -0700)
Previously we supported setting a switch IP address but not those
parameters, which are obviously required also.

debian/ofp-switch-setup
debian/openflow-switch.default
debian/openflow-switch.init

index aa318d72ec107f45bbab5044aa04dac03511c1be..a4a0879f7c52ad0187e8306513e412420a7922b9 100755 (executable)
@@ -8,6 +8,9 @@ use Digest::SHA1 'sha1_hex';
 use strict;
 use warnings;
 
+# XXX should support configuring SWITCH_NETMASK and SWITCH_GATEWAY
+# when the mode is in-band.
+
 my $debconf_owner = 'openflow-switch';
 
 my $default = '/etc/default/openflow-switch';
index 6a86e2ff6f75473b2bff0b5ac91b528563751bae..f8c3159f7e3de06f8459baa72f053f39aa54266f 100644 (file)
@@ -48,7 +48,8 @@ MODE=discovery
 # configured statically or dynamically:
 # 
 # * For static configuration, specify the switch's IP address as a
-#   string.
+#   string.  In this case you may also set SWITCH_NETMASK and
+#   SWITCH_GATEWAY appropriately.
 # 
 # * For dynamic configuration with DHCP (the most common case),
 #   specify "dhcp".  Configuration with DHCP will only work reliably
@@ -57,6 +58,8 @@ MODE=discovery
 #
 # This setting has no effect unless MODE is set to 'in-band'.
 SWITCH_IP=dhcp
+#SWITCH_NETMASK=255.255.255.0
+#SWITCH_GATEWAY=192.168.1.1
 
 # CONTROLLER: Location of controller.
 # One of the following formats:
index 3dbfb9de05010e3323e168e2d03107b814e0bc9a..aac723f0402774d78105b7498993e898928f9b87 100755 (executable)
@@ -225,7 +225,17 @@ case "$1" in
             if test "$SWITCH_IP" = dhcp; then
                 must_succeed "Temporarily disabling of0" ifconfig of0 down
             else
-                must_succeed "Configuring of0 as $SWITCH_IP" ifconfig of0 $SWITCH_IP
+                COMMAND="ifconfig of0 $SWITCH_IP"
+                if test -n "$SWITCH_NETMASK"; then
+                    COMMAND="$COMMAND netmask $SWITCH_NETMASK"
+                fi
+                must_succeed "Configuring of0: $COMMAND" $COMMAND
+                if test -n "$SWITCH_GATEWAY"; then
+                    # This can fail because the route already exists,
+                    # so we don't insist that it succeed.
+                    COMMAND="route add default gw $SWITCH_GATEWAY"
+                    check_op "Adding default route: $COMMAND" $COMMAND
+                fi
             fi
         else
             must_succeed "Disabling of0" ifconfig of0 down