Refactored tunnel and interface config behavior

- Added tunnel interface configuratoin to interfaceConfig and
  deprecated tunnelConfig
- OVSDB client service provides interface create/remove APIs instead
  of tunnel interface create/remove, and this APIs can be used to
  create/remove various types of interfaces like tunnel, patch, tap and so on
- Use tunnel description when create tunnel interface so that we can extend
  more config options later
- Some cleaup OVSDB client

Change-Id: I4653595504a27b18384a92ebe4b31ce9d99237cd
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java
index bf91497..5a0676b 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java
@@ -16,16 +16,12 @@
 package org.onosproject.ovsdb.controller;
 
 import com.google.common.util.concurrent.ListenableFuture;
-
 import org.onlab.packet.IpAddress;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.behaviour.ControllerInfo;
 import org.onosproject.ovsdb.rfc.jsonrpc.OvsdbRpc;
-import org.onosproject.ovsdb.rfc.message.OperationResult;
 import org.onosproject.ovsdb.rfc.message.TableUpdates;
 import org.onosproject.ovsdb.rfc.notation.Row;
-import org.onosproject.ovsdb.rfc.notation.Uuid;
-import org.onosproject.ovsdb.rfc.operations.Operation;
 import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
 
 import java.util.List;
@@ -46,28 +42,43 @@
     /**
      * Creates a tunnel port with given options.
      *
+     * @deprecated version 1.7.0 - Hummingbird
      * @param bridgeName bridge name
      * @param portName port name
      * @param tunnelType tunnel type
      * @param options tunnel options
      * @return true if tunnel creation is successful, false otherwise
      */
-    boolean createTunnel(String bridgeName, String portName, String tunnelType, Map<String, String> options);
+    @Deprecated
+    boolean createTunnel(String bridgeName, String portName, String tunnelType,
+                         Map<String, String> options);
 
     /**
      * Drops the configuration for tunnel.
      *
+     * @deprecated version 1.7.0 - Hummingbird
      * @param srcIp source IP address
      * @param dstIp destination IP address
      */
+    @Deprecated
     void dropTunnel(IpAddress srcIp, IpAddress dstIp);
 
     /**
-     * Gets tunnels of node.
+     * Creates an interface with a given OVSDB interface description.
      *
-     * @return set of tunnels; empty if no tunnel is find
+     * @param bridgeName bridge name
+     * @param ovsdbIface ovsdb interface description
+     * @return true if interface creation is successful, false otherwise
      */
-    Set<OvsdbTunnel> getTunnels();
+    boolean createInterface(String bridgeName, OvsdbInterface ovsdbIface);
+
+    /**
+     * Removes an interface with the supplied interface name.
+     *
+     * @param ifaceName interface name
+     * @return true if interface creation is successful, false otherwise
+     */
+    boolean dropInterface(String ifaceName);
 
     /**
      * Creates a bridge.
@@ -142,17 +153,6 @@
     ControllerInfo localController();
 
     /**
-     * Sets the Controllers for the specified bridge.
-     * <p>
-     * This method will replace the existing controller list with the new controller
-     * list.
-     *
-     * @param bridgeUuid bridge uuid
-     * @param controllers list of controllers
-     */
-    void setControllersWithUuid(Uuid bridgeUuid, List<ControllerInfo> controllers);
-
-    /**
      * Sets the Controllers for the specified device.
      * <p>
      * This method will replace the existing controller list with the new controller
@@ -211,32 +211,6 @@
     String getPortUuid(String portName, String bridgeUuid);
 
     /**
-     * Gets the Interface uuid.
-     *
-     * @param portUuid port uuid
-     * @param portName port name
-     * @return interface uuid, empty if no uuid is find
-     */
-    String getInterfaceUuid(String portUuid, String portName);
-
-    /**
-     * Gets the Controller uuid.
-     *
-     * @param controllerName   controller name
-     * @param controllerTarget controller target
-     * @return controller uuid, empty if no uuid is find
-     */
-    String getControllerUuid(String controllerName, String controllerTarget);
-
-    /**
-     * Gets the OVS uuid.
-     *
-     * @param dbName database name
-     * @return ovs uuid, empty if no uuid is find
-     */
-    String getOvsUuid(String dbName);
-
-    /**
      * Gets the OVSDB database schema.
      *
      * @param dbName database name
@@ -254,16 +228,6 @@
     ListenableFuture<TableUpdates> monitorTables(String dbName, String id);
 
     /**
-     * Gets the OVSDB config operation result.
-     *
-     * @param dbName     database name
-     * @param operations the list of operations
-     * @return operation results
-     */
-    ListenableFuture<List<OperationResult>> transactConfig(String dbName,
-                                                           List<Operation> operations);
-
-    /**
      * Gets the OVSDB database schema from local.
      *
      * @param dbName database name
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
index 5bca1f9..bf1e513 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
@@ -45,6 +45,10 @@
     public static final String DATAPATH_ID = "datapath-id";
     public static final String DISABLE_INBAND = "disable-in-band";
 
+    /** Port table. */
+    public static final String PORT = "Port";
+    public static final String INTERFACES = "interfaces";
+
     /** Interface table. */
     public static final String INTERFACE = "Interface";
     // type
