| 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 |  | 
| Slawek Kaplonski | 4185358 | 2021-07-06 12:05:31 +0200 | [diff] [blame] | 10 | # Load devstack ovs compliation and loading functions | 
 | 11 | source ${TOP_DIR}/lib/neutron_plugins/ovs_source | 
 | 12 |  | 
 | 13 | # Defaults | 
 | 14 | # -------- | 
 | 15 |  | 
| JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 16 | OVS_BRIDGE=${OVS_BRIDGE:-br-int} | 
| Michal Ptacek | c160555 | 2015-09-23 21:02:02 +0100 | [diff] [blame] | 17 | # OVS recognize default 'system' datapath or 'netdev' for userspace datapath | 
 | 18 | OVS_DATAPATH_TYPE=${OVS_DATAPATH_TYPE:-system} | 
| Hirofumi Ichihara | d48d672 | 2015-07-04 22:58:44 +0900 | [diff] [blame] | 19 | OVS_TUNNEL_BRIDGE=${OVS_TUNNEL_BRIDGE:-br-tun} | 
| JordanP | 614202f | 2013-05-16 11:16:13 +0200 | [diff] [blame] | 20 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 21 | function is_neutron_ovs_base_plugin { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 22 |     # Yes, we use OVS. | 
 | 23 |     return 0 | 
 | 24 | } | 
 | 25 |  | 
| Waldemar Znoinski | d4c8928 | 2015-05-07 17:14:21 +0100 | [diff] [blame] | 26 | function _neutron_ovs_base_add_bridge { | 
 | 27 |     local bridge=$1 | 
| Sean M. Collins | 75a6454 | 2016-08-01 14:41:10 -0400 | [diff] [blame] | 28 |     local addbr_cmd="sudo ovs-vsctl -- --may-exist add-br $bridge" | 
| Waldemar Znoinski | d4c8928 | 2015-05-07 17:14:21 +0100 | [diff] [blame] | 29 |  | 
| Michal Ptacek | c160555 | 2015-09-23 21:02:02 +0100 | [diff] [blame] | 30 |     if [ "$OVS_DATAPATH_TYPE" != "system" ] ; then | 
| Waldemar Znoinski | d4c8928 | 2015-05-07 17:14:21 +0100 | [diff] [blame] | 31 |         addbr_cmd="$addbr_cmd -- set Bridge $bridge datapath_type=${OVS_DATAPATH_TYPE}" | 
 | 32 |     fi | 
 | 33 |  | 
 | 34 |     $addbr_cmd | 
 | 35 | } | 
 | 36 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 37 | function _neutron_ovs_base_setup_bridge { | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 38 |     local bridge=$1 | 
| Gary Kotton | 2a59814 | 2016-11-29 03:48:34 -0800 | [diff] [blame] | 39 |     neutron-ovs-cleanup --config-file $NEUTRON_CONF | 
| Waldemar Znoinski | d4c8928 | 2015-05-07 17:14:21 +0100 | [diff] [blame] | 40 |     _neutron_ovs_base_add_bridge $bridge | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 41 |     sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge | 
 | 42 | } | 
 | 43 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 44 | function neutron_ovs_base_cleanup { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 45 |     # remove all OVS ports that look like Neutron created ports | 
| Zhenzan Zhou | 9a70448 | 2015-01-27 10:48:24 +0800 | [diff] [blame] | 46 |     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] | 47 |         sudo ovs-vsctl del-port ${port} | 
 | 48 |     done | 
 | 49 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 50 |     # remove all OVS bridges created by Neutron | 
