[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/TunnelStore.java b/core/api/src/main/java/org/onosproject/net/tunnel/TunnelStore.java
index 09c74c1..107dea3 100644
--- a/core/api/src/main/java/org/onosproject/net/tunnel/TunnelStore.java
+++ b/core/api/src/main/java/org/onosproject/net/tunnel/TunnelStore.java
@@ -15,100 +15,206 @@
  */
 package org.onosproject.net.tunnel;
 
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
+import java.util.Collection;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.Annotations;
 import org.onosproject.net.provider.ProviderId;
+import org.onosproject.net.tunnel.Tunnel.Type;
 import org.onosproject.store.Store;
 
 /**
- * Manages inventory of tunnels.
+ * Manages inventory of tunnel; not intended for direct use.
  */
 public interface TunnelStore extends Store<TunnelEvent, TunnelStoreDelegate> {
-
     /**
-     * Returns the number of tunnels in the store.
+     * Creates or updates a tunnel.
      *
-     * @return number of tunnels
+     * @param tunnel tunnel
+     * @return tunnel identity
      */
-    int getTunnelCount();
+    TunnelId createOrUpdateTunnel(Tunnel tunnel);
 
     /**
-     * Returns an iterable collection of all tunnel in the inventory.
+     * Deletes a tunnel by a specific tunnel identifier.
      *
-     * @return collection of all tunnels
+     * @param tunnelId tunnel unique identifier generated by ONOS
      */
-    Iterable<Tunnel> getTunnels();
+    void deleteTunnel(TunnelId tunnelId);
 
     /**
-     * Returns all tunnels egressing from the specified device.
+     * Deletes all tunnels between source point and destination point.
      *
-     * @param deviceId device identifier
-     * @return set of device tunnels
+     * @param src a source point of tunnel.
+     * @param dst a destination point of tunnel.
+     * @param producerName producerName
      */
-    Iterable<Tunnel> getDeviceEgressTunnels(DeviceId deviceId);
+    void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst,
+                                  ProviderId producerName);
 
     /**
-     * Returns all tunnels ingressing from the specified device.
+     * Deletes all specific type tunnels between source point and destination
+     * point.
      *
-     * @param deviceId device identifier
-     * @return set of device tunnels
-     */
-    Iterable<Tunnel> getDeviceIngressTunnels(DeviceId deviceId);
-
-    /**
-     * Returns the tunnel between the two end-points and the tunnel type.
-     *
-     * @param src source connection point
-     * @param dst destination connection point
+     * @param src a source point of tunnel.
+     * @param dst a destination point of tunnel.
      * @param type tunnel type
-     * @return tunnels or null if one not found between the end-points
+     * @param producerName producerName
      */
-    Iterable<Tunnel> getTunnel(ConnectPoint src, ConnectPoint dst, Tunnel.Type type);
+    void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst,
+                                  Tunnel.Type type, ProviderId producerName);
 
     /**
-     * Returns all tunnels egressing from the specified connection point.
+     * Returns a specific tunnel. 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 source connection point
-     * @return set of connection point tunnels
+     * @param consumerId a tunnel consumer
+     * @param tunnelId tunnel identify generated by onos
+     * @param annotations parameter
+     * @return Tunnel subscribed tunnel
      */
-    Iterable<Tunnel> getEgressTunnels(ConnectPoint src);
+    Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId,
+                           Annotations... annotations);
 
     /**
-     * Returns all tunnels ingressing to the specified connection point.
+     * Returns 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 dst destination connection point
-     * @return set of connection point tunnels
+     * @param consumerId a tunnel consumer
+     * @param tunnelName tunnel name
+     * @param annotations parameter
+     * @return collection of subscribed Tunnels
      */
-    Iterable<Tunnel> getIngressTunnels(ConnectPoint dst);
+    Collection<Tunnel> borrowTunnel(ApplicationId consumerId,
+                                       TunnelName tunnelName,
+                                       Annotations... annotations);
 
     /**
-     * Creates a new tunnel based on the given information.
+     * Returns 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.
      *
-     * @param providerId    provider identity (e.g., PCEP provider)
-     * @param tunnel tunnel information
-     * @return create tunnel event
+     * @param consumerId a tunnel consumer
+     * @param src a source point of tunnel.
+     * @param dst a destination point of tunnel
+     * @param annotations parameter
+     * @return collection of subscribed Tunnels
      */
-    TunnelEvent addTunnel(ProviderId providerId,
-                                        Tunnel tunnel);
+    Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src,
+                                       TunnelEndPoint dst, Annotations... annotations);
 
     /**
-     * Updates a new tunnel based on the given information.
+     * Returns 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 providerId      provider identity (e.g., PCEP provider)
-     * @param tunnel tunnel
-     * @return update tunnel event
+     * @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 collection of available Tunnels
      */
-    TunnelEvent updateTunnel(ProviderId providerId,
-                                        Tunnel tunnel);
+    Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src,
+                                       TunnelEndPoint dst, Type type,
+                                       Annotations... annotations);
 
     /**
-     * Removes a new tunnel based on the given information.
+     * Returns back a specific tunnel to store.
      *
-     * @param providerId      provider identity (e.g., PCEP provider)
-     * @param tunnel tunnel
-     * @return remove tunnel event
+     * @param consumerId a tunnel consumer
+     * @param tunnelId tunnel identify generated by ONOS
+     * @param annotations Annotations
+     * @return success or fail
      */
-    TunnelEvent removeTunnel(ProviderId providerId,
-                             Tunnel tunnel);
+    boolean returnTunnel(ApplicationId consumerId, TunnelId tunnelId,
+                              Annotations... annotations);
 
+    /**
+     * 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 consumerId a tunnel consumer
+     * @param tunnelName tunnel name
+     * @param annotations Annotations
+     * @return boolean
+     */
+    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();
 }