ONOS-3633 - Implementation of virtual network point to point intent provider.

Change-Id: Ie2c1e5ac278bc0dd6259479c44dd92b9b625e90b
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java
index d176102..81a699b 100755
--- a/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java
@@ -18,8 +18,6 @@
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.onosproject.incubator.net.tunnel.TunnelId;
-import org.onosproject.incubator.net.virtual.DefaultVirtualLink;
 import org.onosproject.incubator.net.virtual.NetworkId;
 import org.onosproject.incubator.net.virtual.TenantId;
 import org.onosproject.incubator.net.virtual.VirtualDevice;
@@ -100,7 +98,7 @@
     @Path("{tenantId}")
     public Response getVirtualNetworkById(@PathParam("tenantId") String tenantId) {
         final TenantId existingTid = TenantWebResource.getExistingTenantId(vnetAdminService,
-                TenantId.tenantId(tenantId));
+                                                                           TenantId.tenantId(tenantId));
         Set<VirtualNetwork> vnets = vnetService.getVirtualNetworks(existingTid);
         return ok(encodeArray(VirtualNetwork.class, "vnets", vnets)).build();
     }
@@ -158,7 +156,7 @@
     @Path("{networkId}/devices")
     public Response getVirtualDevices(@PathParam("networkId") long networkId) {
         NetworkId nid = NetworkId.networkId(networkId);
-        Set<VirtualDevice> vdevs  = vnetService.getVirtualDevices(nid);
+        Set<VirtualDevice> vdevs = vnetService.getVirtualDevices(nid);
         return ok(encodeArray(VirtualDevice.class, "devices", vdevs)).build();
     }
 
@@ -166,7 +164,7 @@
      * Creates a virtual device from the JSON input stream.
      *
      * @param networkId network identifier
-     * @param stream Virtual device JSON stream
+     * @param stream    Virtual device JSON stream
      * @return status of the request - CREATED if the JSON is correct,
      * BAD_REQUEST if the JSON is invalid
      * @onos.rsModel VirtualDevice
@@ -201,13 +199,13 @@
      * Removes the virtual network device from the virtual network.
      *
      * @param networkId network identifier