| Hirofumi Ichihara | 7ab3e39 | 2015-07-04 23:11:52 +0900 | [diff] [blame] | 51 |     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] | 52 |         sudo ovs-vsctl del-br ${bridge} | 
 | 53 |     done | 
 | 54 | } | 
 | 55 |  | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 56 | function _neutron_ovs_base_install_ubuntu_dkms { | 
 | 57 |     # install Dynamic Kernel Module Support packages if needed | 
| Ian Wienand | ada886d | 2015-10-07 14:06:26 +1100 | [diff] [blame] | 58 |     local kernel_version | 
 | 59 |     kernel_version=$(uname -r) | 
 | 60 |     local kernel_major_minor | 
 | 61 |     kernel_major_minor=`echo $kernel_version | cut -d. -f1-2` | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 62 |     # From kernel 3.13 on, openvswitch-datapath-dkms is not needed | 
| Yi Zhao | 2ae8b09 | 2016-05-12 12:11:24 +0800 | [diff] [blame] | 63 |     if vercmp "$kernel_major_minor" "<" "3.13" ; then | 
| Kyle Mestery | 86af4a0 | 2014-06-24 11:07:54 +0000 | [diff] [blame] | 64 |         install_package "dkms openvswitch-datapath-dkms linux-headers-$kernel_version" | 
 | 65 |     fi | 
 | 66 | } | 
 | 67 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 68 | function _neutron_ovs_base_install_agent_packages { | 
| Slawek Kaplonski | 4185358 | 2021-07-06 12:05:31 +0200 | [diff] [blame] | 69 |     if [ "$Q_BUILD_OVS_FROM_GIT" == "True" ]; then | 
 | 70 |         remove_ovs_packages | 
| Rodolfo Alonso Hernandez | 8c67103 | 2022-02-09 18:01:46 +0000 | [diff] [blame] | 71 |         compile_ovs False /usr/local /var | 
| Slawek Kaplonski | 4185358 | 2021-07-06 12:05:31 +0200 | [diff] [blame] | 72 |         load_conntrack_gre_module | 
 | 73 |         start_new_ovs | 
 | 74 |     else | 
 | 75 |         # Install deps | 
 | 76 |         install_package $(get_packages "openvswitch") | 
 | 77 |         if is_ubuntu; then | 
 | 78 |             _neutron_ovs_base_install_ubuntu_dkms | 
| Dirk Mueller | 30b58bf | 2016-12-09 00:58:54 +0100 | [diff] [blame] | 79 |             restart_service openvswitch-switch | 
| Slawek Kaplonski | 4185358 | 2021-07-06 12:05:31 +0200 | [diff] [blame] | 80 |         elif is_fedora; then | 
 | 81 |             restart_service openvswitch | 
 | 82 |             sudo systemctl enable openvswitch | 
| 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 { | 
| Gary Kotton | 2a59814 | 2016-11-29 03:48:34 -0800 | [diff] [blame] | 99 |     neutron-ovs-cleanup --config-file $NEUTRON_CONF | 
| YAMAMOTO Takashi | 0f18c23 | 2014-09-12 23:44:58 +0900 | [diff] [blame] | 100 |     if [[ "$Q_USE_PUBLIC_VETH" = "True" ]]; then | 
 | 101 |         ip link show $Q_PUBLIC_VETH_INT > /dev/null 2>&1 || | 
 | 102 |         sudo ip link add $Q_PUBLIC_VETH_INT type veth \ | 
 | 103 |             peer name $Q_PUBLIC_VETH_EX | 
 | 104 |         sudo ip link set $Q_PUBLIC_VETH_INT up | 
 | 105 |         sudo ip link set $Q_PUBLIC_VETH_EX up | 
 | 106 |         sudo ip addr flush dev $Q_PUBLIC_VETH_EX | 
 | 107 |     else | 
| Ihar Hrachyshka | 7b5c7dc | 2016-07-15 20:17:13 +0200 | [diff] [blame] | 108 |         _neutron_ovs_base_add_public_bridge | 
| YAMAMOTO Takashi | 0f18c23 | 2014-09-12 23:44:58 +0900 | [diff] [blame] | 109 |         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] | 110 |     fi | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 111 | } | 
 | 112 |  | 
| Ihar Hrachyshka | 7b5c7dc | 2016-07-15 20:17:13 +0200 | [diff] [blame] | 113 | function _neutron_ovs_base_add_public_bridge { | 
 | 114 |     _neutron_ovs_base_add_bridge $PUBLIC_BRIDGE | 
 | 115 |     set_mtu $PUBLIC_BRIDGE $PUBLIC_BRIDGE_MTU | 
 | 116 | } | 
 | 117 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 118 | function _neutron_ovs_base_configure_nova_vif_driver { | 
| Aaron Rosen | 4540d00 | 2013-10-24 13:59:33 -0700 | [diff] [blame] | 119 |     : | 
| Akihiro MOTOKI | 3452f8e | 2013-03-21 14:11:27 +0900 | [diff] [blame] | 120 | } | 
 | 121 |  | 
| Isaku Yamahata | 0dd34df | 2012-12-28 13:15:31 +0900 | [diff] [blame] | 122 | # Restore xtrace | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 123 | $_XTRACE_NEUTRON_OVS_BASE |