Skip to content

Commit 0dd34df

Browse files
author
Isaku Yamahata
committed
lib/quantum: refactor quantum plugins and third party
As quantum plugin support is coming like floodlight, nvp and nec, it's worth while to refactor quantum plugin logic so that each plugin can be modified/enhanced intervening with other quantum plugin. And new plugin support can be added easily (hopefully) without modifying core logic. Change-Id: Ic5ab5b993272fdd3b4e779823323777a845ee681
1 parent e575b6f commit 0dd34df

File tree

12 files changed

+517
-304
lines changed

12 files changed

+517
-304
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Gabriel Hurley <[email protected]>
1919
Gary Kotton <[email protected]>
2020
Hengqing Hu <[email protected]>
2121
Hua ZHANG <[email protected]>
22+
Isaku Yamahata <[email protected]>
2223
Jake Dahn <[email protected]>
2324
James E. Blair <[email protected]>
2425
Jason Cannavale <[email protected]>

lib/nova

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ function configure_nova() {
229229
configure_baremetal_nova_dirs
230230
fi
231231

232-
if is_service_enabled quantum && is_quantum_ovs_base_plugin "$Q_PLUGIN" && ! sudo grep -q '^cgroup_device_acl' $QEMU_CONF ; then
232+
if is_service_enabled quantum && is_quantum_ovs_base_plugin && ! sudo grep -q '^cgroup_device_acl' $QEMU_CONF ; then
233233
# Add /dev/net/tun to cgroup_device_acls, needed for type=ethernet interfaces
234234
cat <<EOF | sudo tee -a $QEMU_CONF
235235
cgroup_device_acl = [

lib/quantum

Lines changed: 39 additions & 289 deletions
Large diffs are not rendered by default.

lib/quantum_plugins/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Quantum plugin specific files
2+
=============================
3+
Quantum plugins require plugin specific behavior.
4+
The files under the directory, ``lib/quantum_plugins/``, will be used
5+
when their service is enabled.
6+
Each plugin has ``lib/quantum_plugins/$Q_PLUGIN`` and define the following
7+
functions.
8+
Plugin specific configuration variables should be in this file.
9+
10+
* filename: ``$Q_PLUGIN``
11+
* The corresponding file name MUST be the same to plugin name ``$Q_PLUGIN``.
12+
Plugin specific configuration variables should be in this file.
13+
14+
functions
15+
---------
16+
``lib/quantum`` calls the following functions when the ``$Q_PLUGIN`` is enabled
17+
18+
* ``quantum_plugin_create_nova_conf`` :
19+
set ``NOVA_VIF_DRIVER`` and optionally set options in nova_conf
20+
e.g.
21+
NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver"}
22+
* ``quantum_plugin_install_agent_packages`` :
23+
install packages that is specific to plugin agent
24+
e.g.
25+
install_package bridge-utils
26+
* ``quantum_plugin_configure_common`` :
27+
set plugin-specific variables, ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``,
28+
``Q_DB_NAME``, ``Q_PLUGIN_CLASS``
29+
* ``quantum_plugin_configure_debug_command``
30+
* ``quantum_plugin_configure_dhcp_agent``
31+
* ``quantum_plugin_configure_l3_agent``
32+
* ``quantum_plugin_configure_plugin_agent``
33+
* ``quantum_plugin_configure_service``
34+
* ``quantum_plugin_setup_interface_driver``
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Quantum Big Switch/FloodLight plugin
2+
# ------------------------------------
3+
4+
# Save trace setting
5+
XTRACE=$(set +o | grep xtrace)
6+
set +o xtrace
7+
8+
source $TOP_DIR/lib/quantum_plugins/ovs_base
9+
source $TOP_DIR/lib/quantum_thirdparty/bigswitch_floodlight # for third party service specific configuration values
10+
11+
function quantum_plugin_create_nova_conf() {
12+
NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver"}
13+
}
14+
15+
function quantum_plugin_install_agent_packages() {
16+
_quantum_ovs_base_install_agent_packages
17+
}
18+
19+
function quantum_plugin_configure_common() {
20+
Q_PLUGIN_CONF_PATH=etc/quantum/plugins/bigswitch
21+
Q_PLUGIN_CONF_FILENAME=restproxy.ini
22+
Q_DB_NAME="restproxy_quantum"
23+
Q_PLUGIN_CLASS="quantum.plugins.bigswitch.plugin.QuantumRestProxyV2"
24+
BS_FL_CONTROLLERS_PORT=${BS_FL_CONTROLLERS_PORT:-localhost:80}
25+
BS_FL_CONTROLLER_TIMEOUT=${BS_FL_CONTROLLER_TIMEOUT:-10}
26+
}
27+
28+
function quantum_plugin_configure_debug_command() {
29+
_quantum_ovs_base_configure_debug_command
30+
}
31+
32+
function quantum_plugin_configure_dhcp_agent() {
33+
:
34+
}
35+
36+
function quantum_plugin_configure_l3_agent() {
37+
_quantum_ovs_base_configure_l3_agent
38+
}
39+
40+
function quantum_plugin_configure_plugin_agent() {
41+
:
42+
}
43+
44+
function quantum_plugin_configure_service() {
45+
iniset /$Q_PLUGIN_CONF_FILE RESTPROXY servers $BS_FL_CONTROLLERS_PORT
46+
iniset /$Q_PLUGIN_CONF_FILE RESTPROXY servertimeout $BS_FL_CONTROLLER_TIMEOUT
47+
}
48+
49+
function quantum_plugin_setup_interface_driver() {
50+
local conf_file=$1
51+
iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver
52+
}
53+
54+
# Restore xtrace
55+
$XTRACE

lib/quantum_plugins/linuxbridge

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Quantum Linux Bridge plugin
2+
# ---------------------------
3+
4+
# Save trace setting
5+
XTRACE=$(set +o | grep xtrace)
6+
set +o xtrace
7+
8+
function is_quantum_ovs_base_plugin() {
9+
# linuxbridge doesn't use OVS
10+
return 1
11+
}
12+
13+
function quantum_plugin_create_nova_conf() {
14+
NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.QuantumLinuxBridgeVIFDriver"}
15+
}
16+
17+
function quantum_plugin_install_agent_packages() {
18+
install_package bridge-utils
19+
}
20+
21+
function quantum_plugin_configure_common() {
22+
Q_PLUGIN_CONF_PATH=etc/quantum/plugins/linuxbridge
23+
Q_PLUGIN_CONF_FILENAME=linuxbridge_conf.ini
24+
Q_DB_NAME="quantum_linux_bridge"
25+
Q_PLUGIN_CLASS="quantum.plugins.linuxbridge.lb_quantum_plugin.LinuxBridgePluginV2"
26+
}
27+
28+
function quantum_plugin_configure_debug_command() {
29+
iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT external_network_bridge
30+
}
31+
32+
function quantum_plugin_configure_dhcp_agent() {
33+
:
34+
}
35+
36+
function quantum_plugin_configure_l3_agent() {
37+
iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge
38+
}
39+
40+
function quantum_plugin_configure_plugin_agent() {
41+
# Setup physical network interface mappings. Override
42+
# ``LB_VLAN_RANGES`` and ``LB_INTERFACE_MAPPINGS`` in ``localrc`` for more
43+
# complex physical network configurations.
44+
if [[ "$LB_INTERFACE_MAPPINGS" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]] && [[ "$LB_PHYSICAL_INTERFACE" != "" ]]; then
45+
LB_INTERFACE_MAPPINGS=$PHYSICAL_NETWORK:$LB_PHYSICAL_INTERFACE
46+
fi
47+
if [[ "$LB_INTERFACE_MAPPINGS" != "" ]]; then
48+
iniset /$Q_PLUGIN_CONF_FILE LINUX_BRIDGE physical_interface_mappings $LB_INTERFACE_MAPPINGS
49+
fi
50+
AGENT_BINARY="$QUANTUM_DIR/bin/quantum-linuxbridge-agent"
51+
}
52+
53+
function quantum_plugin_configure_service() {
54+
if [[ "$ENABLE_TENANT_VLANS" = "True" ]]; then
55+
iniset /$Q_PLUGIN_CONF_FILE VLANS tenant_network_type vlan
56+
else
57+
echo "WARNING - The linuxbridge plugin is using local tenant networks, with no connectivity between hosts."
58+
fi
59+
60+
# Override ``LB_VLAN_RANGES`` and ``LB_INTERFACE_MAPPINGS`` in ``localrc``
61+
# for more complex physical network configurations.
62+
if [[ "$LB_VLAN_RANGES" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]]; then
63+
LB_VLAN_RANGES=$PHYSICAL_NETWORK
64+
if [[ "$TENANT_VLAN_RANGE" != "" ]]; then
65+
LB_VLAN_RANGES=$LB_VLAN_RANGES:$TENANT_VLAN_RANGE
66+
fi
67+
fi
68+
if [[ "$LB_VLAN_RANGES" != "" ]]; then
69+
iniset /$Q_PLUGIN_CONF_FILE VLANS network_vlan_ranges $LB_VLAN_RANGES
70+
fi
71+
}
72+
73+
function quantum_plugin_setup_interface_driver() {
74+
local conf_file=$1
75+
iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.BridgeInterfaceDriver
76+
}
77+
78+
# Restore xtrace
79+
$XTRACE

lib/quantum_plugins/openvswitch

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Quantum Open vSwtich plugin
2+
# ---------------------------
3+
4+
# Save trace setting
5+
XTRACE=$(set +o | grep xtrace)
6+
set +o xtrace
7+
8+
source $TOP_DIR/lib/quantum_plugins/ovs_base
9+
10+
function quantum_plugin_create_nova_conf() {
11+
NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver"}
12+
if [ "$VIRT_DRIVER" = 'xenserver' ]; then
13+
iniset $NOVA_CONF DEFAULT xenapi_vif_driver nova.virt.xenapi.vif.XenAPIOpenVswitchDriver
14+
iniset $NOVA_CONF DEFAULT xenapi_ovs_integration_bridge $FLAT_NETWORK_BRIDGE
15+
fi
16+
}
17+
18+
function quantum_plugin_install_agent_packages() {
19+
_quantum_ovs_base_install_agent_packages
20+
}
21+
22+
function quantum_plugin_configure_common() {
23+
Q_PLUGIN_CONF_PATH=etc/quantum/plugins/openvswitch
24+
Q_PLUGIN_CONF_FILENAME=ovs_quantum_plugin.ini
25+
Q_DB_NAME="ovs_quantum"
26+
Q_PLUGIN_CLASS="quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2"
27+
}
28+
29+
function quantum_plugin_configure_debug_command() {
30+
_quantum_ovs_base_configure_debug_command
31+
}
32+
33+
function quantum_plugin_configure_dhcp_agent() {
34+
:
35+
}
36+
37+
function quantum_plugin_configure_l3_agent() {
38+
_quantum_ovs_base_configure_l3_agent
39+
}
40+
41+
function quantum_plugin_configure_plugin_agent() {
42+
# Setup integration bridge
43+
OVS_BRIDGE=${OVS_BRIDGE:-br-int}
44+
_quantum_ovs_base_setup_bridge $OVS_BRIDGE
45+
46+
# Setup agent for tunneling
47+
if [[ "$OVS_ENABLE_TUNNELING" = "True" ]]; then
48+
# Verify tunnels are supported
49+
# REVISIT - also check kernel module support for GRE and patch ports
50+
OVS_VERSION=`ovs-vsctl --version | head -n 1 | awk '{print $4;}'`
51+
if [ $OVS_VERSION \< "1.4" ] && ! is_service_enabled q-svc ; then
52+
echo "You are running OVS version $OVS_VERSION."
53+
echo "OVS 1.4+ is required for tunneling between multiple hosts."
54+
exit 1
55+
fi
56+
iniset /$Q_PLUGIN_CONF_FILE OVS enable_tunneling True
57+
iniset /$Q_PLUGIN_CONF_FILE OVS local_ip $HOST_IP
58+
fi
59+
60+
# Setup physical network bridge mappings. Override
61+
# ``OVS_VLAN_RANGES`` and ``OVS_BRIDGE_MAPPINGS`` in ``localrc`` for more
62+
# complex physical network configurations.
63+
if [[ "$OVS_BRIDGE_MAPPINGS" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]] && [[ "$OVS_PHYSICAL_BRIDGE" != "" ]]; then
64+
OVS_BRIDGE_MAPPINGS=$PHYSICAL_NETWORK:$OVS_PHYSICAL_BRIDGE
65+
66+
# Configure bridge manually with physical interface as port for multi-node
67+
sudo ovs-vsctl --no-wait -- --may-exist add-br $OVS_PHYSICAL_BRIDGE
68+
fi
69+
if [[ "$OVS_BRIDGE_MAPPINGS" != "" ]]; then
70+
iniset /$Q_PLUGIN_CONF_FILE OVS bridge_mappings $OVS_BRIDGE_MAPPINGS
71+
fi
72+
AGENT_BINARY="$QUANTUM_DIR/bin/quantum-openvswitch-agent"
73+
74+
if [ "$VIRT_DRIVER" = 'xenserver' ]; then
75+
# Nova will always be installed along with quantum for a domU
76+
# devstack install, so it should be safe to rely on nova.conf
77+
# for xenapi configuration.
78+
Q_RR_DOM0_COMMAND="$QUANTUM_DIR/bin/quantum-rootwrap-dom0 $NOVA_CONF"
79+
# Under XS/XCP, the ovs agent needs to target the dom0
80+
# integration bridge. This is enabled by using a root wrapper
81+
# that executes commands on dom0 via a XenAPI plugin.
82+
iniset /$Q_PLUGIN_CONF_FILE AGENT root_helper "$Q_RR_DOM0_COMMAND"
83+
84+
# FLAT_NETWORK_BRIDGE is the dom0 integration bridge. To
85+
# ensure the bridge lacks direct connectivity, set
86+
# VM_VLAN=-1;VM_DEV=invalid in localrc
87+
iniset /$Q_PLUGIN_CONF_FILE OVS integration_bridge $FLAT_NETWORK_BRIDGE
88+
89+
# The ovs agent needs to ensure that the ports associated with
90+
# a given network share the same local vlan tag. On
91+
# single-node XS/XCP, this requires monitoring both the dom0
92+
# bridge, where VM's are attached, and the domU bridge, where
93+
# dhcp servers are attached.
94+
if is_service_enabled q-dhcp; then
95+
iniset /$Q_PLUGIN_CONF_FILE OVS domu_integration_bridge $OVS_BRIDGE
96+
# DomU will use the regular rootwrap
97+
iniset /$Q_PLUGIN_CONF_FILE AGENT domu_root_helper "$Q_RR_COMMAND"
98+
# Plug the vm interface into the domU integration bridge.
99+
sudo ip addr flush dev $GUEST_INTERFACE_DEFAULT
100+
sudo ip link set $OVS_BRIDGE up
101+
# Assign the VM IP only if it has been set explicitly
102+
if [[ "$VM_IP" != "" ]]; then
103+
sudo ip addr add $VM_IP dev $OVS_BRIDGE
104+
fi
105+
sudo ovs-vsctl add-port $OVS_BRIDGE $GUEST_INTERFACE_DEFAULT
106+
fi
107+
fi
108+
}
109+
110+
function quantum_plugin_configure_service() {
111+
if [[ "$ENABLE_TENANT_TUNNELS" = "True" ]]; then
112+
iniset /$Q_PLUGIN_CONF_FILE OVS tenant_network_type gre
113+
iniset /$Q_PLUGIN_CONF_FILE OVS tunnel_id_ranges $TENANT_TUNNEL_RANGES
114+
elif [[ "$ENABLE_TENANT_VLANS" = "True" ]]; then
115+
iniset /$Q_PLUGIN_CONF_FILE OVS tenant_network_type vlan
116+
else
117+
echo "WARNING - The openvswitch plugin is using local tenant networks, with no connectivity between hosts."
118+
fi
119+
120+
# Override ``OVS_VLAN_RANGES`` and ``OVS_BRIDGE_MAPPINGS`` in ``localrc``
121+
# for more complex physical network configurations.
122+
if [[ "$OVS_VLAN_RANGES" = "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]]; then
123+
OVS_VLAN_RANGES=$PHYSICAL_NETWORK
124+
if [[ "$TENANT_VLAN_RANGE" != "" ]]; then
125+
OVS_VLAN_RANGES=$OVS_VLAN_RANGES:$TENANT_VLAN_RANGE
126+
fi
127+
fi
128+
if [[ "$OVS_VLAN_RANGES" != "" ]]; then
129+
iniset /$Q_PLUGIN_CONF_FILE OVS network_vlan_ranges $OVS_VLAN_RANGES
130+
fi
131+
132+
# Enable tunnel networks if selected
133+
if [[ $OVS_ENABLE_TUNNELING = "True" ]]; then
134+
iniset /$Q_PLUGIN_CONF_FILE OVS enable_tunneling True
135+
fi
136+
}
137+
138+
function quantum_plugin_setup_interface_driver() {
139+
local conf_file=$1
140+
iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver
141+
}
142+
143+
# Restore xtrace
144+
$XTRACE

lib/quantum_plugins/ovs_base

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# common functions for ovs based plugin
2+
# -------------------------------------
3+
4+
# Save trace setting
5+
XTRACE=$(set +o | grep xtrace)
6+
set +o xtrace
7+
8+
function is_quantum_ovs_base_plugin() {
9+
# Yes, we use OVS.
10+
return 0
11+
}
12+
13+
function _quantum_ovs_base_setup_bridge() {
14+
local bridge=$1
15+
quantum-ovs-cleanup --ovs_integration_bridge $bridge
16+
sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge
17+
sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge
18+
}
19+
20+
function _quantum_ovs_base_install_agent_packages() {
21+
local kernel_version
22+
# Install deps
23+
# FIXME add to ``files/apts/quantum``, but don't install if not needed!
24+
if is_ubuntu; then
25+
kernel_version=`cat /proc/version | cut -d " " -f3`
26+
install_package make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms linux-headers-$kernel_version
27+
else
28+
### FIXME(dtroyer): Find RPMs for OpenVSwitch
29+
echo "OpenVSwitch packages need to be located"
30+
# Fedora does not started OVS by default
31+
restart_service openvswitch
32+
fi
33+
}
34+
35+
function _quantum_ovs_base_configure_debug_command() {
36+
iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
37+
}
38+
39+
function _quantum_ovs_base_configure_l3_agent() {
40+
iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
41+
42+
quantum-ovs-cleanup --external_network_bridge $PUBLIC_BRIDGE
43+
sudo ovs-vsctl --no-wait -- --may-exist add-br $PUBLIC_BRIDGE
44+
# ensure no IP is configured on the public bridge
45+
sudo ip addr flush dev $PUBLIC_BRIDGE
46+
}
47+
48+
# Restore xtrace
49+
$XTRACE

0 commit comments

Comments
 (0)