@@ -52,13 +56,14 @@
     // virtual machine identifiers
     public static final String EXTERNAL_ID_INTERFACE_ID = "iface-id";
     public static final String EXTERNAL_ID_VM_MAC = "attached-mac";
+    // tunnel interface options
+    public static final String TUNNEL_LOCAL_IP = "local_ip";
+    public static final String TUNNEL_REMOTE_IP = "remote_ip";
+    public static final String TUNNEL_KEY = "key";
 
     /** Controller table. */
     public static final String CONTROLLER = "Controller";
 
-    /** Port table. */
-    public static final String PORT = "Port";
-
     /** Ovsdb bridge name. */
     // TODO remove this particular bridge name from OVSDB provider
     public static final String INTEGRATION_BRIDGE = "br-int";
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbInterface.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbInterface.java
new file mode 100644
index 0000000..e047833
--- /dev/null
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbInterface.java
@@ -0,0 +1,232 @@
+/*
+ * Copyright 2015-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ovsdb.controller;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.*;
+
+import java.util.Map;
+import java.util.Objects;
+
+import com.google.common.collect.Maps;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.behaviour.TunnelDescription;
+
+/**
+ * The class representing an OVSDB interface.
+ * This class is immutable.
+ */
+public final class OvsdbInterface {
+
+    public enum Type {
+        /**
+         * An ordinary network device, e.g. eth0 on Linux.
+         */
+        SYSTEM,
+        /**
+         * A simulated network device that sends and receives traffic.
+         */
+        INTERNAL,
+        /**
+         * A TUN/TAP device managed by Open vSwitch.
+         */
+        TAP,
+        /**
+         * An Ethernet over RFC 2890 Generic Routing Encapsulation over IPv4 IPsec tunnel.
+         */
+        GRE,
+        /**
+         * An Ethernet tunnel over the experimental, UDP-based VXLAN protocol.
+         */
+        VXLAN,
+        /**
+         * A pair of virtual devices that act as a patch cable.
+         */
+        PATCH
+    }
+
+    private final String name;
+    private final Type type;
+
+    /* Adds more configs */
+
+    /* Fields start with "options:" prefix defined in the OVSDB */
+    private final Map<String, String> options;
+
+    private OvsdbInterface(String name, Type type, Map<String, String> options) {
+        this.name = name;
+        this.type = type;
+        this.options = Maps.newHashMap(options);
+    }
+
+    /**
+     * Returns name of the interface.
+     *
+     * @return interface name
+     */
+    public String name() {
+        return name;
+    }
+
+    /**
+     * Returns type of the interface.
+     *
+     * @return interface type
+     */
+    public Type type() {
+        return type;
+    }
+
+    /**
+     * Returns type of the interface with lowercase string.
+     *
+     * @return interface type string
+     */
+    public String typeToString() {
+        return type.name().toLowerCase();
+    }
+
+    /**
+     * Returns optional configs of the interface.
+     *
+     * @return interface options
+     */
+    public Map<String, String> options() {
+        return options;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(name);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof OvsdbInterface) {
+            final OvsdbInterface otherOvsdbInterface = (OvsdbInterface) obj;
+            return Objects.equals(this.name, otherOvsdbInterface.name);
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("name", name)
+                .add("type", type)
+                .add("options", options)
+                .toString();
+    }
+
+    /**
+     * Returns new OVSDB interface builder.
+     *
+     * @return ovsdb interface builder
+     */
+    public static OvsdbInterface.Builder builder() {
+        return new Builder();
+    }
+
+    /**
+     * Returns new OVSDB interface builder with tunnel interface description.
+     *
+     * @param tunnelDesc tunnel interface description
+     * @return ovsdb interface builder
+     */
+    public static OvsdbInterface.Builder builder(TunnelDescription tunnelDesc) {
+        return new Builder(tunnelDesc);
+    }
+
+    /**
+     * Builder of OVSDB interface entities.
+     */
+    public static final class Builder {
+        private String name;
+        private Type type;
+        private Map<String, String> options = Maps.newHashMap();
+
+        private Builder() {
+        }
+
+        /**
+         * Constructs a builder with a given tunnel interface description.
+         *
+         * @param tunnelDesc tunnel interface description
+         */
+        private Builder(TunnelDescription tunnelDesc) {
+            this.name = tunnelDesc.ifaceName();
+            this.type = Type.valueOf(tunnelDesc.type().name());
+
+            if (tunnelDesc.local().isPresent()) {
+                options.put(TUNNEL_LOCAL_IP, tunnelDesc.local().get().strValue());
+            }
+            if (tunnelDesc.remote().isPresent()) {
+                options.put(TUNNEL_REMOTE_IP, tunnelDesc.remote().get().strValue());
+            }
+            if (tunnelDesc.key().isPresent()) {
+                options.put(TUNNEL_KEY, tunnelDesc.key().get().strValue());
+            }
+
+            // set other configurations if there are any
+            options.putAll(((DefaultAnnotations) tunnelDesc.annotations()).asMap());
+        }
+
+        /**
+         * Returns new OVSDB interface.
+         *
+         * @return ovsdb interface
+         */
+        public OvsdbInterface build() {
+            return new OvsdbInterface(name, type, options);
+        }
+
+        /**
+         * Returns OVSDB interface builder with a given name.
+         *
+         * @param name name of the interface
+         * @return ovsdb interface builder
+         */
+        public Builder name(String name) {
+            this.name = name;
+            return this;
+        }
+
+        /**
+         * Returns OVSDB interface builder with a given interface type.
+         *
+         * @param type type of the interface
+         * @return ovsdb interface builder
+         */
+        public Builder type(Type type) {
+            this.type = type;
+            return this;
+        }
+
+        /**
+         * Returns OVSDB interface builder with given options.
+         *
+         * @param options map of options
+         * @return ovsdb interface builder
+         */
+        public Builder options(Map<String, String> options) {
+            this.options = Maps.newHashMap(options);
+            return this;
+        }
+    }
+}
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbTunnel.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbTunnel.java
deleted file mode 100644
index fd9987c..0000000
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbTunnel.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2015-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.ovsdb.controller;
-
-import static com.google.common.base.MoreObjects.toStringHelper;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Objects;
-
-import org.onlab.packet.IpAddress;
-
-/**
- * The class representing an ovsdb tunnel.
- * This class is immutable.
- */
-public final class OvsdbTunnel {
-
-    private final IpAddress localIp;
-    private final IpAddress remoteIp;
-
-    public enum Type {
-        VXLAN, GRE
-    }
-
-    private final Type tunnelType;
-    private final OvsdbTunnelName tunnelName;
-
-    /**
-     * Constructor from an IpAddress localIp, IpAddress remoteIp Type tunnelType,
-     * OvsdbTunnelName tunnelName.
-     *
-     * @param localIp the localIp to use
-     * @param remoteIp the remoteIp to use
-     * @param tunnelType the tunnelType to use
-     * @param tunnelName the tunnelName to use
-     */
-    public OvsdbTunnel(IpAddress localIp, IpAddress remoteIp, Type tunnelType,
-                       OvsdbTunnelName tunnelName) {
-        checkNotNull(localIp, "portName is not null");
-        checkNotNull(remoteIp, "portName is not null");
-        checkNotNull(tunnelName, "portName is not null");
-        this.localIp = localIp;
-        this.remoteIp = remoteIp;
-        this.tunnelType = tunnelType;
-        this.tunnelName = tunnelName;
-    }
-
-    /**
-     * Gets the local IP of tunnel.
-     *
-     * @return the local IP of tunnel
-     */
-    public IpAddress localIp() {
-        return localIp;
-    }
-
-    /**
-     * Gets the remote IP of tunnel.
-     *
-     * @return the remote IP of tunnel
-     */
-    public IpAddress remoteIp() {
-        return remoteIp;
-    }
-
-    /**
-     * Gets the tunnel type of tunnel.
-     *
-     * @return the tunnel type of tunnel
-     */
-    public Type tunnelType() {
-        return tunnelType;
-    }
-
-    /**
-     * Gets the tunnel name of tunnel.
-     *
-     * @return the tunnel name of tunnel
-     */
-    public OvsdbTunnelName tunnelName() {
-        return tunnelName;
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(localIp, remoteIp, tunnelType, tunnelName);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof OvsdbTunnel) {
-            final OvsdbTunnel otherOvsdbTunnel = (OvsdbTunnel) obj;
-            return Objects.equals(this.localIp, otherOvsdbTunnel.localIp)
-                    && Objects.equals(this.remoteIp, otherOvsdbTunnel.remoteIp)
-                    && Objects.equals(this.tunnelType,
-                                      otherOvsdbTunnel.tunnelType)
-                    && Objects.equals(this.tunnelName,
-                                      otherOvsdbTunnel.tunnelName);
-        }
-        return false;
-    }
-
-    @Override
-    public String toString() {
-        return toStringHelper(this).add("localIp", localIp.toString())
-                .add("remoteIp", remoteIp.toString())
-                .add("tunnelType", tunnelType).add("tunnelName", tunnelName)
-                .toString();
-    }
-}
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbTunnelName.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbTunnelName.java
deleted file mode 100644
index 2494ddc..0000000
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbTunnelName.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2015-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.ovsdb.controller;
-
-import static com.google.common.base.MoreObjects.toStringHelper;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Objects;
-
-/**
- * The class representing a tunnel name.
- * This class is immutable.
- */
-public final class OvsdbTunnelName {
-    private final String value;
-
-    /**
-     * Constructor from a String.
-     *
-     * @param value the tunnel name to use
-     */
-    public OvsdbTunnelName(String value) {
-        checkNotNull(value, "value is not null");
-        this.value = value;
-    }
-
-    /**
-     * Gets the value of tunnel name.
-     *
-     * @return the value of tunnel name
-     */
-    public String value() {
-        return value;
-    }
-
-    @Override
-    public int hashCode() {
-        return value.hashCode();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof OvsdbTunnelName) {
-            final OvsdbTunnelName otherOvsdbTunnelName = (OvsdbTunnelName) obj;
-            return Objects.equals(this.value, otherOvsdbTunnelName.value);
-        }
-        return false;
-    }
-
-    @Override
-    public String toString() {
-        return toStringHelper(this).add("value", value).toString();
-    }
-}
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
index cbb94ac..6469f4d 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
@@ -32,6 +32,8 @@
 import org.onosproject.net.behaviour.ControllerInfo;
 import org.onosproject.ovsdb.controller.OvsdbBridge;
 import org.onosproject.ovsdb.controller.OvsdbClientService;
