]> git.ipfire.org Git - network.git/commitdiff
Import some experimental Open vSwitch code.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Aug 2012 10:16:33 +0000 (10:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 Aug 2012 10:16:33 +0000 (10:16 +0000)
functions.switch [new file with mode: 0644]
hooks/zones/switch [new file with mode: 0755]

diff --git a/functions.switch b/functions.switch
new file mode 100644 (file)
index 0000000..69894ff
--- /dev/null
@@ -0,0 +1,129 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2012  IPFire Network Development Team                         #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+function switch_create() {
+       local device=${1}
+       assert isset device
+
+       log DEBUG "Creating virtual switch: ${device}"
+       ovs-vsctl -- --may-exist add-br ${device}
+
+       assert device_exists ${device}
+
+       return ${EXIT_OK}
+}
+
+function switch_remove() {
+       local device=${1}
+       assert isset device
+
+       # Set device down.
+       device_set_down ${device}
+
+       log DEBUG "Removing virtual switch: ${device}"
+       ovs-vsctl -- --if-exists del-br ${device}
+
+       return ${EXIT_OK}
+}
+
+function switch_exists() {
+       local device=${1}
+       assert isset device
+
+       ovs-vsctl -- br-exists ${device}
+       case "$?" in
+               0)
+                       return ${EXIT_TRUE}
+                       ;;
+               2)
+                       return ${EXIT_FALSE}
+                       ;;
+       esac
+
+       return ${EXIT_ERROR}
+}
+
+function switch_get_members() {
+       local device=${1}
+       assert isset device
+
+       ovs-vsctl -- list-ports ${device}
+       return ${EXIT_OK}
+}
+
+function switch_attach_port() {
+       local device=${1}
+       assert isset device
+
+       local port=${2}
+       assert isset port
+
+       log DEBUG "Attaching port '${port}' to switch '${device}'"
+       ovs-vsctl -- --may-exist ${device} ${port}
+
+       return ${EXIT_OK}
+}
+
+function switch_detach_port() {
+       local device=${1}
+       assert isset device
+
+       local port=${2}
+       assert isset port
+
+       log DEBUG "Detaching port '${port}' from switch '${device}'"
+       ovs-vsctl -- --if-exists ${device} ${port}
+
+       return ${EXIT_OK}
+}
+
+function switch_stp_enable() {
+       local device=${1}
+       assert isset device
+
+       log DEBUG "Enable STP on switch ${device}"
+       ovs-vsctl set Bridge ${device} "stp_enable=true"
+
+       return ${EXIT_OK}
+}
+
+function switch_stp_disable() {
+       local device=${1}
+       assert isset device
+
+       log DEBUG "Disable STP on switch ${device}"
+       ovs-vsctl set Bridge ${device} "stp_enable=false"
+
+       return ${EXIT_OK}
+}
+
+function switch_stp_is_enabled() {
+       local device=${1}
+       assert isset device
+
+       local output=$(ovs-vsctl -- --if-exists get Bridge ${device} stp_enable)
+
+       if enabled output; then
+               return ${EXIT_TRUE}
+       fi
+
+       return ${EXIT_FALSE}
+}
diff --git a/hooks/zones/switch b/hooks/zones/switch
new file mode 100755 (executable)
index 0000000..d00116f
--- /dev/null
@@ -0,0 +1,145 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2010  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+. /usr/lib/network/header-zone
+
+HOOK_SETTINGS="HOOK MAC MTU"
+
+# Default values
+MAC=$(mac_generate)
+MTU=1500
+
+function _check() {
+       assert ismac MAC
+       assert isinteger MTU
+}
+
+function _parse_cmdline() {
+       while [ $# -gt 0 ]; do
+               case "${1}" in
+                       --mtu=*)
+                               MTU=${1#--mtu=}
+                               ;;
+                       --mac=*)
+                               MAC=${1#--mac=}
+                               ;;
+                       *)
+                               warning "Ignoring unknown option '${1}'"
+                               ;;
+               esac
+               shift
+       done
+}
+
+function _up() {
+       local zone=${1}
+       shift
+
+       zone_config_read ${zone}
+
+       # Create the interface.
+       log INFO "Creating virtual switch '${zone}'."
+       switch_create ${zone}
+
+       [ -n "${MAC}" ] && device_set_address ${zone} ${MAC}
+       [ -n "${MTU}" ] && device_set_mtu ${zone} ${MTU} 
+
+       # Bring it up.
+       device_set_up ${zone}
+
+       # Bring all ports up
+       zone_ports_up ${zone}
+       zone_configs_up ${zone}
+
+       exit ${EXIT_OK}
+}
+
+function _down() {
+       local zone=${1}
+       shift
+
+       zone_configs_down ${zone}
+       zone_ports_down ${zone}
+
+       # Bring it down.
+       device_set_down ${zone}
+
+       # Remove the virtual switch.
+       log INFO "Removing virtual switch '${zone}'."
+       switch_remove ${zone}
+
+       exit ${EXIT_OK}
+}
+
+function _status() {
+       local zone=${1}
+       assert isset zone
+
+       # Print the default header.
+       cli_device_headline ${zone}
+
+       # Exit if zone is down
+       if ! zone_is_up ${zone}; then
+               echo # Empty line
+               exit ${EXIT_ERROR}
+       fi
+
+       cli_headline 2 "Spanning Tree Protocol information"
+       if switch_stp_is_enabled ${zone}; then
+       #       local proto=$(stp_bridge_get_protocol ${zone})
+
+       #       cli_print_fmt1 2 "Version"      "$(stp_get_name ${proto})"
+       #       cli_print_fmt1 2 "ID"           "$(stp_bridge_get_id ${zone})"
+       #       cli_print_fmt1 2 "Priority"     "$(switch_stp_get_priority ${zone})"
+
+       #       if stp_bridge_is_root ${zone}; then
+       #               cli_print 2 "This bridge is root."
+       #       else
+       #               cli_print_fmt1 2 "Designated root" \
+       #                       "$(stp_bridge_get_designated_root ${zone})"
+       #               cli_print_fmt1 2 "Root path cost" \
+       #                       "$(stp_bridge_get_root_path_cost ${zone})"
+       #       fi
+       #       cli_space
+
+       #       # Topology information
+       #       cli_print_fmt1 2 "Topology changing" \
+       #               "$(stp_bridge_get_topology_change_detected ${zone})"
+       #       cli_print_fmt1 2 "Topology change time" \
+       #               "$(beautify_time $(stp_bridge_get_topology_change_timer ${zone}))"
+       #       cli_print_fmt1 2 "Topology change count" \
+       #               "$(stp_bridge_get_topology_change_count ${zone})"
+       #       cli_space
+       else
+               cli_print 2 "Disabled"
+               cli_space
+       fi
+
+       #cli_headline 2 "Ports"
+       #zone_ports_status ${zone}
+       #cli_space
+
+       #cli_headline 2 "Configurations"
+       #zone_configs_cmd status ${zone}
+       #cli_space
+
+       exit ${EXIT_OK}
+}