Moving LabelResourceManager to incubator

Breaking apart resource package into {device, link, label}
Refactored cluster serializers so they are visible

Change-Id: I71051bcd5e790ae6abeb154bf58286e584c32858
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/DefaultLabelResource.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/DefaultLabelResource.java
new file mode 100644
index 0000000..8eed7c1
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/DefaultLabelResource.java
@@ -0,0 +1,81 @@
+package org.onosproject.incubator.net.resource.label;
+
+import java.util.Objects;
+
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.provider.ProviderId;
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * the implementation of a label resource of a device.
+ */
+public final class DefaultLabelResource implements LabelResource {
+
+    private DeviceId deviceId;
+
+    private LabelResourceId labelResourceId;
+
+    /**
+     * Initialize a label resource object.
+     * @param deviceId device identifier
+     * @param labelResourceId label resource id
+     */
+    public DefaultLabelResource(String deviceId, long labelResourceId) {
+        this.deviceId = DeviceId.deviceId(deviceId);
+        this.labelResourceId = LabelResourceId.labelResourceId(labelResourceId);
+    }
+
+    /**
+     * Initialize a label resource object.
+     * @param deviceId device identifier
+     * @param labelResourceId label resource id
+     */
+    public DefaultLabelResource(DeviceId deviceId,
+                                LabelResourceId labelResourceId) {
+        this.deviceId = deviceId;
+        this.labelResourceId = labelResourceId;
+    }
+
+    @Override
+    public DeviceId deviceId() {
+        return deviceId;
+    }
+
+    @Override
+    public LabelResourceId labelResourceId() {
+        return labelResourceId;
+    }
+
+    @Override
+    public Annotations annotations() {
+        return null;
+    }
+
+    @Override
+    public ProviderId providerId() {
+        return null;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(deviceId, labelResourceId);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof DefaultLabelResource) {
+            DefaultLabelResource that = (DefaultLabelResource) obj;
+            return Objects.equals(this.deviceId, that.deviceId)
+                    && Objects.equals(this.labelResourceId,
+                                      that.labelResourceId);
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this).add("deviceId", deviceId)
+                .add("labelResourceId", labelResourceId).toString();
+    }
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResource.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResource.java
new file mode 100644
index 0000000..612240f
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResource.java
@@ -0,0 +1,23 @@
+package org.onosproject.incubator.net.resource.label;
+
+import org.onosproject.net.Annotated;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.Provided;
+
+/**
+ * Representation of label resource.
+ */
+public interface LabelResource extends Annotated, Provided, NetworkResource {
+    /**
+     * Returns device id.
+     * @return DeviceId
+     */
+    DeviceId deviceId();
+
+    /**
+     * Returns labelResource Id.
+     * @return LabelResourceId
+     */
+    LabelResourceId labelResourceId();
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceAdminService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceAdminService.java
new file mode 100644
index 0000000..6576ebf
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceAdminService.java
@@ -0,0 +1,49 @@
+package org.onosproject.incubator.net.resource.label;
+
+import org.onosproject.net.DeviceId;
+
+/**
+ * Service for managing label resource.
+ */
+public interface LabelResourceAdminService {
+    /**
+     * Creates the only label resource of some device id from begin label to end
+     * label.
+     *
+     * @param deviceId device identifier
+     * @param beginLabel represents for the first label id in the range of label
+     *            pool
+     * @param endLabel represents for the last label id in the range of label
+     *            pool
+     * @return success or fail
+     */
+    boolean createDevicePool(DeviceId deviceId, LabelResourceId beginLabel,
+                             LabelResourceId endLabel);
+
+    /**
+     * Creates the only global label resource pool.
+     *
+     * @param beginLabel represents for the first label id in the range of label
+     *            pool
+     * @param endLabel represents for the last label id in the range of label
+     *            pool
+     * @return success or fail
+     */
+    boolean createGlobalPool(LabelResourceId beginLabel,
+                             LabelResourceId endLabel);
+
+    /**
+     * Destroys a label resource pool of a specific device id.
+     *
+     * @param deviceId device identifier
+     * @return success or fail
+     */
+    boolean destroyDevicePool(DeviceId deviceId);
+
+    /**
+     * Destroys the global label resource pool.
+     *
+     * @return success or fail
+     */
+    boolean destroyGlobalPool();
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceDelegate.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceDelegate.java
new file mode 100644
index 0000000..25287b9
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceDelegate.java
@@ -0,0 +1,9 @@
+package org.onosproject.incubator.net.resource.label;
+
+import org.onosproject.store.StoreDelegate;
+/**
+ * Label resource store delegate.
+ */
+public interface LabelResourceDelegate extends StoreDelegate<LabelResourceEvent> {
+
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceEvent.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceEvent.java
new file mode 100644
index 0000000..b532378
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceEvent.java
@@ -0,0 +1,38 @@
+package org.onosproject.incubator.net.resource.label;
+
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Describes label resource event.
+ */
+public final class LabelResourceEvent
+        extends AbstractEvent<LabelResourceEvent.Type, LabelResourcePool> {
+
+    /**
+     * Type of label resource event.
+     */
+    public enum Type {
+        /**
+         * Signifies that a new pool has been administratively created.
+         */
+        POOL_CREATED,
+        /**
+         * Signifies that a new pool has been administratively destroyed.
+         */
+        POOL_DESTROYED,
+        /**
+         * Signifies that a new pool has been administratively changed.
+         */
+        POOL_CAPACITY_CHANGED
+    }
+
+    /**
+     * Creates an event of a given type and the given LabelResourcePool.
+     *
+     * @param type event type
+     * @param subject pool
+     */
+    public LabelResourceEvent(Type type, LabelResourcePool subject) {
+        super(type, subject);
+    }
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceId.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceId.java
new file mode 100644
index 0000000..688dbff
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceId.java
@@ -0,0 +1,46 @@
+package org.onosproject.incubator.net.resource.label;
+
+import org.onosproject.net.resource.ResourceId;
+
+import java.util.Objects;
+
+/**
+ * Representation of a label.
+ */
+public final class LabelResourceId implements ResourceId {
+
+    private long labelId;
+
+    public static LabelResourceId labelResourceId(long labelResourceId) {
+        return new LabelResourceId(labelResourceId);
+    }
+
+    // Public construction is prohibited
+    private LabelResourceId(long labelId) {
+        this.labelId = labelId;
+    }
+
+    public long labelId() {
+        return labelId;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(labelId);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof LabelResourceId) {
+            LabelResourceId that = (LabelResourceId) obj;
+            return Objects.equals(this.labelId, that.labelId);
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return String.valueOf(this.labelId);
+    }
+
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceListener.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceListener.java
new file mode 100644
index 0000000..599a2b4
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceListener.java
@@ -0,0 +1,9 @@
+package org.onosproject.incubator.net.resource.label;
+
+import org.onosproject.event.EventListener;
+/**
+ * Entity capable of receiving label resource related events.
+ */
+public interface LabelResourceListener extends EventListener<LabelResourceEvent> {
+
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourcePool.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourcePool.java
new file mode 100644
index 0000000..e590dd9
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourcePool.java
@@ -0,0 +1,173 @@
+package org.onosproject.incubator.net.resource.label;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.util.Collections;
+import java.util.Objects;
+import java.util.Set;
+
+import org.onosproject.net.DeviceId;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Abstraction of the capacity of device label resource or global label
+ * resource. it's contiguous range of label resource.when a application apply
+ * some labels of some device,first catch from Set that store
+ * available labels,if the size of the Set less than the apply number,then get
+ * labels by calculating with three attributes, beginLabel,endLabel and
+ * currentUsedMaxLabelId
+ */
+public class LabelResourcePool {
+
+    private final DeviceId deviceId;
+    private final LabelResourceId beginLabel;
+    private final LabelResourceId endLabel;
+    private final long totalNum; // capacity of label resource pool
+    private final long usedNum; // have used label number
+    private final LabelResourceId currentUsedMaxLabelId; // the maximal label
+                                                        // number id
+    private ImmutableSet<LabelResource> releaseLabelId; // Set of released label
+
+    /**
+     * Creates a pool by device id,begin label id,end label id.
+     *
+     * @param deviceId device identifier
+     * @param beginLabel represents for the first label id in the range of label
+     *            resource pool
+     * @param endLabel represents for the last label id in the range of label
+     *            resource pool
+     */
+    public LabelResourcePool(String deviceId, long beginLabel, long endLabel) {
+        this(deviceId, beginLabel, endLabel, endLabel - beginLabel + 1, 0L,
+             beginLabel, ImmutableSet.copyOf(Collections.emptySet()));
+    }
+
+    /**
+     * Creates a pool by device id,begin label id,end label id.
+     * used to update a pool in the store.
+     * @param deviceId device identifier
+     * @param beginLabel represents for the first label id in the range of label
+     *            resource pool
+     * @param endLabel represents for the last label id in the range of label
+     *            resource pool
+     * @param totalNum capacity of label resource pool
+     * @param usedNum have used label number
+     * @param currentUsedMaxLabelId the maximal label number id
+     * @param releaseLabelId Set of released label
+     */
+    public LabelResourcePool(String deviceId, long beginLabel, long endLabel,
+                             long totalNum, long usedNum,
+                             long currentUsedMaxLabelId,
+                             ImmutableSet<LabelResource> releaseLabelId) {
+        checkArgument(endLabel >= beginLabel,
+                      "endLabel %s must be greater than or equal to beginLabel %s",
+                      endLabel, beginLabel);
+        this.deviceId = DeviceId.deviceId(deviceId);
+        this.beginLabel = LabelResourceId.labelResourceId(beginLabel);
+        this.endLabel = LabelResourceId.labelResourceId(endLabel);
+        this.totalNum = totalNum;
+        this.usedNum = usedNum;
+        this.currentUsedMaxLabelId = LabelResourceId
+                .labelResourceId(currentUsedMaxLabelId);
+        this.releaseLabelId = releaseLabelId;
+    }
+
+    /**
+     * Returns a device id.
+     *
+     * @return DeviceId
+     */
+    public DeviceId deviceId() {
+        return deviceId;
+    }
+
+    /**
+     * Returns a begin Label id.
+     *
+     * @return begin Label id
+     */
+    public LabelResourceId beginLabel() {
+        return beginLabel;
+    }
+
+    /**
+     * Returns a end Label id.
+     *
+     * @return end Label id
+     */
+    public LabelResourceId endLabel() {
+        return endLabel;
+    }
+
+    /**
+     * Returns a begin Label id.
+     *
+     * @return current Used Maximal Label Id
+     */
+    public LabelResourceId currentUsedMaxLabelId() {
+        return currentUsedMaxLabelId;
+    }
+
+    /**
+     * Returns total number.
+     *
+     * @return the total label number
+     */
+    public long totalNum() {
+        return totalNum;
+    }
+
+    /**
+     * Returns used number.
+     *
+     * @return the used label number
+     */
+    public long usedNum() {
+        return usedNum;
+    }
+
+    /**
+     * Returns the Set of released label before.
+     *
+     * @return the Set of LabelResource
+     */
+    public Set<LabelResource> releaseLabelId() {
+        return releaseLabelId;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(this.deviceId, this.beginLabel, this.endLabel,
+                            this.totalNum, this.usedNum,
+                            this.currentUsedMaxLabelId, this.releaseLabelId);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof LabelResourcePool) {
+            LabelResourcePool that = (LabelResourcePool) obj;
+            return Objects.equals(this.deviceId, that.deviceId)
+                    && Objects.equals(this.beginLabel, that.beginLabel)
+                    && Objects.equals(this.endLabel, that.endLabel)
+                    && Objects.equals(this.totalNum, that.totalNum)
+                    && Objects.equals(this.usedNum, that.usedNum)
+                    && Objects.equals(this.currentUsedMaxLabelId,
+                                      that.currentUsedMaxLabelId)
+                    && Objects.equals(this.releaseLabelId, that.releaseLabelId);
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        // TODO Auto-generated method stub
+        return MoreObjects.toStringHelper(this).add("deviceId", this.deviceId)
+                .add("beginLabel", this.beginLabel)
+                .add("endLabel", this.endLabel).add("totalNum", this.totalNum)
+                .add("usedNum", this.usedNum)
+                .add("currentUsedMaxLabelId", this.currentUsedMaxLabelId)
+                .add("releaseLabelId", this.releaseLabelId).toString();
+    }
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProvider.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProvider.java
new file mode 100644
index 0000000..d0b46d0
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProvider.java
@@ -0,0 +1,10 @@
+package org.onosproject.incubator.net.resource.label;
+
+import org.onosproject.net.provider.Provider;
+/**
+ * Abstraction of an entity providing information about label resource
+ * to the core.
+ */
+public interface LabelResourceProvider extends Provider {
+
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderRegistry.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderRegistry.java
new file mode 100644
index 0000000..4d50297
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderRegistry.java
@@ -0,0 +1,10 @@
+package org.onosproject.incubator.net.resource.label;
+
+import org.onosproject.net.provider.ProviderRegistry;
+/**
+ * Abstraction of an label resource provider registry.
+ */
+public interface LabelResourceProviderRegistry
+        extends ProviderRegistry<LabelResourceProvider, LabelResourceProviderService> {
+
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderService.java
new file mode 100644
index 0000000..e804cc9
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderService.java
@@ -0,0 +1,26 @@
+package org.onosproject.incubator.net.resource.label;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.provider.ProviderService;
+
+/**
+ * Means for injecting label information into the core.
+ */
+public interface LabelResourceProviderService extends ProviderService<LabelResourceProvider> {
+
+    /**
+     * Signals that a device label resource pool has been detected.
+     * @param deviceId device identifier
+     * @param beginLabel the begin label number of resource
+     * @param endLabel the end label number of resource
+     */
+    void deviceLabelResourcePoolDetected(DeviceId deviceId,
+                                         LabelResourceId beginLabel,
+                                         LabelResourceId endLabel);
+
+    /**
+     * Signals that an label resource pool has been destroyed.
+     * @param deviceId device identifier
+     */
+    void deviceLabelResourcePoolDestroyed(DeviceId deviceId);
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceRequest.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceRequest.java
new file mode 100644
index 0000000..7e429e2
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceRequest.java
@@ -0,0 +1,101 @@
+package org.onosproject.incubator.net.resource.label;
+
+import java.util.Collection;
+import java.util.Objects;
+
+import org.onosproject.net.DeviceId;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableSet;
+/**
+ * Represents for a label request.
+ */
+public class LabelResourceRequest {
+
+    private final DeviceId deviceId;
+    private final Type type;
+    private final long applyNum;
+    private ImmutableSet<LabelResource> releaseCollection;
+
+    /**
+     * Creates LabelResourceRequest object.
+     * @param deviceId device identifier
+     * @param type request type
+     * @param applyNum apply the number of labels
+     * @param releaseCollection Set of released label
+     */
+    public LabelResourceRequest(DeviceId deviceId,
+                                Type type,
+                                long applyNum,
+                                ImmutableSet<LabelResource> releaseCollection) {
+        this.deviceId = deviceId;
+        this.type = type;
+        this.applyNum = applyNum;
+        this.releaseCollection = releaseCollection;
+    }
+    /**
+     * Returns a device id.
+     * @return DeviceId
+     */
+    public DeviceId deviceId() {
+        return deviceId;
+    }
+
+    /**
+     * Returns request type.
+     * @return Type
+     */
+    public Type type() {
+        return type;
+    }
+
+    /**
+     * Returns apply label number.
+     * @return label number
+     */
+    public long applyNum() {
+        return applyNum;
+    }
+
+    /**
+     * Returns the collection of release labels.
+     * @return Collection of DefaultLabelResource
+     */
+    public Collection<LabelResource> releaseCollection() {
+        return releaseCollection;
+    }
+
+    /**
+     * Request type.
+     */
+    public enum Type {
+        APPLY, //apple label request
+        RELEASE //release label request
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(this.deviceId, this.applyNum, this.type,
+                            this.releaseCollection);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof LabelResourceRequest) {
+            LabelResourceRequest that = (LabelResourceRequest) obj;
+            return Objects.equals(this.deviceId, that.deviceId)
+                    && Objects.equals(this.applyNum, that.applyNum)
+                    && Objects.equals(this.type, that.type)
+                    && Objects.equals(this.releaseCollection,
+                                      that.releaseCollection);
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this).add("deviceId", this.deviceId)
+                .add("applyNum", this.applyNum).add("type", this.type)
+                .add("releaseCollection", this.releaseCollection).toString();
+    }
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceService.java
new file mode 100644
index 0000000..9b35de1
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceService.java
@@ -0,0 +1,109 @@
+package org.onosproject.incubator.net.resource.label;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.onosproject.net.DeviceId;
+
+import com.google.common.collect.Multimap;
+
+/**
+ * Service for providing label resource allocation.
+ */
+public interface LabelResourceService {
+
+    /**
+     * Returns labels from resource pool by a specific device id.
+     *
+     * @param deviceId device identifier
+     * @param applyNum the applying number
+     * @return collection of applying labels
+     */
+    Collection<LabelResource> applyFromDevicePool(DeviceId deviceId,
+                                                  long applyNum);
+
+    /**
+     * Returns labels from the global label resource pool.
+     *
+     * @param applyNum the applying number
+     * @return collection of applying labels
+     */
+    Collection<LabelResource> applyFromGlobalPool(long applyNum);
+
+    /**
+     * Releases unused labels to device pools .
+     *
+     * @param release the collection of releasing labels
+     * @return success or fail
+     */
+    boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release);
+
+    /**
+     * Releases unused labels to the global resource pool.
+     *
+     * @param release release the collection of releasing labels
+     * @return success or fail
+     */
+    boolean releaseToGlobalPool(Set<LabelResourceId> release);
+
+    /**
+     * Judges if the pool of a specific device id is full.
+     *
+     * @param deviceId device identifier
+     * @return yes or no
+     */
+    boolean isDevicePoolFull(DeviceId deviceId);
+
+    /**
+     * Judges if the global resource pool is full.
+     *
+     * @return yes or no
+     */
+    boolean isGlobalPoolFull();
+
+    /**
+     * Returns the unused label number of a label resource pool by a specific device
+     * id.
+     *
+     * @param deviceId device identifier
+     * @return number of unused labels
+     */
+    long getFreeNumOfDevicePool(DeviceId deviceId);
+
+    /**
+     * Returns the unused label number of a global label resource pool.
+     *
+     * @return number of unused labels
+     */
+    long getFreeNumOfGlobalPool();
+
+    /**
+     * Returns the label resource pool of a label resource by a specific device
+     * id.
+     *
+     * @param deviceId device identifier
+     * @return the device label resource pool
+     */
+    LabelResourcePool getDeviceLabelResourcePool(DeviceId deviceId);
+
+    /**
+     * Returns the global label resource pool.
+     *
+     * @return the global label resource pool
+     */
+    LabelResourcePool getGlobalLabelResourcePool();
+
+    /**
+     * Adds the specified label resource listener.
+     *
+     * @param listener label resource listener
+     */
+    void addListener(LabelResourceListener listener);
+
+    /**
+     * Removes the specified label resource listener.
+     *
+     * @param listener label resource listener
+     */
+    void removeListener(LabelResourceListener listener);
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceStore.java b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceStore.java
new file mode 100644
index 0000000..8fdc77d
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceStore.java
@@ -0,0 +1,137 @@
+package org.onosproject.incubator.net.resource.label;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.store.Store;
+
+import com.google.common.collect.Multimap;
+
+/**
+ * Manages inventory of label; not intended for direct use.
+ *
+ */
+public interface LabelResourceStore
+        extends Store<LabelResourceEvent, LabelResourceDelegate> {
+
+    /**
+     * Creates a label resource of some device id from begin label to end label.
+     *
+     * @param deviceId device identifier
+     * @param beginLabel represents for the first label id in the range of label
+     *            pool
+     * @param endLabel represents for the last label id in the range of label
+     *            pool
+     * @return success or fail
+     */
+    boolean createDevicePool(DeviceId deviceId, LabelResourceId beginLabel,
+                             LabelResourceId endLabel);
+
+    /**
+     * Creates the global label resource pool.
+     *
+     * @param beginLabel represents for the first label id in the range of label
+     *            pool
+     * @param endLabel represents for the last label id in the range of label
+     *            pool
+     * @return success or fail
+     */
+    boolean createGlobalPool(LabelResourceId beginLabel,
+                             LabelResourceId endLabel);
+
+    /**
+     * Destroys a label resource pool of a specific device id.
+     *
+     * @param deviceId device identifier
+     * @return success or fail
+     */
+    boolean destroyDevicePool(DeviceId deviceId);
+
+    /**
+     * Destroys a the global label resource pool.
+     *
+     * @return success or fail
+     */
+    boolean destroyGlobalPool();
+
+    /**
+     * Returns labels from resource pool by a specific device id.
+     *
+     * @param deviceId device identifier
+     * @param applyNum the applying number
+     * @return collection of applying labels
+     */
+    Collection<LabelResource> applyFromDevicePool(DeviceId deviceId,
+                                                  long applyNum);
+
+    /**
+     * Returns labels from the global label resource pool.
+     *
+     * @param applyNum apply the number of labels
+     * @return collection of labels
+     */
+    Collection<LabelResource> applyFromGlobalPool(long applyNum);
+
+    /**
+     * Releases unused labels to device pools .
+     *
+     * @param release the collection of releasing labels
+     * @return success or fail
+     */
+    boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release);
+
+    /**
+     * Releases unused labels to the global resource pool.
+     *
+     * @param release release the collection of releasing labels
+     * @return success or fail
+     */
+    boolean releaseToGlobalPool(Set<LabelResourceId> release);
+
+    /**
+     * Judges if the pool of a specific device id is full.
+     *
+     * @param deviceId device identifier
+     * @return yes or no
+     */
+    boolean isDevicePoolFull(DeviceId deviceId);
+
+    /**
+     * Judges if the global resource pool is full.
+     *
+     * @return yes or no
+     */
+    boolean isGlobalPoolFull();
+
+    /**
+     * Returns the unused label number of a label resource pool by a specific device
+     * id.
+     *
+     * @param deviceId device identifier
+     * @return number of unused labels
+     */
+    long getFreeNumOfDevicePool(DeviceId deviceId);
+
+    /**
+     * Returns the unused number of a global label resource pool.
+     *
+     * @return number of unused labels
+     */
+    long getFreeNumOfGlobalPool();
+
+    /**
+     * Returns the label resource pool by a specific device id.
+     *
+     * @param deviceId device identifier
+     * @return the device label resource pool
+     */
+    LabelResourcePool getDeviceLabelResourcePool(DeviceId deviceId);
+
+    /**
+     * Returns the global label resource pool.
+     *
+     * @return the global label resource pool
+     */
+    LabelResourcePool getGlobalLabelResourcePool();
+}