+import org.onosproject.ovsdb.controller.OvsdbInterface;
+import org.onosproject.ovsdb.controller.OvsdbInterface.Type;
 import org.onosproject.ovsdb.controller.OvsdbNodeId;
 import org.onosproject.ovsdb.controller.OvsdbPort;
 import org.onosproject.ovsdb.controller.OvsdbPortName;
@@ -39,7 +41,6 @@
 import org.onosproject.ovsdb.controller.OvsdbRowStore;
 import org.onosproject.ovsdb.controller.OvsdbStore;
 import org.onosproject.ovsdb.controller.OvsdbTableStore;
-import org.onosproject.ovsdb.controller.OvsdbTunnel;
 import org.onosproject.ovsdb.rfc.jsonrpc.Callback;
 import org.onosproject.ovsdb.rfc.message.OperationResult;
 import org.onosproject.ovsdb.rfc.message.TableUpdates;
@@ -72,11 +73,11 @@
 
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutionException;
@@ -102,7 +103,6 @@
     private final Map<String, String> requestMethod = Maps.newHashMap();
     private final Map<String, SettableFuture<? extends Object>> requestResult = Maps.newHashMap();
     private final Map<String, DatabaseSchema> schema = Maps.newHashMap();
-    private final Set<OvsdbTunnel> ovsdbTunnels = new HashSet<OvsdbTunnel>();
 
     /**
      * Creates an OvsdbClient.
@@ -263,38 +263,8 @@
     }
 
     @Override
-    public String getInterfaceUuid(String portUuid, String portName) {
-        DatabaseSchema dbSchema = schema.get(DATABASENAME);
-
-        Row portRow = getRow(DATABASENAME, PORT, portUuid);
-        Port port = (Port) TableGenerator.getTable(dbSchema, portRow, OvsdbTable.PORT);
-
-        if (port != null) {
-            OvsdbSet setInterfaces = (OvsdbSet) port.getInterfacesColumn().data();
-            @SuppressWarnings("unchecked")
-            Set<Uuid> interfaces = setInterfaces.set();
-
-            if (interfaces == null || interfaces.size() == 0) {
-                log.warn("The interface uuid is null");
-                return null;
-            }
-
-            for (Uuid uuid : interfaces) {
-                Row intfRow = getRow(DATABASENAME, INTERFACE, uuid.value());
-                Interface intf = (Interface) TableGenerator
-                        .getTable(dbSchema, intfRow, OvsdbTable.INTERFACE);
-                if (intf != null && portName.equalsIgnoreCase(intf.getName())) {
-                    return uuid.value();
-                }
-            }
-        }
-        return null;
-    }
-
-    @Override
     public String getBridgeUuid(String bridgeName) {
         DatabaseSchema dbSchema = schema.get(DATABASENAME);
-
         OvsdbRowStore rowStore = getRowStore(DATABASENAME, BRIDGE);
         if (rowStore == null) {
             log.debug("The bridge uuid is null");
@@ -317,32 +287,7 @@
         return null;
     }
 
-    @Override
-    public String getControllerUuid(String controllerName, String controllerTarget) {
-        DatabaseSchema dbSchema = schema.get(DATABASENAME);
-        OvsdbRowStore rowStore = getRowStore(DATABASENAME, CONTROLLER);
-        if (rowStore == null) {
-            log.debug("The controller uuid is null");
-            return null;
-        }
-
-        ConcurrentMap<String, Row> controllerTableRows = rowStore.getRowStore();
-        if (controllerTableRows != null) {
-            for (String uuid : controllerTableRows.keySet()) {
-                Controller controller = (Controller) TableGenerator
-                        .getTable(dbSchema, controllerTableRows.get(uuid),
-                                  OvsdbTable.CONTROLLER);
-                String target = (String) controller.getTargetColumn().data();
-                if (target.equalsIgnoreCase(controllerTarget)) {
-                    return uuid;
-                }
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public String getOvsUuid(String dbName) {
+    private String getOvsUuid(String dbName) {
         OvsdbRowStore rowStore = getRowStore(DATABASENAME, DATABASENAME);
         if (rowStore == null) {
             log.debug("The bridge uuid is null");
@@ -485,8 +430,7 @@
         return new ControllerInfo(ipAddress, OFPORT, "tcp");
     }
 
-    @Override
-    public void setControllersWithUuid(Uuid bridgeUuid, List<ControllerInfo> controllers) {
+    private void setControllersWithUuid(Uuid bridgeUuid, List<ControllerInfo> controllers) {
         DatabaseSchema dbSchema = schema.get(DATABASENAME);
         if (dbSchema == null) {
             log.debug("There is no schema");
@@ -555,19 +499,37 @@
             log.warn("Could not find bridge in node", nodeId.getIpAddress());
             return;
         }
-        deleteConfig(BRIDGE, UUID, bridgeUuid, DATABASENAME, "bridges");
+        deleteConfig(BRIDGE, UUID, bridgeUuid, DATABASENAME, BRIDGES);
+    }
+
+    @Deprecated
+    @Override
+    public boolean createTunnel(String bridgeName, String ifaceName, String tunnelType,
+                                Map<String, String> options) {
+        OvsdbInterface ovsdbIface = OvsdbInterface.builder()
+                .name(ifaceName)
+                .type(Type.valueOf(tunnelType))
+                .options(options)
+                .build();
+
+        return createInterface(bridgeName, ovsdbIface);
+    }
+
+    @Deprecated
+    @Override
+    public void dropTunnel(IpAddress srcIp, IpAddress dstIp) {
     }
 
     @Override
-    public boolean createTunnel(String bridgeName, String portName, String tunnelType, Map<String, String> options) {
+    public boolean createInterface(String bridgeName, OvsdbInterface ovsdbIface) {
         String bridgeUuid  = getBridgeUuid(bridgeName);
         if (bridgeUuid == null) {
             log.warn("Couldn't find bridge {} in {}", bridgeName, nodeId.getIpAddress());
             return false;
         }
 
-        if (getPortUuid(portName, bridgeUuid) != null) {
-            log.warn("Port {} already exists", portName);
+        if (getPortUuid(ovsdbIface.name(), bridgeUuid) != null) {
+            log.warn("Interface {} already exists", ovsdbIface.name());
             // remove existing one and re-create?
             return false;
         }
@@ -577,45 +539,57 @@
 
         // insert a new port to the port table
         Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT);
-        port.setName(portName);
-        Insert portInsert = new Insert(dbSchema.getTableSchema("Port"), "Port", port.getRow());
-        portInsert.getRow().put("interfaces", Uuid.uuid("Interface"));
+        port.setName(ovsdbIface.name());
+        Insert portInsert = new Insert(dbSchema.getTableSchema(PORT), PORT, port.getRow());
+        portInsert.getRow().put(INTERFACES, Uuid.uuid(INTERFACE));
         operations.add(portInsert);
 
         // update the bridge table
         Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(bridgeUuid));
-        Mutation mutation = MutationUtil.insert(PORTS, Uuid.uuid("Port"));
-        List<Condition> conditions = new ArrayList<>(Arrays.asList(condition));
-        List<Mutation> mutations = new ArrayList<>(Arrays.asList(mutation));
-        operations.add(new Mutate(dbSchema.getTableSchema("Bridge"), conditions, mutations));
+        Mutation mutation = MutationUtil.insert(PORTS, Uuid.uuid(PORT));
+        List<Condition> conditions = Lists.newArrayList(condition);
+        List<Mutation> mutations = Lists.newArrayList(mutation);
+        operations.add(new Mutate(dbSchema.getTableSchema(BRIDGE), conditions, mutations));
 
         // insert a tunnel interface
         Interface intf = (Interface) TableGenerator.createTable(dbSchema, OvsdbTable.INTERFACE);
-        intf.setName(portName);
-        intf.setType(tunnelType);
-        intf.setOptions(options);
-        Insert intfInsert = new Insert(dbSchema.getTableSchema("Interface"), "Interface", intf.getRow());
+        intf.setName(ovsdbIface.name());
+        intf.setType(ovsdbIface.typeToString());
+        intf.setOptions(ovsdbIface.options());
+        Insert intfInsert = new Insert(dbSchema.getTableSchema(INTERFACE), INTERFACE, intf.getRow());
         operations.add(intfInsert);
 
         transactConfig(DATABASENAME, operations);
+        log.info("Created interface {}", ovsdbIface.name());
         return true;
     }
 
     @Override
-    public void dropTunnel(IpAddress srcIp, IpAddress dstIp) {
-        String bridgeName = INTEGRATION_BRIDGE;
-        String portName = getTunnelName(TYPEVXLAN, dstIp);
-        String bridgeUuid = getBridgeUuid(INTEGRATION_BRIDGE);
-        if (bridgeUuid == null) {
-            log.warn("Could not find bridge {} in {}", bridgeName,
-                     nodeId.getIpAddress());
-            return;
+    public boolean dropInterface(String ifaceName) {
+        OvsdbRowStore rowStore = getRowStore(DATABASENAME, BRIDGE);
+        if (rowStore == null) {
+            log.warn("Failed to get BRIDGE table");
+            return false;
         }
 
-        String portUuid = getPortUuid(portName, bridgeUuid);
-        if (portUuid != null) {
-            log.info("Delete tunnel");
-            deleteConfig(PORT, UUID, portUuid, BRIDGE, PORTS);
+        ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore();
+        if (bridgeTableRows == null) {
+            log.warn("Failed to get BRIDGE table rows");
+            return false;
+        }
+
+        // interface name is unique
+        Optional<String> bridgeId = bridgeTableRows.keySet().stream()
+                .filter(uuid -> getPortUuid(ifaceName, uuid) != null)
+                .findFirst();
+
+        if (bridgeId.isPresent()) {
+            String portId = getPortUuid(ifaceName, bridgeId.get());
+            deleteConfig(PORT, UUID, portId, BRIDGE, PORTS);
+            return true;
+        } else {
+            log.warn("Unable to find the interface with name {}", ifaceName);
+            return false;
         }
     }
 
@@ -727,7 +701,7 @@
         }
         if (childTableName.equalsIgnoreCase(PORT)) {
             log.debug("Handle port insert");
-            Insert intfInsert = handlePortInsertTable(INTERFACE, row);
+            Insert intfInsert = handlePortInsertTable(row);
 
             if (intfInsert != null) {
                 operations.add(intfInsert);
@@ -754,11 +728,10 @@
     /**
      * Handles port insert.
      *
-     * @param tableName ovsdb table interface
      * @param portRow   row of port
      * @return insert, empty if null
      */