-     * @param deviceId device identifier
+     * @param deviceId  device identifier
      * @return 200 OK, 404 not found
      */
     @DELETE
     @Path("{networkId}/devices/{deviceId}")
     public Response removeVirtualDevice(@PathParam("networkId") long networkId,
-            @PathParam("deviceId") String deviceId) {
+                                        @PathParam("deviceId") String deviceId) {
         NetworkId nid = NetworkId.networkId(networkId);
         DeviceId did = DeviceId.deviceId(deviceId);
         vnetAdminService.removeVirtualDevice(nid, did);
@@ -220,25 +218,25 @@
      * Returns all virtual network ports in a virtual device in a virtual network.
      *
      * @param networkId network identifier
-     * @param deviceId virtual device identifier
+     * @param deviceId  virtual device identifier
      * @return 200 OK
      */
     @GET
     @Produces(MediaType.APPLICATION_JSON)
     @Path("{networkId}/devices/{deviceId}/ports")
     public Response getVirtualPorts(@PathParam("networkId") long networkId,
-            @PathParam("deviceId") String deviceId) {
+                                    @PathParam("deviceId") String deviceId) {
         NetworkId nid = NetworkId.networkId(networkId);
-        Iterable<VirtualPort> vports  = vnetService.getVirtualPorts(nid, DeviceId.deviceId(deviceId));
+        Iterable<VirtualPort> vports = vnetService.getVirtualPorts(nid, DeviceId.deviceId(deviceId));
         return ok(encodeArray(VirtualPort.class, "ports", vports)).build();
     }
 
     /**
      * Creates a virtual network port in a virtual device in a virtual network.
      *
-     * @param networkId network identifier
+     * @param networkId    network identifier
      * @param virtDeviceId virtual device identifier
-     * @param stream Virtual device JSON stream
+     * @param stream       Virtual device JSON stream
      * @return status of the request - CREATED if the JSON is correct,
      * BAD_REQUEST if the JSON is invalid
      * @onos.rsModel VirtualPort
@@ -248,8 +246,8 @@
     @Produces(MediaType.APPLICATION_JSON)
     @Path("{networkId}/devices/{deviceId}/ports")
     public Response createVirtualPort(@PathParam("networkId") long networkId,
-            @PathParam("deviceId") String virtDeviceId,
-            InputStream stream) {
+                                      @PathParam("deviceId") String virtDeviceId,
+                                      InputStream stream) {
         try {
             ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
 //            final VirtualPort vportReq = codec(VirtualPort.class).decode(jsonTree, this);
@@ -268,11 +266,11 @@
             DeviceId vdevId = DeviceId.deviceId(virtDeviceId);
             DefaultAnnotations annotations = DefaultAnnotations.builder().build();
             Device physDevice = new DefaultDevice(null, DeviceId.deviceId(specifiedPhysDeviceId.asText()),
-                    null, null, null, null, null, null, annotations);
+                                                  null, null, null, null, null, null, annotations);
             Port realizedBy = new DefaultPort(physDevice,
-                    PortNumber.portNumber(specifiedPhysPortNum.asText()), true);
+                                              PortNumber.portNumber(specifiedPhysPortNum.asText()), true);
             VirtualPort vport = vnetAdminService.createVirtualPort(nid, vdevId,
-                    PortNumber.portNumber(specifiedPortNum.asText()), realizedBy);
+                                    PortNumber.portNumber(specifiedPortNum.asText()), realizedBy);
             UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
                     .path("vnets").path(specifiedNetworkId.asText())
                     .path("devices").path(specifiedDeviceId.asText())
@@ -289,18 +287,18 @@
      * Removes the virtual network port from the virtual device in a virtual network.
      *
      * @param networkId network identifier
-     * @param deviceId virtual device identifier
-     * @param portNum virtual port number
+     * @param deviceId  virtual device identifier
+     * @param portNum   virtual port number
      * @return 200 OK, 404 not found
      */
     @DELETE
     @Path("{networkId}/devices/{deviceId}/ports/{portNum}")
     public Response removeVirtualPort(@PathParam("networkId") long networkId,
-            @PathParam("deviceId") String deviceId,
-            @PathParam("portNum") long portNum) {
+                                      @PathParam("deviceId") String deviceId,
+                                      @PathParam("portNum") long portNum) {
         NetworkId nid = NetworkId.networkId(networkId);
         vnetAdminService.removeVirtualPort(nid, DeviceId.deviceId(deviceId),
-                PortNumber.portNumber(portNum));
+                                           PortNumber.portNumber(portNum));
         return Response.ok().build();
     }
 
@@ -317,15 +315,15 @@
     @Path("{networkId}/links")
     public Response getVirtualLinks(@PathParam("networkId") long networkId) {
         NetworkId nid = NetworkId.networkId(networkId);
-        Set<VirtualLink> vlinks  = vnetService.getVirtualLinks(nid);
+        Set<VirtualLink> vlinks = vnetService.getVirtualLinks(nid);
         return ok(encodeArray(VirtualLink.class, "links", vlinks)).build();
     }
 
-     /**
+    /**
      * Creates a virtual network link from the JSON input stream.
      *
      * @param networkId network identifier
-     * @param stream Virtual device JSON stream
+     * @param stream    Virtual device JSON stream
      * @return status of the request - CREATED if the JSON is correct,
      * BAD_REQUEST if the JSON is invalid
      * @onos.rsModel VirtualLink
@@ -343,12 +341,8 @@
                 throw new IllegalArgumentException(INVALID_FIELD + "networkId");
             }
             final VirtualLink vlinkReq = codec(VirtualLink.class).decode(jsonTree, this);
-            TunnelId tunnelId = TunnelId.valueOf(0);
-            if (vlinkReq instanceof DefaultVirtualLink) {
-                tunnelId = ((DefaultVirtualLink) vlinkReq).tunnelId();
-            }
             vnetAdminService.createVirtualLink(vlinkReq.networkId(),
-                    vlinkReq.src(), vlinkReq.dst(), tunnelId);
+                                               vlinkReq.src(), vlinkReq.dst());
             UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
                     .path("vnets").path(specifiedNetworkId.asText())
                     .path("links");
@@ -364,7 +358,7 @@
      * Removes the virtual network link from the JSON input stream.
      *
      * @param networkId network identifier
-     * @param stream deviceIds JSON stream
+     * @param stream    deviceIds JSON stream
      * @return 200 OK, 404 not found
      * @onos.rsModel VirtualLink
      */
