| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 1 | # Neutron Modular Layer 2 plugin | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 2 | # ------------------------------ | 
 | 3 |  | 
 | 4 | # Save trace setting | 
| Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 5 | ML2_XTRACE=$(set +o | grep xtrace) | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 6 | set +o xtrace | 
 | 7 |  | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 8 | # Enable this to simply and quickly enable tunneling with ML2. | 
 | 9 | # Select either 'gre', 'vxlan', or '(gre vxlan)' | 
| Attila Fazekas | 8feaf6c | 2014-07-27 20:47:04 +0200 | [diff] [blame] | 10 | Q_ML2_TENANT_NETWORK_TYPE=${Q_ML2_TENANT_NETWORK_TYPE:-"vxlan"} | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 11 | # This has to be set here since the agent will set this in the config file | 
| Kevin Benton | e3cfbf1 | 2014-08-04 11:25:20 -0600 | [diff] [blame^] | 12 | if [[ "$Q_ML2_TENANT_NETWORK_TYPE" == "gre" || "$Q_ML2_TENANT_NETWORK_TYPE" == "vxlan" ]]; then | 
| Kyle Mestery | 061d525 | 2013-09-09 08:52:19 +0000 | [diff] [blame] | 13 |     Q_AGENT_EXTRA_AGENT_OPTS+=(tunnel_types=$Q_ML2_TENANT_NETWORK_TYPE) | 
| Kyle Mestery | bd08550 | 2014-04-30 23:50:29 +0000 | [diff] [blame] | 14 | elif [[ "$ENABLE_TENANT_TUNNELS" == "True" ]]; then | 
| Kyle Mestery | 061d525 | 2013-09-09 08:52:19 +0000 | [diff] [blame] | 15 |     Q_AGENT_EXTRA_AGENT_OPTS+=(tunnel_types=gre) | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 16 | fi | 
 | 17 |  | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 18 | # Default openvswitch L2 agent | 
 | 19 | Q_AGENT=${Q_AGENT:-openvswitch} | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 20 | source $TOP_DIR/lib/neutron_plugins/${Q_AGENT}_agent | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 21 |  | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 22 | # List of MechanismDrivers to load | 
| Kyle Mestery | bc63247 | 2013-09-06 14:59:30 +0000 | [diff] [blame] | 23 | Q_ML2_PLUGIN_MECHANISM_DRIVERS=${Q_ML2_PLUGIN_MECHANISM_DRIVERS:-openvswitch,linuxbridge} | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 24 | # List of Type Drivers to load | 
 | 25 | Q_ML2_PLUGIN_TYPE_DRIVERS=${Q_ML2_PLUGIN_TYPE_DRIVERS:-local,flat,vlan,gre,vxlan} | 
 | 26 | # Default GRE TypeDriver options | 
 | 27 | Q_ML2_PLUGIN_GRE_TYPE_OPTIONS=${Q_ML2_PLUGIN_GRE_TYPE_OPTIONS:-tunnel_id_ranges=$TENANT_TUNNEL_RANGES} | 
 | 28 | # Default VXLAN TypeDriver options | 
 | 29 | Q_ML2_PLUGIN_VXLAN_TYPE_OPTIONS=${Q_ML2_PLUGIN_VXLAN_TYPE_OPTIONS:-vni_ranges=1001:2000} | 
 | 30 | # Default VLAN TypeDriver options | 
 | 31 | Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS=${Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS:-} | 
 | 32 |  | 
