| Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 | # | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 3 | # common functions for ovs based plugin | 
|  | 4 | # ------------------------------------- | 
|  | 5 |  | 
|  | 6 | # Save trace setting | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 7 | _XTRACE_NEUTRON_OVS_BASE=$(set +o | grep xtrace) | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 8 | set +o xtrace | 
|  | 9 |  | 
| JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 10 | OVS_BRIDGE=${OVS_BRIDGE:-br-int} | 
| Michal Ptacek | c160555 | 2015-09-23 21:02:02 +0100 | [diff] [blame] | 11 | # OVS recognize default 'system' datapath or 'netdev' for userspace datapath | 
|  | 12 | OVS_DATAPATH_TYPE=${OVS_DATAPATH_TYPE:-system} | 
| Hirofumi Ichihara | d48d672 | 2015-07-04 22:58:44 +0900 | [diff] [blame] | 13 | OVS_TUNNEL_BRIDGE=${OVS_TUNNEL_BRIDGE:-br-tun} | 
| JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 14 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 15 | function is_neutron_ovs_base_plugin { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 16 | # Yes, we use OVS. | 
|  | 17 | return 0 | 
|  | 18 | } | 
|  | 19 |  | 
| Waldemar Znoinski | d4c8928 | 2015-05-07 17:14:21 +0100 | [diff] [blame] | 20 | function _neutron_ovs_base_add_bridge { | 
|  | 21 | local bridge=$1 | 
| Sean M. Collins | 75a6454 | 2016-08-01 14:41:10 -0400 | [diff] [blame] | 22 | local addbr_cmd="sudo ovs-vsctl -- --may-exist add-br $bridge" | 
| Waldemar Znoinski | d4c8928 | 2015-05-07 17:14:21 +0100 | [diff] [blame] | 23 |  | 
| Michal Ptacek | c160555 | 2015-09-23 21:02:02 +0100 | [diff] [blame] | 24 | if [ "$OVS_DATAPATH_TYPE" != "system" ] ; then | 
| Waldemar Znoinski | d4c8928 | 2015-05-07 17:14:21 +0100 | [diff] [blame] | 25 | addbr_cmd="$addbr_cmd -- set Bridge $bridge datapath_type=${OVS_DATAPATH_TYPE}" | 
|  | 26 | fi | 
|  | 27 |  | 
|  | 28 | $addbr_cmd | 
|  | 29 | } | 
|  | 30 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 31 | function _neutron_ovs_base_setup_bridge { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 32 | local bridge=$1 | 
| Gary Kotton | 2a59814 | 2016-11-29 03:48:34 -0800 | [diff] [blame] | 33 | neutron-ovs-cleanup --config-file $NEUTRON_CONF | 
| Waldemar Znoinski | d4c8928 | 2015-05-07 17:14:21 +0100 | [diff] [blame] | 34 | _neutron_ovs_base_add_bridge $bridge | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 35 | sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge | 
|  | 36 | } | 
|  | 37 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 38 | function neutron_ovs_base_cleanup { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 39 | # remove all OVS ports that look like Neutron created ports | 
| Zhenzan Zhou | 9a70448 | 2015-01-27 10:48:24 +0800 | [diff] [blame] | 40 | for port in $(sudo ovs-vsctl list port | grep -o -e [a-zA-Z\-]*tap[0-9a-f\-]* -e q[rg]-[0-9a-f\-]*); do | 
| JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 41 | sudo ovs-vsctl del-port ${port} | 
|  | 42 | done | 
|  | 43 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 44 | # remove all OVS bridges created by Neutron | 
| Hirofumi Ichihara | 7ab3e39 | 2015-07-04 23:11:52 +0900 | [diff] [blame] | 45 | for bridge in $(sudo ovs-vsctl list-br | grep -o -e ${OVS_BRIDGE} -e ${PUBLIC_BRIDGE} -e ${OVS_TUNNEL_BRIDGE}); do | 
| JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 46 | sudo ovs-vsctl del-br ${bridge} | 
|  | 47 | done | 
|  | 48 | } | 
|  | 49 |  | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 50 | function _neutron_ovs_base_install_ubuntu_dkms { | 
|  | 51 | # install Dynamic Kernel Module Support packages if needed | 
| Ian Wienand | ada886d | 2015-10-07 14:06:26 +1100 | [diff] [blame] | 52 | local kernel_version | 
|  | 53 | kernel_version=$(uname -r) | 
|  | 54 | local kernel_major_minor | 
|  | 55 | kernel_major_minor=`echo $kernel_version | cut -d. -f1-2` | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 56 | # From kernel 3.13 on, openvswitch-datapath-dkms is not needed | 
| Yi Zhao | 2ae8b09 | 2016-05-12 12:11:24 +0800 | [diff] [blame] | 57 | if vercmp "$kernel_major_minor" "<" "3.13" ; then | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 58 | install_package "dkms openvswitch-datapath-dkms linux-headers-$kernel_version" | 
|  | 59 | fi | 
|  | 60 | } | 
|  | 61 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 62 | function _neutron_ovs_base_install_agent_packages { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 63 | # Install deps | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 64 | install_package $(get_packages "openvswitch") | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 65 | if is_ubuntu; then | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 66 | _neutron_ovs_base_install_ubuntu_dkms | 
| Sean M. Collins | d738a9e | 2014-08-28 15:32:44 -0400 | [diff] [blame] | 67 | restart_service openvswitch-switch | 
| Gary Kotton | 5452b18 | 2013-02-25 13:02:38 +0000 | [diff] [blame] | 68 | elif is_fedora; then | 
| Gary Kotton | 5452b18 | 2013-02-25 13:02:38 +0000 | [diff] [blame] | 69 | restart_service openvswitch | 
| Zhang Jinnan | 4d8c03a | 2015-08-20 10:00:20 -0400 | [diff] [blame] | 70 | sudo systemctl enable openvswitch | 
| Gary Kotton | 5452b18 | 2013-02-25 13:02:38 +0000 | [diff] [blame] | 71 | elif is_suse; then | 
| Adam Spiers | bbb6b0c | 2019-01-25 00:29:42 +0000 | [diff] [blame] | 72 | if [[ $DISTRO == "sle12" ]] && vercmp "$os_RELEASE" "<" "12.2" ; then | 
| Dirk Mueller | 30b58bf | 2016-12-09 00:58:54 +0100 | [diff] [blame] | 73 | restart_service openvswitch-switch | 
|  | 74 | else | 
| Dirk Mueller | 486057f | 2018-03-21 13:59:18 +0100 | [diff] [blame] | 75 | # workaround for https://bugzilla.suse.com/show_bug.cgi?id=1085971 | 
|  | 76 | if [[ $DISTRO =~ "tumbleweed" ]]; then | 
|  | 77 | sudo sed -i -e "s,^OVS_USER_ID=.*,OVS_USER_ID='root:root'," /etc/sysconfig/openvswitch | 
|  | 78 | fi | 
|  | 79 | restart_service openvswitch || { | 
|  | 80 | journalctl -xe || : | 
|  | 81 | systemctl status openvswitch | 
|  | 82 | } | 
| Dirk Mueller | 30b58bf | 2016-12-09 00:58:54 +0100 | [diff] [blame] | 83 | fi | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 84 | fi | 
|  | 85 | } | 
|  | 86 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 87 | function _neutron_ovs_base_configure_firewall_driver { | 
| Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 88 | if [[ "$Q_USE_SECGROUP" == "True" ]]; then | 
| Jakub Libosvar | a99ab70 | 2018-05-14 16:12:52 +0200 | [diff] [blame] | 89 | iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver openvswitch | 
| Denis Buliga | 0bf75a4 | 2017-02-06 16:56:46 +0200 | [diff] [blame] | 90 | if ! running_in_container; then | 
|  | 91 | enable_kernel_bridge_firewall | 
|  | 92 | fi | 
| Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 93 | else | 
| Brian Haley | 30ab23c | 2016-11-02 16:30:31 -0400 | [diff] [blame] | 94 | iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver noop | 
| Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 95 | fi | 
|  | 96 | } | 
|  | 97 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 98 | function _neutron_ovs_base_configure_l3_agent { | 
| Derek Higgins | e3e9ea2 | 2018-11-09 15:43:13 +0000 | [diff] [blame] | 99 | if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" != "True" ]; then | 
|  | 100 | iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE | 
|  | 101 | fi | 
|  | 102 |  | 
| Gary Kotton | 2a59814 | 2016-11-29 03:48:34 -0800 | [diff] [blame] | 103 | neutron-ovs-cleanup --config-file $NEUTRON_CONF | 
| YAMAMOTO Takashi | 0f18c23 | 2014-09-12 23:44:58 +0900 | [diff] [blame] | 104 | if [[ "$Q_USE_PUBLIC_VETH" = "True" ]]; then | 
|  | 105 | ip link show $Q_PUBLIC_VETH_INT > /dev/null 2>&1 || | 
|  | 106 | sudo ip link add $Q_PUBLIC_VETH_INT type veth \ | 
|  | 107 | peer name $Q_PUBLIC_VETH_EX | 
|  | 108 | sudo ip link set $Q_PUBLIC_VETH_INT up | 
|  | 109 | sudo ip link set $Q_PUBLIC_VETH_EX up | 
|  | 110 | sudo ip addr flush dev $Q_PUBLIC_VETH_EX | 
|  | 111 | else | 
| Ihar Hrachyshka | 7b5c7dc | 2016-07-15 20:17:13 +0200 | [diff] [blame] | 112 | _neutron_ovs_base_add_public_bridge | 
| YAMAMOTO Takashi | 0f18c23 | 2014-09-12 23:44:58 +0900 | [diff] [blame] | 113 | sudo ovs-vsctl br-set-external-id $PUBLIC_BRIDGE bridge-id $PUBLIC_BRIDGE | 
| YAMAMOTO Takashi | 0f18c23 | 2014-09-12 23:44:58 +0900 | [diff] [blame] | 114 | fi | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 115 | } | 
|  | 116 |  | 
| Ihar Hrachyshka | 7b5c7dc | 2016-07-15 20:17:13 +0200 | [diff] [blame] | 117 | function _neutron_ovs_base_add_public_bridge { | 
|  | 118 | _neutron_ovs_base_add_bridge $PUBLIC_BRIDGE | 
|  | 119 | set_mtu $PUBLIC_BRIDGE $PUBLIC_BRIDGE_MTU | 
|  | 120 | } | 
|  | 121 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 122 | function _neutron_ovs_base_configure_nova_vif_driver { | 
| Aaron Rosen | 4540d00 | 2013-10-24 13:59:33 -0700 | [diff] [blame] | 123 | : | 
| Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 124 | } | 
|  | 125 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 126 | # Restore xtrace | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 127 | $_XTRACE_NEUTRON_OVS_BASE |