@@ -372,7 +366,7 @@
     @Path("{networkId}/links")
     @Consumes(MediaType.APPLICATION_JSON)
     public Response removeVirtualLink(@PathParam("networkId") long networkId,
-                                        InputStream stream) {
+                                      InputStream stream) {
         try {
             ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
             JsonNode specifiedNetworkId = jsonTree.get("networkId");
@@ -382,7 +376,7 @@
             }
             final VirtualLink vlinkReq = codec(VirtualLink.class).decode(jsonTree, this);
             vnetAdminService.removeVirtualLink(vlinkReq.networkId(),
-                    vlinkReq.src(), vlinkReq.dst());
+                                               vlinkReq.src(), vlinkReq.dst());
         } catch (IOException e) {
             throw new IllegalArgumentException(e);
         }
@@ -393,7 +387,7 @@
     /**
      * Get the tenant identifier from the JSON stream.
      *
-     * @param stream TenantId JSON stream
+     * @param stream        TenantId JSON stream
      * @param jsonFieldName field name
      * @return JsonNode
      * @throws IOException if unable to parse the request
diff --git a/web/api/src/main/resources/definitions/VirtualLink.json b/web/api/src/main/resources/definitions/VirtualLink.json
index 2bc7be7..6f79e49 100644
--- a/web/api/src/main/resources/definitions/VirtualLink.json
+++ b/web/api/src/main/resources/definitions/VirtualLink.json
@@ -56,10 +56,6 @@
     "state": {
       "type": "string",
       "example": "ACTIVE"
-    },
-    "tunnelId": {
-      "type": "int64",
-      "example": "Tunnel identifier"
     }
   }
 }
diff --git a/web/api/src/test/java/org/onosproject/rest/resources/VirtualNetworkWebResourceTest.java b/web/api/src/test/java/org/onosproject/rest/resources/VirtualNetworkWebResourceTest.java
index 63c6698..a41f65a 100644
--- a/web/api/src/test/java/org/onosproject/rest/resources/VirtualNetworkWebResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/resources/VirtualNetworkWebResourceTest.java
@@ -32,7 +32,6 @@
 import org.onlab.rest.BaseResource;
 import org.onosproject.codec.CodecService;
 import org.onosproject.codec.impl.CodecManager;
-import org.onosproject.incubator.net.tunnel.TunnelId;
 import org.onosproject.incubator.net.virtual.DefaultVirtualDevice;
 import org.onosproject.incubator.net.virtual.DefaultVirtualLink;
 import org.onosproject.incubator.net.virtual.DefaultVirtualNetwork;
@@ -104,7 +103,6 @@
     private static final String PORT_NUM = "portNum";
     private static final String PHYS_DEVICE_ID = "physDeviceId";
     private static final String PHYS_PORT_NUM = "physPortNum";
-    private static final String TUNNEL_ID = "tunnelId";
 
     private final TenantId tenantId1 = TenantId.tenantId("TenantId1");
     private final TenantId tenantId2 = TenantId.tenantId("TenantId2");
@@ -137,18 +135,26 @@
     Port port2 = new DefaultPort(dev2, portNumber(2), true);
 
     private final VirtualPort vport22 = new DefaultVirtualPort(networkId3,
-                                                              dev22, portNumber(22), port1);
+                                                               dev22, portNumber(22), port1);
     private final VirtualPort vport23 = new DefaultVirtualPort(networkId3,
-                                                              dev22, portNumber(23), port2);
+                                                               dev22, portNumber(23), port2);
 
     private final ConnectPoint cp11 = NetTestTools.connectPoint(devId1.toString(), 21);
     private final ConnectPoint cp21 = NetTestTools.connectPoint(devId2.toString(), 22);
     private final ConnectPoint cp12 = NetTestTools.connectPoint(devId1.toString(), 2);
     private final ConnectPoint cp22 = NetTestTools.connectPoint(devId2.toString(), 22);
 
-    private final TunnelId tunnelId = TunnelId.valueOf(31);
-    private final VirtualLink vlink1 = new DefaultVirtualLink(networkId3, cp22, cp11, tunnelId);
-    private final VirtualLink vlink2 = new DefaultVirtualLink(networkId3, cp12, cp21, tunnelId);
+    private final VirtualLink vlink1 = DefaultVirtualLink.builder()
+            .networkId(networkId3)
+            .src(cp22)
+            .dst(cp11)
+            .build();
+
+    private final VirtualLink vlink2 = DefaultVirtualLink.builder()
+            .networkId(networkId3)
+            .src(cp12)
+            .dst(cp21)
+            .build();
 
     /**
      * Sets up the global values for all the tests.
@@ -217,14 +223,14 @@
     /**
      * Factory to allocate a virtual network entity matcher.
      *
-     * @param obj virtual network object we are looking for
+     * @param obj            virtual network object we are looking for
      * @param jsonFieldNames JSON field names to check against
-     * @param getValue function to retrieve value from virtual network object
+     * @param getValue       function to retrieve value from virtual network object
      * @param <T>
      * @return JsonObjectMatcher
      */
     private static <T> JsonObjectMatcher matchesVnetEntity(T obj, List<String> jsonFieldNames,
-                                                    BiFunction<T, String, String> getValue) {
+                                                           BiFunction<T, String, String> getValue) {
         return new JsonObjectMatcher(obj, jsonFieldNames, getValue);
     }
 
