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