| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1 | # Neutron NEC OpenFlow plugin | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 2 | # --------------------------- | 
|  | 3 |  | 
|  | 4 | # Save trace setting | 
| Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 5 | NEC_XTRACE=$(set +o | grep xtrace) | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 6 | set +o xtrace | 
|  | 7 |  | 
|  | 8 | # Configuration parameters | 
|  | 9 | OFC_HOST=${OFC_HOST:-127.0.0.1} | 
|  | 10 | OFC_PORT=${OFC_PORT:-8888} | 
|  | 11 |  | 
|  | 12 | OFC_API_HOST=${OFC_API_HOST:-$OFC_HOST} | 
|  | 13 | OFC_API_PORT=${OFC_API_PORT:-$OFC_PORT} | 
|  | 14 | OFC_OFP_HOST=${OFC_OFP_HOST:-$OFC_HOST} | 
|  | 15 | OFC_OFP_PORT=${OFC_OFP_PORT:-6633} | 
|  | 16 | OFC_DRIVER=${OFC_DRIVER:-trema} | 
|  | 17 | OFC_RETRY_MAX=${OFC_RETRY_MAX:-0} | 
|  | 18 | OFC_RETRY_INTERVAL=${OFC_RETRY_INTERVAL:-1} | 
|  | 19 |  | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 20 | # Main logic | 
|  | 21 | # --------------------------- | 
|  | 22 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 23 | source $TOP_DIR/lib/neutron_plugins/ovs_base | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 24 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 25 | function neutron_plugin_create_nova_conf { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 26 | _neutron_ovs_base_configure_nova_vif_driver | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 27 | } | 
|  | 28 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 29 | function neutron_plugin_install_agent_packages { | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 30 | # SKIP_OVS_INSTALL is useful when we want to use Open vSwitch whose | 
|  | 31 | # version is different from the version provided by the distribution. | 
|  | 32 | if [[ "$SKIP_OVS_INSTALL" = "True" ]]; then | 
|  | 33 | echo "You need to install Open vSwitch manually." | 
|  | 34 | return | 
|  | 35 | fi | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 36 | _neutron_ovs_base_install_agent_packages | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 39 | function neutron_plugin_configure_common { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 40 | Q_PLUGIN_CONF_PATH=etc/neutron/plugins/nec | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 41 | Q_PLUGIN_CONF_FILENAME=nec.ini | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 42 | Q_DB_NAME="neutron_nec" | 
|  | 43 | Q_PLUGIN_CLASS="neutron.plugins.nec.nec_plugin.NECPluginV2" | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 44 | } | 
|  | 45 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 46 | function neutron_plugin_configure_debug_command { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 47 | _neutron_ovs_base_configure_debug_command | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 48 | } | 
|  | 49 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 50 | function neutron_plugin_configure_dhcp_agent { | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 51 | : | 
|  | 52 | } | 
|  | 53 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 54 | function neutron_plugin_configure_l3_agent { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 55 | _neutron_ovs_base_configure_l3_agent | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 56 | } | 
|  | 57 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 58 | function _quantum_plugin_setup_bridge { | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 59 | if [[ "$SKIP_OVS_BRIDGE_SETUP" = "True" ]]; then | 
|  | 60 | return | 
|  | 61 | fi | 
|  | 62 | # Set up integration bridge | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 63 | _neutron_ovs_base_setup_bridge $OVS_BRIDGE | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 64 | # Generate datapath ID from HOST_IP | 
| Akihiro MOTOKI | 7a4ae3d | 2013-10-10 00:40:38 +0900 | [diff] [blame] | 65 | local dpid=$(printf "%07d%03d%03d%03d\n" ${HOST_IP//./ }) | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 66 | sudo ovs-vsctl --no-wait set Bridge $OVS_BRIDGE other-config:datapath-id=$dpid | 
|  | 67 | sudo ovs-vsctl --no-wait set-fail-mode $OVS_BRIDGE secure | 
| Akihiro MOTOKI | 7a4ae3d | 2013-10-10 00:40:38 +0900 | [diff] [blame] | 68 | sudo ovs-vsctl --no-wait set-controller $OVS_BRIDGE tcp:$OFC_OFP_HOST:$OFC_OFP_PORT | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 69 | if [ -n "$OVS_INTERFACE" ]; then | 
|  | 70 | sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_BRIDGE $OVS_INTERFACE | 
|  | 71 | fi | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 72 | _neutron_setup_ovs_tunnels $OVS_BRIDGE | 
| Akihiro MOTOKI | 7a4ae3d | 2013-10-10 00:40:38 +0900 | [diff] [blame] | 73 | } | 
|  | 74 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 75 | function neutron_plugin_configure_plugin_agent { | 
| Akihiro MOTOKI | 7a4ae3d | 2013-10-10 00:40:38 +0900 | [diff] [blame] | 76 | _quantum_plugin_setup_bridge | 
|  | 77 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 78 | AGENT_BINARY="$NEUTRON_BIN_DIR/neutron-nec-agent" | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 79 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 80 | _neutron_ovs_base_configure_firewall_driver | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 81 | } | 
|  | 82 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 83 | function neutron_plugin_configure_service { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 84 | iniset $NEUTRON_CONF DEFAULT api_extensions_path neutron/plugins/nec/extensions/ | 
| Gary Kotton | d42634f | 2013-06-24 09:26:55 +0000 | [diff] [blame] | 85 | iniset /$Q_PLUGIN_CONF_FILE ofc host $OFC_API_HOST | 
|  | 86 | iniset /$Q_PLUGIN_CONF_FILE ofc port $OFC_API_PORT | 
|  | 87 | iniset /$Q_PLUGIN_CONF_FILE ofc driver $OFC_DRIVER | 
|  | 88 | iniset /$Q_PLUGIN_CONF_FILE ofc api_retry_max OFC_RETRY_MAX | 
|  | 89 | iniset /$Q_PLUGIN_CONF_FILE ofc api_retry_interval OFC_RETRY_INTERVAL | 
| Jiajun Liu | e6f2ee5 | 2013-05-14 09:48:15 +0000 | [diff] [blame] | 90 |  | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 91 | _neutron_ovs_base_configure_firewall_driver | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 92 | } | 
|  | 93 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 94 | function neutron_plugin_setup_interface_driver { | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 95 | local conf_file=$1 | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 96 | iniset $conf_file DEFAULT interface_driver neutron.agent.linux.interface.OVSInterfaceDriver | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 97 | iniset $conf_file DEFAULT ovs_use_veth True | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | # Utility functions | 
|  | 101 | # --------------------------- | 
|  | 102 |  | 
|  | 103 | # Setup OVS tunnel manually | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 104 | function _neutron_setup_ovs_tunnels { | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 105 | local bridge=$1 | 
|  | 106 | local id=0 | 
|  | 107 | GRE_LOCAL_IP=${GRE_LOCAL_IP:-$HOST_IP} | 
|  | 108 | if [ -n "$GRE_REMOTE_IPS" ]; then | 
| Sean Dague | 16dd8b3 | 2014-02-03 09:10:54 +0900 | [diff] [blame] | 109 | for ip in ${GRE_REMOTE_IPS//:/ }; do | 
| Sean Dague | 3bdb922 | 2013-10-22 08:36:16 -0400 | [diff] [blame] | 110 | if [[ "$ip" == "$GRE_LOCAL_IP" ]]; then | 
|  | 111 | continue | 
|  | 112 | fi | 
|  | 113 | sudo ovs-vsctl --no-wait add-port $bridge gre$id -- \ | 
|  | 114 | set Interface gre$id type=gre options:remote_ip=$ip | 
|  | 115 | id=`expr $id + 1` | 
|  | 116 | done | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 117 | fi | 
|  | 118 | } | 
|  | 119 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 120 | function has_neutron_plugin_security_group { | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 121 | # 0 means True here | 
|  | 122 | return 0 | 
|  | 123 | } | 
|  | 124 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 125 | function neutron_plugin_check_adv_test_requirements { | 
| armando-migliaccio | 7c025fe | 2013-05-08 11:33:07 -0700 | [diff] [blame] | 126 | is_service_enabled q-agt && is_service_enabled q-dhcp && return 0 | 
|  | 127 | } | 
|  | 128 |  | 
| Akihiro MOTOKI | f85fa08 | 2013-01-13 05:01:08 +0900 | [diff] [blame] | 129 | # Restore xtrace | 
| Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 130 | $NEC_XTRACE |