| Kyle Mestery | 14ea1a2 | 2013-09-22 03:04:56 +0000 | [diff] [blame] | 33 | # L3 Plugin to load for ML2 | 
 | 34 | ML2_L3_PLUGIN=${ML2_L3_PLUGIN:-neutron.services.l3_router.l3_router_plugin.L3RouterPlugin} | 
 | 35 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 36 | function populate_ml2_config { | 
| Akihiro Motoki | 130c90e | 2013-11-28 16:56:51 +0900 | [diff] [blame] | 37 |     CONF=$1 | 
 | 38 |     SECTION=$2 | 
 | 39 |     OPTS=$3 | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 40 |  | 
| Akihiro Motoki | 130c90e | 2013-11-28 16:56:51 +0900 | [diff] [blame] | 41 |     if [ -z "$OPTS" ]; then | 
 | 42 |         return | 
 | 43 |     fi | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 44 |     for I in "${OPTS[@]}"; do | 
 | 45 |         # Replace the first '=' with ' ' for iniset syntax | 
 | 46 |         iniset $CONF $SECTION ${I/=/ } | 
 | 47 |     done | 
 | 48 | } | 
 | 49 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 50 | function neutron_plugin_configure_common { | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 51 |     Q_PLUGIN_CONF_PATH=etc/neutron/plugins/ml2 | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 52 |     Q_PLUGIN_CONF_FILENAME=ml2_conf.ini | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 53 |     Q_PLUGIN_CLASS="neutron.plugins.ml2.plugin.Ml2Plugin" | 
| Bob Melander | 748fe3d | 2013-01-31 17:12:56 +0100 | [diff] [blame] | 54 |     # The ML2 plugin delegates L3 routing/NAT functionality to | 
 | 55 |     # the L3 service plugin which must therefore be specified. | 
| Isaku Yamahata | 9e136b4 | 2013-12-16 15:52:03 +0900 | [diff] [blame] | 56 |     _neutron_service_plugin_class_add $ML2_L3_PLUGIN | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 57 | } | 
 | 58 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 59 | function neutron_plugin_configure_service { | 
| Attila Fazekas | 8feaf6c | 2014-07-27 20:47:04 +0200 | [diff] [blame] | 60 |     if [[ "$Q_ML2_TENANT_NETWORK_TYPE" != "local" ]]; then | 
| Kyle Mestery | 061d525 | 2013-09-09 08:52:19 +0000 | [diff] [blame] | 61 |         Q_SRV_EXTRA_OPTS+=(tenant_network_types=$Q_ML2_TENANT_NETWORK_TYPE) | 
| Kyle Mestery | bd08550 | 2014-04-30 23:50:29 +0000 | [diff] [blame] | 62 |     elif [[ "$ENABLE_TENANT_TUNNELS" == "True" ]]; then | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 63 |         # This assumes you want a simple configuration, and will overwrite | 
 | 64 |         # Q_SRV_EXTRA_OPTS if set in addition to ENABLE_TENANT_TUNNELS. | 
| Kyle Mestery | 061d525 | 2013-09-09 08:52:19 +0000 | [diff] [blame] | 65 |         Q_SRV_EXTRA_OPTS+=(tenant_network_types=gre) | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 66 |         Q_ML2_PLUGIN_GRE_TYPE_OPTIONS=(tunnel_id_ranges=$TENANT_TUNNEL_RANGES) | 
| Kyle Mestery | bd08550 | 2014-04-30 23:50:29 +0000 | [diff] [blame] | 67 |     elif [[ "$ENABLE_TENANT_VLANS" == "True" ]]; then | 
| Kyle Mestery | 061d525 | 2013-09-09 08:52:19 +0000 | [diff] [blame] | 68 |         Q_SRV_EXTRA_OPTS+=(tenant_network_types=vlan) | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 69 |     else | 
 | 70 |         echo "WARNING - The ml2 plugin is using local tenant networks, with no connectivity between hosts." | 
 | 71 |     fi | 
 | 72 |  | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 73 |     # Allow for overrding VLAN configuration (for example, to configure provider | 
 | 74 |     # VLANs) by first checking if Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS is set. | 
 | 75 |     if [ "$Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS" == "" ]; then | 
| Kyle Mestery | bd08550 | 2014-04-30 23:50:29 +0000 | [diff] [blame] | 76 |         if [[ "$ML2_VLAN_RANGES" == "" ]] && [[ "$PHYSICAL_NETWORK" != "" ]]; then | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 77 |             ML2_VLAN_RANGES=$PHYSICAL_NETWORK | 
 | 78 |             if [[ "$TENANT_VLAN_RANGE" != "" ]]; then | 
 | 79 |                 ML2_VLAN_RANGES=$ML2_VLAN_RANGES:$TENANT_VLAN_RANGE | 
 | 80 |             fi | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 81 |         fi | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 82 |         if [[ "$ML2_VLAN_RANGES" != "" ]]; then | 
 | 83 |             Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS=(network_vlan_ranges=$ML2_VLAN_RANGES) | 
 | 84 |         fi | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 85 |     fi | 
 | 86 |  | 
 | 87 |     # REVISIT(rkukura): Setting firewall_driver here for | 
| Mark McClain | b05c876 | 2013-07-06 23:29:39 -0400 | [diff] [blame] | 88 |     # neutron.agent.securitygroups_rpc.is_firewall_enabled() which is | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 89 |     # used in the server, in case no L2 agent is configured on the | 
 | 90 |     # server's node. If an L2 agent is configured, this will get | 
 | 91 |     # overridden with the correct driver. The ml2 plugin should | 
 | 92 |     # instead use its own config variable to indicate whether security | 
 | 93 |     # groups is enabled, and that will need to be set here instead. | 
 | 94 |     if [[ "$Q_USE_SECGROUP" == "True" ]]; then | 
| Akihiro Motoki | 4074e29 | 2014-02-14 00:54:58 +0900 | [diff] [blame] | 95 |         iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.not.a.real.FirewallDriver | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 96 |     else | 
| Akihiro Motoki | 4074e29 | 2014-02-14 00:54:58 +0900 | [diff] [blame] | 97 |         iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.firewall.NoopFirewallDriver | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 98 |     fi | 
 | 99 |  | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 100 |     # Since we enable the tunnel TypeDrivers, also enable a local_ip | 
| Edgar Magana | 6f335b9 | 2014-07-10 15:42:44 -0700 | [diff] [blame] | 101 |     iniset /$Q_PLUGIN_CONF_FILE ovs local_ip $TUNNEL_ENDPOINT_IP | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 102 |  | 
| Akihiro Motoki | 130c90e | 2013-11-28 16:56:51 +0900 | [diff] [blame] | 103 |     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2 mechanism_drivers=$Q_ML2_PLUGIN_MECHANISM_DRIVERS | 
| Kyle Mestery | 3ea28ec | 2013-08-05 12:24:32 +0000 | [diff] [blame] | 104 |  | 
| Akihiro Motoki | 130c90e | 2013-11-28 16:56:51 +0900 | [diff] [blame] | 105 |     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2 type_drivers=$Q_ML2_PLUGIN_TYPE_DRIVERS | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 106 |  | 
| Akihiro Motoki | 130c90e | 2013-11-28 16:56:51 +0900 | [diff] [blame] | 107 |     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2 $Q_SRV_EXTRA_OPTS | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 108 |  | 
| Akihiro Motoki | 130c90e | 2013-11-28 16:56:51 +0900 | [diff] [blame] | 109 |     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_type_gre $Q_ML2_PLUGIN_GRE_TYPE_OPTIONS | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 110 |  | 
| Akihiro Motoki | 130c90e | 2013-11-28 16:56:51 +0900 | [diff] [blame] | 111 |     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_type_vxlan $Q_ML2_PLUGIN_VXLAN_TYPE_OPTIONS | 
| Kyle Mestery | b772659 | 2013-07-19 14:26:53 +0000 | [diff] [blame] | 112 |  | 
| Akihiro Motoki | 130c90e | 2013-11-28 16:56:51 +0900 | [diff] [blame] | 113 |     populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_type_vlan $Q_ML2_PLUGIN_VLAN_TYPE_OPTIONS | 
| Brian Haley | eea7621 | 2014-06-27 11:45:50 -0400 | [diff] [blame] | 114 |  | 
 | 115 |     if [[ "$Q_DVR_MODE" != "legacy" ]]; then | 
 | 116 |         populate_ml2_config /$Q_PLUGIN_CONF_FILE agent l2_population=True | 
 | 117 |         populate_ml2_config /$Q_PLUGIN_CONF_FILE agent tunnel_types=vxlan | 
 | 118 |         populate_ml2_config /$Q_PLUGIN_CONF_FILE agent enable_distributed_routing=True | 
 | 119 |     fi | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 120 | } | 
 | 121 |  | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 122 | function has_neutron_plugin_security_group { | 
| Bob Kukura | c9b0f1a | 2013-04-23 16:28:24 -0400 | [diff] [blame] | 123 |     return 0 | 
 | 124 | } | 
 | 125 |  | 
 | 126 | # Restore xtrace | 
| Dean Troyer | e3a9160 | 2014-03-28 12:40:56 -0500 | [diff] [blame] | 127 | $ML2_XTRACE |