Detangling incubator: virtual nets, tunnels, resource labels, oh my
- virtual networking moved to /apps/virtual; with CLI & REST API
- tunnels and labels moved to /apps/tunnel; with CLI & REST API; UI disabled for now
- protobuf/models moved to /core/protobuf/models
- defunct grpc/rpc registry stuff left under /graveyard
- compile dependencies on /incubator moved to respective modules for compilation
- run-time dependencies will need to be re-tested for dependent apps
- /graveyard will be removed in not-too-distant future
Change-Id: I0a0b995c635487edcf95a352f50dd162186b0b39
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/DefaultLabelResource.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/DefaultLabelResource.java
new file mode 100644
index 0000000..9c5a6c0
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/DefaultLabelResource.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import java.util.Objects;
+
+import com.google.common.annotations.Beta;
+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.
+ */
+@Beta
+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/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResource.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResource.java
new file mode 100644
index 0000000..669c020
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResource.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.Annotated;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.Provided;
+
+/**
+ * Representation of label resource.
+ */
+@Beta
+public interface LabelResource extends Annotated, Provided, NetworkResource {
+ /**
+ * Returns device id.
+ * @return DeviceId
+ */
+ DeviceId deviceId();
+
+ /**
+ * Returns label resource identifier.
+ *
+ * @return resource id
+ */
+ LabelResourceId labelResourceId();
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceAdminService.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceAdminService.java
new file mode 100644
index 0000000..28bf86b
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceAdminService.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.DeviceId;
+
+/**
+ * Service for managing label resource.
+ */
+@Beta
+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/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceDelegate.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceDelegate.java
new file mode 100644
index 0000000..2dde408
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceDelegate.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * Label resource store delegate.
+ */
+@Beta
+public interface LabelResourceDelegate extends StoreDelegate<LabelResourceEvent> {
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceEvent.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceEvent.java
new file mode 100644
index 0000000..a21ae3b
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceEvent.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Describes label resource event.
+ */
+@Beta
+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/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceId.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceId.java
new file mode 100644
index 0000000..99d7f69
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceId.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
+
+/**
+ * Representation of a label.
+ */
+@Beta
+public final class LabelResourceId extends Identifier<Long> {
+
+ /**
+ * Creates a new label identifier.
+ *
+ * @param labelResourceId backing identifier value
+ * @return label identifier
+ */
+ public static LabelResourceId labelResourceId(long labelResourceId) {
+ return new LabelResourceId(labelResourceId);
+ }
+
+ // Public construction is prohibited
+ private LabelResourceId(long labelId) {
+ super(labelId);
+ }
+
+ /**
+ * Returns label identifier.
+ *
+ * @return label identifier
+ */
+ public long labelId() {
+ return identifier;
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceListener.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceListener.java
new file mode 100644
index 0000000..113dd2a
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceListener.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.EventListener;
+
+/**
+ * Entity capable of receiving label resource related events.
+ */
+@Beta
+public interface LabelResourceListener extends EventListener<LabelResourceEvent> {
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourcePool.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourcePool.java
new file mode 100644
index 0000000..d34bb97
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourcePool.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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 com.google.common.annotations.Beta;
+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.
+ */
+@Beta
+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 an 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/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProvider.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProvider.java
new file mode 100644
index 0000000..986993e
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProvider.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.provider.Provider;
+
+/**
+ * Abstraction of an entity providing information about label resource
+ * to the core.
+ */
+@Beta
+public interface LabelResourceProvider extends Provider {
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderRegistry.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderRegistry.java
new file mode 100644
index 0000000..c6130cb
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderRegistry.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.provider.ProviderRegistry;
+
+/**
+ * Abstraction of an label resource provider registry.
+ */
+@Beta
+public interface LabelResourceProviderRegistry
+ extends ProviderRegistry<LabelResourceProvider, LabelResourceProviderService> {
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderService.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderService.java
new file mode 100644
index 0000000..b7fd072
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceProviderService.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.provider.ProviderService;
+
+/**
+ * Means for injecting label information into the core.
+ */
+@Beta
+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/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceRequest.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceRequest.java
new file mode 100644
index 0000000..776e068
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceRequest.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import java.util.Collection;
+import java.util.Objects;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.DeviceId;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Represents for a label request.
+ */
+@Beta
+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/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceService.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceService.java
new file mode 100644
index 0000000..91cdedc
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceService.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import java.util.Collection;
+import java.util.Set;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.ListenerService;
+import org.onosproject.net.DeviceId;
+
+import com.google.common.collect.Multimap;
+
+/**
+ * Service for providing label resource allocation.
+ */
+@Beta
+public interface LabelResourceService
+ extends ListenerService<LabelResourceEvent, LabelResourceListener> {
+
+ /**
+ * 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();
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceStore.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceStore.java
new file mode 100644
index 0000000..b27cefe
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/LabelResourceStore.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.net.resource.label;
+
+import java.util.Collection;
+import java.util.Set;
+
+import com.google.common.annotations.Beta;
+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.
+ *
+ */
+@Beta
+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();
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/package-info.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/package-info.java
new file mode 100644
index 0000000..7a8de6f
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/resource/label/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Service for reserving labels as network resources.
+ */
+package org.onosproject.incubator.net.resource.label;
\ No newline at end of file