Added patch interface add and remove behavior, and implemented OVSDB driver

Change-Id: Ic7632906fcfe50ec224fabdc15cb902a70150fae
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 bf1e513..6562384 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
@@ -60,6 +60,8 @@
     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";
+    // patch interface options
+    public static final String PATCH_PEER = "peer";
 
     /** Controller table. */
     public static final String CONTROLLER = "Controller";
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
index e047833..1322748 100644
--- 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
@@ -23,6 +23,7 @@
 
 import com.google.common.collect.Maps;
 import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.behaviour.PatchDescription;
 import org.onosproject.net.behaviour.TunnelDescription;
 
 /**
@@ -154,6 +155,16 @@
     }
 
     /**
+     * Returns new OVSDB interface builder with patch interface description.
+     *
+     * @param patchDesc patch interface description
+     * @return ovsdb interface builder
+     */
+    public static OvsdbInterface.Builder builder(PatchDescription patchDesc) {
+        return new Builder(patchDesc);
+    }
+
+    /**
      * Builder of OVSDB interface entities.
      */
     public static final class Builder {
@@ -173,18 +184,34 @@
             this.name = tunnelDesc.ifaceName();
             this.type = Type.valueOf(tunnelDesc.type().name());
 
+            Map<String, String> tunOptions = Maps.newHashMap();
             if (tunnelDesc.local().isPresent()) {
-                options.put(TUNNEL_LOCAL_IP, tunnelDesc.local().get().strValue());
+                tunOptions.put(TUNNEL_LOCAL_IP, tunnelDesc.local().get().strValue());
             }
             if (tunnelDesc.remote().isPresent()) {
-                options.put(TUNNEL_REMOTE_IP, tunnelDesc.remote().get().strValue());
+                tunOptions.put(TUNNEL_REMOTE_IP, tunnelDesc.remote().get().strValue());
             }
             if (tunnelDesc.key().isPresent()) {
-                options.put(TUNNEL_KEY, tunnelDesc.key().get().strValue());
+                tunOptions.put(TUNNEL_KEY, tunnelDesc.key().get().strValue());
             }
 
             // set other configurations if there are any
-            options.putAll(((DefaultAnnotations) tunnelDesc.annotations()).asMap());
+            tunOptions.putAll(((DefaultAnnotations) tunnelDesc.annotations()).asMap());
+            options = tunOptions;
+        }
+
+        /**
+         * Constructs a builder with a given patch interface description.
+         *
+         * @param patchDesc patch interface description
+         */
+        private Builder(PatchDescription patchDesc) {
+            this.name = patchDesc.ifaceName();
+            this.type = Type.PATCH;
+
+            Map<String, String> patchOptions = Maps.newHashMap();
+            patchOptions.put(PATCH_PEER, patchDesc.peer());
+            options = patchOptions;
         }
 
         /**
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 6469f4d..f5b0811 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
@@ -537,21 +537,21 @@
         ArrayList<Operation> operations = Lists.newArrayList();
         DatabaseSchema dbSchema = schema.get(DATABASENAME);
 
-        // insert a new port to the port table
+        // insert a new port with the interface name
         Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT);
         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
+        // update the bridge table with the new port
         Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(bridgeUuid));
         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
+        // insert an interface
         Interface intf = (Interface) TableGenerator.createTable(dbSchema, OvsdbTable.INTERFACE);
         intf.setName(ovsdbIface.name());
         intf.setType(ovsdbIface.typeToString());
@@ -560,7 +560,7 @@
         operations.add(intfInsert);
 
         transactConfig(DATABASENAME, operations);
-        log.info("Created interface {}", ovsdbIface.name());
+        log.info("Created interface {}", ovsdbIface);
         return true;
     }