[ONOS-700][ONOS-1801]refactor tunnel subsystem api.
1.use more abstract and more flexible entity[TunnelPoint] to represent
for source or destination point of tunnel,instead of Label
2.suport for muti-producer
3.use Order entity to record tunnel-order relationship
4.modify Tunnel entity to add more properties.
5.rename Label and LabelId to OpticalTunnelPoint and OpticalLogicId in
order to keep code style consistently,at the same time
OpticalTunnelPoint implements TunnelPoint
6.add junit test

Change-Id: I371afcef5501e468a43758c5982e7a93b443b114
diff --git a/core/api/src/main/java/org/onosproject/net/tunnel/TunnelService.java b/core/api/src/main/java/org/onosproject/net/tunnel/TunnelService.java
index 3b060fc..109d981 100644
--- a/core/api/src/main/java/org/onosproject/net/tunnel/TunnelService.java
+++ b/core/api/src/main/java/org/onosproject/net/tunnel/TunnelService.java
@@ -17,88 +17,166 @@
 
 import java.util.Collection;
 
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.Path;
-import org.onosproject.net.resource.BandwidthResource;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.tunnel.Tunnel.Type;
 
 /**
- * Service for interacting with the tunnel inventory.
+ * Service for interacting with the inventory of tunnels.
  */
 public interface TunnelService {
 
     /**
-     * Invokes the core to create a tunnel based on specified parameters.
+     * Borrows a specific tunnel. Annotations parameter is reserved.If there
+     * is no tunnel in the store, returns a "null" object, and record the tunnel subscription.
+     * Where tunnel is created, ONOS notifies this consumer actively.
      *
-     * @param src sourcePoint
-     * @param dst destinationPoint
-     * @param bw  bandwidth
-     * @param path explicit path or null
+     * @param consumerId a tunnel consumer
+     * @param tunnelId tunnel identify generated by onos
+     * @param annotations Annotations
+     * @return Tunnel subscribed tunnel
      */
-    void requestTunnel(ConnectPoint src, ConnectPoint dst, BandwidthResource bw, Path path);
+    Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId,
+                           Annotations... annotations);
 
     /**
-     * Invokes the core to create a tunnel based on specified parameters with a tunnel type.
+     * Borrows a specific tunnel by tunnelName. Annotations parameter is reserved.If there
+     * is no tunnel in the store, return a "null" object, and record the tunnel subscription.
+     * Where tunnel is created, ONOS notifies this consumer actively.
      *
-     * @param src sourcePoint
-     * @param dst destinationPoint
-     * @param type  tunnelType
-     * @param bw  bandwidth
-     * @param path explicit path or null
+     * @param consumerId a tunnel consumer
+     * @param tunnelName tunnel name
+     * @param annotations Annotations
+     * @return collection of subscribed Tunnels
      */
-    void requestTunnel(ConnectPoint src, ConnectPoint dst, Tunnel.Type type, BandwidthResource bw, Path path);
+    Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelName tunnelName,
+                           Annotations... annotations);
 
     /**
-     * Returns the count of all known tunnels in the dataStore.
+     * Borrows all tunnels between source and destination. Annotations
+     * parameter is reserved.If there is no any tunnel in the store, return a
+     * empty collection,and record the tunnel subscription. Where tunnel is created, ONOS
+     * notifies this consumer actively. Otherwise ONOS core returns all the
+     * tunnels, consumer determined which one to use.
      *
-     * @return number of tunnels
+     * @param consumerId a tunnel consumer
+     * @param src a source point of tunnel.
+     * @param dst a destination point of tunnel
+     * @param annotations Annotations
+     * @return collection of subscribed Tunnels
      */
