CORD-223 Added ovsdb driver methods for bridge and tunnel interface creation

Change-Id: Ida80a4ef5b66cebb83b2629054c68a3546526d23
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java b/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java
index 7f157e9..e3d6993 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java
@@ -36,6 +36,17 @@
     void addBridge(BridgeName bridgeName);
 
     /**
+     * Adds a bridge with given bridge name and dpid, and sets the controller
+     * of the bridge with given controllers.
+     *
+     * @param bridgeName bridge name
+     * @param dpid dpid
+     * @param controllers list of controller
+     * @return true if succeeds, fail otherwise
+     */
+    boolean addBridge(BridgeName bridgeName, String dpid, List<ControllerInfo> controllers);
+
+    /**
      * Remove a bridge.
      *
      * @param bridgeName bridge name
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/TunnelConfig.java b/core/api/src/main/java/org/onosproject/net/behaviour/TunnelConfig.java
index 7e79a57..e3b4c19 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/TunnelConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/TunnelConfig.java
@@ -32,6 +32,15 @@
     void createTunnel(TunnelDescription tunnel);
 
     /**
+     * Creates a tunnel interface on a given bridge of this device.
+     *
+     * @param bridgeName bridge name
+     * @param tunnel tunnel description
+     * @return true if succeeds, false otherwise
+     */
+    boolean createTunnelInterface(BridgeName bridgeName, TunnelDescription tunnel);
+
+    /**
      * Removes a tunnel on this device.
      *
      * @param tunnel tunnel descriptor
diff --git a/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbBridgeConfig.java b/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbBridgeConfig.java
index 899f18d..1fdec74 100644
--- a/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbBridgeConfig.java
+++ b/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbBridgeConfig.java
@@ -22,11 +22,13 @@
 import java.util.stream.Collectors;
 
 import org.onlab.packet.IpAddress;
+import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.behaviour.BridgeConfig;
 import org.onosproject.net.behaviour.BridgeDescription;
 import org.onosproject.net.behaviour.BridgeName;
+import org.onosproject.net.behaviour.ControllerInfo;
 import org.onosproject.net.behaviour.DefaultBridgeDescription;
 import org.onosproject.net.device.DefaultPortDescription;
 import org.onosproject.net.device.PortDescription;
@@ -52,6 +54,13 @@
     }
 
     @Override
+    public boolean addBridge(BridgeName bridgeName, String dpid, List<ControllerInfo> controllers) {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        return clientService.createBridge(bridgeName.name(), dpid, controllers);
+    }
+
+    @Override
     public void deleteBridge(BridgeName bridgeName) {
         DriverHandler handler = handler();
         OvsdbClientService clientService = getOvsdbClientService(handler);
@@ -108,9 +117,10 @@
         return ports.stream()
                 .map(x -> new DefaultPortDescription(
                                 PortNumber.portNumber(x.portNumber().value()),
-                                true
-                        )
-                )
+                                true,
+                                DefaultAnnotations.builder()
+                                        .set("portName", x.portName().value())
+                                        .build()))
                 .collect(Collectors.toSet());
     }
 
diff --git a/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbTunnelConfig.java b/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbTunnelConfig.java
index 0b3a99a2..6c0f111 100644
--- a/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbTunnelConfig.java
+++ b/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbTunnelConfig.java
@@ -16,11 +16,14 @@
 package org.onosproject.driver.ovsdb;
 
 import java.util.Collection;
+import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
 
 import org.onlab.packet.IpAddress;
+import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.BridgeName;
 import org.onosproject.net.behaviour.DefaultTunnelDescription;
 import org.onosproject.net.behaviour.IpTunnelEndPoint;
 import org.onosproject.net.behaviour.TunnelConfig;
@@ -40,6 +43,8 @@
         implements TunnelConfig {
 
     private static final String DEFAULT_ADDRESS = "0.0.0.0";
+    private static final String OPTION_LOCAL_IP = "local_ip";
+    private static final String OPTION_REMOTE_IP = "remote_ip";
 
     @Override
     public void createTunnel(TunnelDescription tunnel) {
@@ -60,6 +65,22 @@
     }
 
     @Override
+    public boolean createTunnelInterface(BridgeName bridgeName, TunnelDescription tunnel) {
+        Map<String, String> options = ((DefaultAnnotations) tunnel.annotations()).asMap();
+        if (tunnel.src() != null) {
+            options.put(OPTION_LOCAL_IP, tunnel.src().toString());
+        }
+        if (tunnel.dst() != null) {
+            options.put(OPTION_REMOTE_IP, tunnel.dst().toString());
+        }
+
+        DriverHandler handler = handler();
+        OvsdbClientService ovsdbClient = getOvsdbNode(handler);
+        return ovsdbClient.createTunnel(bridgeName.name(), tunnel.tunnelName().toString(),
+                                        tunnel.type().toString().toLowerCase(), options);
+    }
+
+    @Override
     public void removeTunnel(TunnelDescription tunnel) {
         DriverHandler handler = handler();
         OvsdbClientService ovsdbNode = getOvsdbNode(handler);