| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 1 | # common functions for ovs based plugin | 
|  | 2 | # ------------------------------------- | 
|  | 3 |  | 
|  | 4 | # Save trace setting | 
| Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 5 | OVSB_XTRACE=$(set +o | grep xtrace) | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 6 | set +o xtrace | 
|  | 7 |  | 
| JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 8 | OVS_BRIDGE=${OVS_BRIDGE:-br-int} | 
|  | 9 | PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex} | 
| James Chapman | c83cc75 | 2014-06-11 19:29:26 +0100 | [diff] [blame] | 10 | OVS_DATAPATH_TYPE=${OVS_DATAPATH_TYPE:-""} | 
| JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 11 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 12 | function is_neutron_ovs_base_plugin { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 13 | # Yes, we use OVS. | 
|  | 14 | return 0 | 
|  | 15 | } | 
|  | 16 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 17 | function _neutron_ovs_base_setup_bridge { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 18 | local bridge=$1 | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 19 | neutron-ovs-cleanup | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 20 | sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge | 
| James Chapman | c83cc75 | 2014-06-11 19:29:26 +0100 | [diff] [blame] | 21 | if [[ $OVS_DATAPATH_TYPE != "" ]]; then | 
|  | 22 | sudo ovs-vsctl set Bridge $bridge datapath_type=${OVS_DATAPATH_TYPE} | 
|  | 23 | fi | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 24 | sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge | 
|  | 25 | } | 
|  | 26 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 27 | function neutron_ovs_base_cleanup { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 28 | # remove all OVS ports that look like Neutron created ports | 
| JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 29 | 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 McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 33 | # remove all OVS bridges created by Neutron | 
| JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 34 | 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 Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 39 | function _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 Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 49 | function _neutron_ovs_base_install_agent_packages { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 50 | # Install deps | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 51 | install_package $(get_packages "openvswitch") | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 52 | if is_ubuntu; then | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 53 | _neutron_ovs_base_install_ubuntu_dkms | 
| Gary Kotton | 5452b18 | 2013-02-25 13:02:38 +0000 | [diff] [blame] | 54 | elif is_fedora; then | 
| Gary Kotton | 5452b18 | 2013-02-25 13:02:38 +0000 | [diff] [blame] | 55 | restart_service openvswitch | 
|  | 56 | elif is_suse; then | 
| Vincent Untz | cf6d809 | 2013-07-04 09:59:34 +0200 | [diff] [blame] | 57 | restart_service openvswitch-switch | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 58 | fi | 
|  | 59 | } | 
|  | 60 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 61 | function _neutron_ovs_base_configure_debug_command { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 62 | iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 63 | } | 
|  | 64 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 65 | function _neutron_ovs_base_configure_firewall_driver { | 
| Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 66 | if [[ "$Q_USE_SECGROUP" == "True" ]]; then | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 67 | iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver | 
| Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 68 | else | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 69 | iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.firewall.NoopFirewallDriver | 
| Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 70 | fi | 
|  | 71 | } | 
|  | 72 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 73 | function _neutron_ovs_base_configure_l3_agent { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 74 | iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE | 
|  | 75 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 76 | neutron-ovs-cleanup | 
| Dave Tucker | f60e8c0 | 2014-06-11 17:02:24 +0100 | [diff] [blame] | 77 | # --no-wait causes a race condition if $PUBLIC_BRIDGE is not up when ip addr flush is called | 
|  | 78 | sudo ovs-vsctl -- --may-exist add-br $PUBLIC_BRIDGE | 
|  | 79 | sudo ovs-vsctl br-set-external-id $PUBLIC_BRIDGE bridge-id $PUBLIC_BRIDGE | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 80 | # ensure no IP is configured on the public bridge | 
|  | 81 | sudo ip addr flush dev $PUBLIC_BRIDGE | 
|  | 82 | } | 
|  | 83 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 84 | function _neutron_ovs_base_configure_nova_vif_driver { | 
| Aaron Rosen | 4540d00 | 2013-10-24 13:59:33 -0700 | [diff] [blame] | 85 | : | 
| Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 86 | } | 
|  | 87 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 88 | # Restore xtrace | 
| Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 89 | $OVSB_XTRACE |