blob: d913f7c3cc091623a44e71dc6ff5863df02bd5eb [file] [log] [blame]
Isaku Yamahata0dd34df2012-12-28 13:15:31 +09001# common functions for ovs based plugin
2# -------------------------------------
3
4# Save trace setting
Dean Troyere3a91602014-03-28 12:40:56 -05005OVSB_XTRACE=$(set +o | grep xtrace)
Isaku Yamahata0dd34df2012-12-28 13:15:31 +09006set +o xtrace
7
JordanP614202f2013-05-16 11:16:13 +02008OVS_BRIDGE=${OVS_BRIDGE:-br-int}
9PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex}
James Chapmanc83cc752014-06-11 19:29:26 +010010OVS_DATAPATH_TYPE=${OVS_DATAPATH_TYPE:-""}
JordanP614202f2013-05-16 11:16:13 +020011
Ian Wienandaee18c72014-02-21 15:35:08 +110012function is_neutron_ovs_base_plugin {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090013 # Yes, we use OVS.
14 return 0
15}
16
Ian Wienandaee18c72014-02-21 15:35:08 +110017function _neutron_ovs_base_setup_bridge {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090018 local bridge=$1
Mark McClainb05c8762013-07-06 23:29:39 -040019 neutron-ovs-cleanup
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090020 sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge
James Chapmanc83cc752014-06-11 19:29:26 +010021 if [[ $OVS_DATAPATH_TYPE != "" ]]; then
22 sudo ovs-vsctl set Bridge $bridge datapath_type=${OVS_DATAPATH_TYPE}
23 fi
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090024 sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge
25}
26
Ian Wienandaee18c72014-02-21 15:35:08 +110027function neutron_ovs_base_cleanup {
Mark McClainb05c8762013-07-06 23:29:39 -040028 # remove all OVS ports that look like Neutron created ports
JordanP614202f2013-05-16 11:16:13 +020029 for port in $(sudo ovs-vsctl list port | grep -o -e tap[0-9a-f\-]* -e q[rg]-[0-9a-f\-]*); do
30 sudo ovs-vsctl del-port ${port}
31 done
32
Mark McClainb05c8762013-07-06 23:29:39 -040033 # remove all OVS bridges created by Neutron
JordanP614202f2013-05-16 11:16:13 +020034 for bridge in $(sudo ovs-vsctl list-br | grep -o -e ${OVS_BRIDGE} -e ${PUBLIC_BRIDGE}); do
35 sudo ovs-vsctl del-br ${bridge}
36 done
37}
38
Kyle Mestery86af4a02014-06-24 11:07:54 +000039function _neutron_ovs_base_install_ubuntu_dkms {
40 # install Dynamic Kernel Module Support packages if needed
41 local kernel_version=$(uname -r)
42 local kernel_major_minor=`echo $kernel_version | cut -d. -f1-2`
43 # From kernel 3.13 on, openvswitch-datapath-dkms is not needed
44 if [ `vercmp_numbers "$kernel_major_minor" "3.13"` -lt "0" ]; then
45 install_package "dkms openvswitch-datapath-dkms linux-headers-$kernel_version"
46 fi
47}
48
Ian Wienandaee18c72014-02-21 15:35:08 +110049function _neutron_ovs_base_install_agent_packages {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090050 # Install deps
Kyle Mestery86af4a02014-06-24 11:07:54 +000051 install_package $(get_packages "openvswitch")
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090052 if is_ubuntu; then
Kyle Mestery86af4a02014-06-24 11:07:54 +000053 _neutron_ovs_base_install_ubuntu_dkms
Sean M. Collinsd738a9e2014-08-28 15:32:44 -040054 restart_service openvswitch-switch
Gary Kotton5452b182013-02-25 13:02:38 +000055 elif is_fedora; then
Gary Kotton5452b182013-02-25 13:02:38 +000056 restart_service openvswitch
57 elif is_suse; then
Vincent Untzcf6d8092013-07-04 09:59:34 +020058 restart_service openvswitch-switch
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090059 fi
60}
61
Ian Wienandaee18c72014-02-21 15:35:08 +110062function _neutron_ovs_base_configure_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -040063 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090064}
65
Ian Wienandaee18c72014-02-21 15:35:08 +110066function _neutron_ovs_base_configure_firewall_driver {
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090067 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -040068 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090069 else
Mark McClainb05c8762013-07-06 23:29:39 -040070 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.firewall.NoopFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090071 fi
72}
73
Ian Wienandaee18c72014-02-21 15:35:08 +110074function _neutron_ovs_base_configure_l3_agent {
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +090075 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
76 iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge ""
77 else
78 iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
79 fi
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090080
Mark McClainb05c8762013-07-06 23:29:39 -040081 neutron-ovs-cleanup
Dave Tuckerf60e8c02014-06-11 17:02:24 +010082 # --no-wait causes a race condition if $PUBLIC_BRIDGE is not up when ip addr flush is called
83 sudo ovs-vsctl -- --may-exist add-br $PUBLIC_BRIDGE
84 sudo ovs-vsctl br-set-external-id $PUBLIC_BRIDGE bridge-id $PUBLIC_BRIDGE
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090085 # ensure no IP is configured on the public bridge
86 sudo ip addr flush dev $PUBLIC_BRIDGE
87}
88
Ian Wienandaee18c72014-02-21 15:35:08 +110089function _neutron_ovs_base_configure_nova_vif_driver {
Aaron Rosen4540d002013-10-24 13:59:33 -070090 :
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090091}
92
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090093# Restore xtrace
Dean Troyere3a91602014-03-28 12:40:56 -050094$OVSB_XTRACE