@@ -710,7 +716,7 @@
         final JsonArray vnetJsonArray = result.get("ports").asArray();
         assertThat(vnetJsonArray, notNullValue());
         assertEquals("Virtual ports array is not the correct size.",
-                vportSet.size(), vnetJsonArray.size());
+                     vportSet.size(), vnetJsonArray.size());
 
         vportSet.forEach(vport -> assertThat(vnetJsonArray, hasVport(vport)));
 
@@ -759,7 +765,7 @@
         DeviceId deviceId = devId22;
         DefaultAnnotations annotations = DefaultAnnotations.builder().build();
         Device physDevice = new DefaultDevice(null, DeviceId.deviceId("dev1"),
-                null, null, null, null, null, null, annotations);
+                                              null, null, null, null, null, null, annotations);
         Port port1 = new DefaultPort(physDevice, portNumber(1), true);
         expect(mockVnetAdminService.createVirtualPort(networkId, deviceId, portNumber(22), port1))
                 .andReturn(vport22);
@@ -817,7 +823,7 @@
         WebTarget wt = target()
                 .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
         String reqLocation = "vnets/" + networkId.toString()
-            + "/devices/" + deviceId.toString() + "/ports/" + portNum.toLong();
+                + "/devices/" + deviceId.toString() + "/ports/" + portNum.toLong();
         Response response = wt.path(reqLocation)
                 .request(MediaType.APPLICATION_JSON_TYPE)
                 .delete();
@@ -902,15 +908,6 @@
                 reason = ID + " was " + jsonNetworkId;
                 return false;
             }
-            // check TunnelId
-            String jsonTunnelId = jsonLink.get(TUNNEL_ID).asString();
-            if (jsonTunnelId != null && vlink instanceof DefaultVirtualLink) {
-                String tunnelId = ((DefaultVirtualLink) vlink).tunnelId().toString();
-                if (!jsonTunnelId.equals(tunnelId)) {
-                    reason = TUNNEL_ID + " was " + jsonTunnelId;
-                    return false;
-                }
-            }
             return true;
         }
 
@@ -980,7 +977,7 @@
     @Test
     public void testPostVirtualLink() {
         NetworkId networkId = networkId3;
-        expect(mockVnetAdminService.createVirtualLink(networkId, cp22, cp11, tunnelId))
+        expect(mockVnetAdminService.createVirtualLink(networkId, cp22, cp11))
                 .andReturn(vlink1);
         replay(mockVnetAdminService);
 
diff --git a/web/api/src/test/resources/org/onosproject/rest/resources/post-virtual-link.json b/web/api/src/test/resources/org/onosproject/rest/resources/post-virtual-link.json
index a7c5d26..8f04673 100644
--- a/web/api/src/test/resources/org/onosproject/rest/resources/post-virtual-link.json
+++ b/web/api/src/test/resources/org/onosproject/rest/resources/post-virtual-link.json
@@ -9,6 +9,5 @@
     "port": "21" 
   },
   "type": "VIRTUAL",
-  "state": "ACTIVE",
-  "tunnelId": "31"
+  "state": "ACTIVE"
 }