-    int getTunnelCount();
+    Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src,
+                                       TunnelEndPoint dst, Annotations... annotations);
 
     /**
-     * Returns a collection of all known tunnel based on the type.
+     * Borrows all specified type tunnels between source and destination.
+     * Annotations parameter is reserved.If there is no any tunnel in the store,
+     * return a empty collection, and record the tunnel subscription. Where tunnel is
+     * created, ONOS notifies this consumer actively. Otherwise,ONOS core returns
+     * all available tunnels, consumer determined which one to use.
      *
-     *@param type  tunnelType
-     * @return all tunnels for a specific type
-     */
-    Collection<Tunnel> getTunnels(Tunnel.Type type);
-
-    /**
-     * Returns set of all tunnels from the specified connectpoint.
-     *
-     * @param connectPoint device/portnumber
-     * @param type  tunnelType
-     * @return set of tunnels
-     */
-    Collection<Tunnel> getTunnels(ConnectPoint connectPoint, Tunnel.Type type);
-
-    /**
-     * Returns set of all tunnels from the
-     * specified source connectpoint and destination connectpoint.
-     *
-     * @param src sourcePoint
-     * @param dst destinationPoint
+     * @param consumerId a tunnel consumer
+     * @param src a source point of tunnel.
+     * @param dst a destination point of tunnel
      * @param type tunnel type
-     * @return set of tunnels
+     * @param annotations Annotations
+     * @return collection of available Tunnels
      */
-    Collection<Tunnel> getTunnels(ConnectPoint src, ConnectPoint dst, Tunnel.Type type);
+    Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src,
+                                       TunnelEndPoint dst, Type type,
+                                       Annotations... annotations);
 
     /**
-     * Returns the tunnel between the specified source
-     * and destination connection points.
+     * Returns back a specific tunnel to store.
      *
-     * @param src source label
-     * @param dst destination label
-     * @return tunnel from source to destination; null if none found
+     * @param consumerId a tunnel consumer
+     * @param tunnelId tunnel identify generated by ONOS
+     * @param annotations Annotations
+     * @return success or fail
      */
-    Tunnel getTunnel(Label src, Label dst);
+    boolean returnTunnel(ApplicationId consumerId, TunnelId tunnelId,
+                              Annotations... annotations);
 
     /**
-     * Returns the tunnel based on the Id.
+     * Returns all specific name tunnel back store. Annotations parameter is reserved.if there
+     * is no tunnel in the store, return a "null" object, and record the tunnel subscription.
+     * Where tunnel is created, ONOS notifies this consumer actively.
      *
-     * @param id tunnelId
-     * @return tunnel with specified Id
+     * @param consumerId a tunnel consumer
+     * @param tunnelName tunnel name
+     * @param annotations Annotations
+     * @return boolean
      */
-    Tunnel getTunnel(TunnelId id);
+    boolean returnTunnel(ApplicationId consumerId, TunnelName tunnelName,
+                           Annotations... annotations);
+
+    /**
+     * Returns all specific type tunnels between source and destination back
+     * store. Annotations parameter is reserved.
+     *
+     * @param consumerId a tunnel consumer
+     * @param src a source point of tunnel.
+     * @param dst a destination point of tunnel
+     * @param type tunnel type
+     * @param annotations Annotations
+     * @return success or fail
+     */
+    boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src,
+                              TunnelEndPoint dst, Type type,
+                              Annotations... annotations);
+
+    /**
+     * Returns all tunnels between source and destination back the store.
+     * Annotations parameter is reserved.
+     *
+     * @param consumerId a tunnel consumer
+     * @param src a source point of tunnel.
+     * @param dst a destination point of tunnel.
+     * @param annotations Annotations
+     * @return success or fail
+     */
+    boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src,
+                              TunnelEndPoint dst, Annotations... annotations);
+
+    /**
+     * Returns a tunnel by a specific tunnel identity.
+     *
+     * @param tunnelId tunnel identify generated by tunnel producer
+     * @return Tunnel
+     */
+    Tunnel queryTunnel(TunnelId tunnelId);
+
+    /**
+     * Returns all tunnel subscription record by consumer.
+     *
+     * @param consumerId consumer identity
+     * @return Collection of TunnelSubscription
+     */
+    Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId consumerId);
+
+    /**
+     * Returns all specified type tunnels.
+     *
+     * @param type tunnel type
+     * @return Collection of tunnels
+     */
+    Collection<Tunnel> queryTunnel(Type type);
+
+    /**
+     * Returns all tunnels between source point and destination point.
+     *
+     * @param src a source point of tunnel.
+     * @param dst a destination point of tunnel.
+     * @return Collection of tunnels
+     */
+    Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst);
+
+    /**
+     * Returns all tunnels.
+     *
+     * @return all tunnels
+     */
+    int tunnelCount();
 
     /**
      * Adds the specified tunnel listener.
@@ -113,5 +191,4 @@
      * @param listener tunnel listener
      */
     void removeListener(TunnelListener listener);
-
 }