blob: d3fd198b08a7ef37713a1ad4f90e7110c69415bc [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Isaku Yamahata0dd34df2012-12-28 13:15:31 +09003# common functions for ovs based plugin
4# -------------------------------------
5
6# Save trace setting
Dean Troyere3a91602014-03-28 12:40:56 -05007OVSB_XTRACE=$(set +o | grep xtrace)
Isaku Yamahata0dd34df2012-12-28 13:15:31 +09008set +o xtrace
9
JordanP614202f2013-05-16 11:16:13 +020010OVS_BRIDGE=${OVS_BRIDGE:-br-int}
Michal Ptacekc1605552015-09-23 21:02:02 +010011# OVS recognize default 'system' datapath or 'netdev' for userspace datapath
12OVS_DATAPATH_TYPE=${OVS_DATAPATH_TYPE:-system}
Hirofumi Ichiharad48d6722015-07-04 22:58:44 +090013OVS_TUNNEL_BRIDGE=${OVS_TUNNEL_BRIDGE:-br-tun}
JordanP614202f2013-05-16 11:16:13 +020014
Ian Wienandaee18c72014-02-21 15:35:08 +110015function is_neutron_ovs_base_plugin {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090016 # Yes, we use OVS.
17 return 0
18}
19
Waldemar Znoinskid4c89282015-05-07 17:14:21 +010020function _neutron_ovs_base_add_bridge {
21 local bridge=$1
22 local addbr_cmd="sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge"
23
Michal Ptacekc1605552015-09-23 21:02:02 +010024 if [ "$OVS_DATAPATH_TYPE" != "system" ] ; then
Waldemar Znoinskid4c89282015-05-07 17:14:21 +010025 addbr_cmd="$addbr_cmd -- set Bridge $bridge datapath_type=${OVS_DATAPATH_TYPE}"
26 fi
27
28 $addbr_cmd
29}
30
Ian Wienandaee18c72014-02-21 15:35:08 +110031function _neutron_ovs_base_setup_bridge {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090032 local bridge=$1
Mark McClainb05c8762013-07-06 23:29:39 -040033 neutron-ovs-cleanup
Waldemar Znoinskid4c89282015-05-07 17:14:21 +010034 _neutron_ovs_base_add_bridge $bridge
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090035 sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge
36}
37
Ian Wienandaee18c72014-02-21 15:35:08 +110038function neutron_ovs_base_cleanup {
Mark McClainb05c8762013-07-06 23:29:39 -040039 # remove all OVS ports that look like Neutron created ports
Zhenzan Zhou9a704482015-01-27 10:48:24 +080040 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
JordanP614202f2013-05-16 11:16:13 +020041 sudo ovs-vsctl del-port ${port}
42 done
43
Mark McClainb05c8762013-07-06 23:29:39 -040044 # remove all OVS bridges created by Neutron
Hirofumi Ichihara7ab3e392015-07-04 23:11:52 +090045 for bridge in $(sudo ovs-vsctl list-br | grep -o -e ${OVS_BRIDGE} -e ${PUBLIC_BRIDGE} -e ${OVS_TUNNEL_BRIDGE}); do
JordanP614202f2013-05-16 11:16:13 +020046 sudo ovs-vsctl del-br ${bridge}
47 done
48}
49
Kyle Mestery86af4a02014-06-24 11:07:54 +000050function _neutron_ovs_base_install_ubuntu_dkms {
51 # install Dynamic Kernel Module Support packages if needed
Ian Wienandada886d2015-10-07 14:06:26 +110052 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 Mestery86af4a02014-06-24 11:07:54 +000056 # From kernel 3.13 on, openvswitch-datapath-dkms is not needed
57 if [ `vercmp_numbers "$kernel_major_minor" "3.13"` -lt "0" ]; then
58 install_package "dkms openvswitch-datapath-dkms linux-headers-$kernel_version"
59 fi
60}
61
Ian Wienandaee18c72014-02-21 15:35:08 +110062function _neutron_ovs_base_install_agent_packages {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090063 # Install deps
Kyle Mestery86af4a02014-06-24 11:07:54 +000064 install_package $(get_packages "openvswitch")
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090065 if is_ubuntu; then
Kyle Mestery86af4a02014-06-24 11:07:54 +000066 _neutron_ovs_base_install_ubuntu_dkms
Sean M. Collinsd738a9e2014-08-28 15:32:44 -040067 restart_service openvswitch-switch
Gary Kotton5452b182013-02-25 13:02:38 +000068 elif is_fedora; then
Gary Kotton5452b182013-02-25 13:02:38 +000069 restart_service openvswitch
70 elif is_suse; then
Vincent Untzcf6d8092013-07-04 09:59:34 +020071 restart_service openvswitch-switch
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090072 fi
73}
74
Ian Wienandaee18c72014-02-21 15:35:08 +110075function _neutron_ovs_base_configure_debug_command {
YAMAMOTO Takashi98a0ad42014-11-21 10:42:18 +090076 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
77 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT external_network_bridge ""
78 else
79 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
80 fi
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090081}
82
Ian Wienandaee18c72014-02-21 15:35:08 +110083function _neutron_ovs_base_configure_firewall_driver {
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090084 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -040085 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090086 else
Mark McClainb05c8762013-07-06 23:29:39 -040087 iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.firewall.NoopFirewallDriver
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +090088 fi
89}
90
Ian Wienandaee18c72014-02-21 15:35:08 +110091function _neutron_ovs_base_configure_l3_agent {
YAMAMOTO Takashi6a633fd2014-07-23 12:02:18 +090092 if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
93 iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge ""
94 else
95 iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
96 fi
Isaku Yamahata0dd34df2012-12-28 13:15:31 +090097
Mark McClainb05c8762013-07-06 23:29:39 -040098 neutron-ovs-cleanup
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +090099 if [[ "$Q_USE_PUBLIC_VETH" = "True" ]]; then
100 ip link show $Q_PUBLIC_VETH_INT > /dev/null 2>&1 ||
101 sudo ip link add $Q_PUBLIC_VETH_INT type veth \
102 peer name $Q_PUBLIC_VETH_EX
103 sudo ip link set $Q_PUBLIC_VETH_INT up
104 sudo ip link set $Q_PUBLIC_VETH_EX up
105 sudo ip addr flush dev $Q_PUBLIC_VETH_EX
106 else
Waldemar Znoinskid4c89282015-05-07 17:14:21 +0100107 _neutron_ovs_base_add_bridge $PUBLIC_BRIDGE
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900108 sudo ovs-vsctl br-set-external-id $PUBLIC_BRIDGE bridge-id $PUBLIC_BRIDGE
YAMAMOTO Takashi0f18c232014-09-12 23:44:58 +0900109 fi
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900110}
111
Ian Wienandaee18c72014-02-21 15:35:08 +1100112function _neutron_ovs_base_configure_nova_vif_driver {
Aaron Rosen4540d002013-10-24 13:59:33 -0700113 :
Akihiro MOTOKI3452f8e2013-03-21 14:11:27 +0900114}
115
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900116# Restore xtrace
Dean Troyere3a91602014-03-28 12:40:56 -0500117$OVSB_XTRACE