-    private Insert handlePortInsertTable(String tableName, Row portRow) {
+    private Insert handlePortInsertTable(Row portRow) {
         DatabaseSchema dbSchema = schema.get(DATABASENAME);
 
         TableSchema portTableSchema = dbSchema.getTableSchema(PORT);
@@ -772,17 +745,6 @@
         return new Insert(intfTableSchema, INTERFACE, inf.getRow());
     }
 
-    /**
-     * Gets tunnel name.
-     *
-     * @param tunnelType tunnel type
-     * @param dstIp      the remote ip address
-     * @return tunnel name
-     */
-    private String getTunnelName(String tunnelType, IpAddress dstIp) {
-        return tunnelType + "-" + dstIp.toString();
-    }
-
     @Override
     public ListenableFuture<DatabaseSchema> getOvsdbSchema(String dbName) {
         if (dbName == null) {
@@ -834,9 +796,8 @@
         return null;
     }
 
-    @Override
-    public ListenableFuture<List<OperationResult>> transactConfig(String dbName,
-                                                                  List<Operation> operations) {
+    private ListenableFuture<List<OperationResult>> transactConfig(String dbName,
+                                                                   List<Operation> operations) {
         if (dbName == null) {
             return null;
         }
@@ -958,11 +919,6 @@
     }
 
     @Override
-    public Set<OvsdbTunnel> getTunnels() {
-        return ovsdbTunnels;
-    }
-
-    @Override
     public Set<OvsdbBridge> getBridges() {
         Set<OvsdbBridge> ovsdbBridges = new HashSet<>();
         OvsdbTableStore tableStore = getTableStore(DATABASENAME);