ofagent: Support physical_interface_mappings

Also, add a knob to create a veth pair instead of a bridge
to provide host connectivity for l3-agent.  (Q_USE_PUBLIC_VETH)

Related: blueprint ofagent-physical-interface-mappings
Change-Id: I4c2538f0fd3fb05bfdb69e7e4c3a8462af42ba10
diff --git a/lib/neutron_plugins/ofagent_agent b/lib/neutron_plugins/ofagent_agent
index a5a58f4..1c04f2f 100644
--- a/lib/neutron_plugins/ofagent_agent
+++ b/lib/neutron_plugins/ofagent_agent
@@ -77,6 +77,10 @@
     if [[ "$OVS_BRIDGE_MAPPINGS" != "" ]]; then
         iniset /$Q_PLUGIN_CONF_FILE ovs bridge_mappings $OVS_BRIDGE_MAPPINGS
     fi
+    if [[ "$OFAGENT_PHYSICAL_INTERFACE_MAPPINGS" != "" ]]; then
+        iniset /$Q_PLUGIN_CONF_FILE agent physical_interface_mappings \
+            $OFAGENT_PHYSICAL_INTERFACE_MAPPINGS
+    fi
     AGENT_BINARY="$NEUTRON_BIN_DIR/neutron-ofagent-agent"
 
     iniset /$Q_PLUGIN_CONF_FILE agent tunnel_types $Q_TUNNEL_TYPES
diff --git a/lib/neutron_plugins/ovs_base b/lib/neutron_plugins/ovs_base
index d913f7c..f0ef194 100644
--- a/lib/neutron_plugins/ovs_base
+++ b/lib/neutron_plugins/ovs_base
@@ -79,11 +79,20 @@
     fi
 
     neutron-ovs-cleanup
-    # --no-wait causes a race condition if $PUBLIC_BRIDGE is not up when ip addr flush is called
-    sudo ovs-vsctl -- --may-exist add-br $PUBLIC_BRIDGE
-    sudo ovs-vsctl br-set-external-id $PUBLIC_BRIDGE bridge-id $PUBLIC_BRIDGE
-    # ensure no IP is configured on the public bridge
-    sudo ip addr flush dev $PUBLIC_BRIDGE
+    if [[ "$Q_USE_PUBLIC_VETH" = "True" ]]; then
+        ip link show $Q_PUBLIC_VETH_INT > /dev/null 2>&1 ||
+        sudo ip link add $Q_PUBLIC_VETH_INT type veth \
+            peer name $Q_PUBLIC_VETH_EX
+        sudo ip link set $Q_PUBLIC_VETH_INT up
+        sudo ip link set $Q_PUBLIC_VETH_EX up
+        sudo ip addr flush dev $Q_PUBLIC_VETH_EX
+    else
+        # --no-wait causes a race condition if $PUBLIC_BRIDGE is not up when ip addr flush is called
+        sudo ovs-vsctl -- --may-exist add-br $PUBLIC_BRIDGE
+        sudo ovs-vsctl br-set-external-id $PUBLIC_BRIDGE bridge-id $PUBLIC_BRIDGE
+        # ensure no IP is configured on the public bridge
+        sudo ip addr flush dev $PUBLIC_BRIDGE
+    fi
 }
 
 function _neutron_ovs_base_configure_nova_vif_driver {