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/domain/ExtraSubjectFactories.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/ExtraSubjectFactories.java
new file mode 100644
index 0000000..08737d6
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/ExtraSubjectFactories.java
@@ -0,0 +1,39 @@
+/*
+ * 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.domain;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.config.SubjectFactory;
+
+/**
+ * Set of subject factories for potential configuration subjects.
+ */
+@Beta
+public final class ExtraSubjectFactories {
+
+ // Construction forbidden
+ private ExtraSubjectFactories() {
+ }
+
+ public static final SubjectFactory<IntentDomainId> INTENT_DOMAIN_SUBJECT_FACTORY =
+ new SubjectFactory<IntentDomainId>(IntentDomainId.class, "domains") {
+ @Override
+ public IntentDomainId createSubject(String key) {
+ return IntentDomainId.valueOf(key);
+ }
+ };
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomain.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomain.java
new file mode 100644
index 0000000..7060104
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomain.java
@@ -0,0 +1,124 @@
+/*
+ * 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.domain;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+
+import java.util.Set;
+
+/**
+ * Representation of an intent domain which includes the set of internal devices,
+ * the set of edge ports, and the implementation of the domain provider.
+ */
+@Beta
+public class IntentDomain {
+
+ private final IntentDomainId id;
+ private String name;
+
+ private Set<DeviceId> internalDevices;
+ private Set<ConnectPoint> edgePorts;
+
+ private IntentDomainProvider provider;
+
+ public IntentDomain(IntentDomainId id, String name,
+ Set<DeviceId> internalDevices,
+ Set<ConnectPoint> edgePorts) {
+ this.id = id;
+ this.name = name;
+ this.internalDevices = internalDevices;
+ this.edgePorts = edgePorts;
+ }
+
+ /**
+ * Returns the id for the intent domain.
+ *
+ * @return intent domain id
+ */
+ public IntentDomainId id() {
+ return id;
+ }
+
+ /**
+ * Returns the friendly name for the intent domain.
+ *
+ * @return intent domain name
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * Returns the set of internal devices for the intent domain (devices under
+ * exclusive control of the intent domain).
+ *
+ * @return set of internal devices
+ */
+ public Set<DeviceId> internalDevices() {
+ return internalDevices;
+ }
+
+ /**
+ * Returns the set of edge ports for the intent domain.
+ *
+ * @return set of edge ports
+ */
+ public Set<ConnectPoint> edgePorts() {
+ return edgePorts;
+ }
+
+ /**
+ * Returns the provider for the intent domain.
+ *
+ * @return intent domain provider
+ */
+ public IntentDomainProvider provider() {
+ return provider;
+ }
+
+ /**
+ * Returns the status of the intent domain. An intent domain is active if it
+ * has an intent domain provider bound, and it is inactive if one is not bound.
+ *
+ * @return true if active; false otherwise
+ */
+ public boolean isActive() {
+ return provider != null;
+ }
+
+ /**
+ * Sets the provider for the intent domain if one is not already set.
+ *
+ * @param provider new intent domain provider
+ */
+ public void setProvider(IntentDomainProvider provider) {
+ // TODO consider checkState depending on caller
+ if (this.provider == null) {
+ this.provider = provider;
+ }
+ }
+
+ /**
+ * Unsets the provider for the intent domain.
+ */
+ public void unsetProvider() {
+ this.provider = null;
+ }
+
+ //TODO add remaining setters (we will probably want to link this to the network config)
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainEvent.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainEvent.java
new file mode 100644
index 0000000..c34e80e
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainEvent.java
@@ -0,0 +1,35 @@
+/*
+ * 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.domain;
+
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Describes an intent domain event.
+ */
+public class IntentDomainEvent
+ extends AbstractEvent<IntentDomainEvent.Type, IntentDomain> {
+
+ public enum Type {
+ DOMAIN_ADDED,
+ DOMAIN_MODIFIED,
+ DOMAIN_REMOVED
+ }
+
+ protected IntentDomainEvent(Type type, IntentDomain subject) {
+ super(type, subject);
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainId.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainId.java
new file mode 100644
index 0000000..5140762
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainId.java
@@ -0,0 +1,53 @@
+/*
+ * 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.domain;
+
+import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Intent domain identifier.
+ */
+@Beta
+public class IntentDomainId extends Identifier<String> {
+ /**
+ * Creates an intent domain identifier from the specified string representation.
+ *
+ * @param value string value
+ * @return intent identifier
+ */
+ public static IntentDomainId valueOf(String value) {
+ return new IntentDomainId(value);
+ }
+
+ /**
+ * Constructor for serializer.
+ */
+ IntentDomainId() {
+ super(null);
+ }
+
+ /**
+ * Constructs the ID corresponding to a given string value.
+ *
+ * @param value the underlying value of this ID
+ */
+ IntentDomainId(String value) {
+ super(checkNotNull(value, "Intent domain ID cannot be null."));
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainListener.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainListener.java
new file mode 100644
index 0000000..c03b904
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainListener.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.domain;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.EventListener;
+
+/**
+ * Listener for intent domain events.
+ */
+@Beta
+public interface IntentDomainListener
+ extends EventListener<IntentDomainEvent> {
+}
\ No newline at end of file
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainProvider.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainProvider.java
new file mode 100644
index 0000000..7c44521
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainProvider.java
@@ -0,0 +1,85 @@
+/*
+ * 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.domain;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.provider.Provider;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * FIXME.
+ */
+@Beta
+public interface IntentDomainProvider extends Provider {
+
+ /**
+ * Requests that the provider attempt to satisfy the intent primitive.
+ * The application must apply the context before the intent resource
+ * can be used. Request contexts can be explictly cancelled, or they will
+ * eventually time out so that resources can be reused.
+ *
+ * @param domain intent domain for the request
+ * @param primitive intent primitive
+ * @return intent resources that specify paths that satisfy the request.
+ */
+ //TODO Consider an iterable and/or holds (only hold one or two reservation(s) at a time)
+ List<IntentResource> request(IntentDomain domain, IntentPrimitive primitive);
+
+ /**
+ * Request that the provider attempt to modify an existing resource to satisfy
+ * a new intent primitive. The application must apply the context before
+ * the intent resource can be used.
+ *
+ * @param oldResource the resource to be replaced
+ * @param newResource the resource to be applied
+ * @return request contexts that contain resources to satisfy the intent
+ */
+ IntentResource modify(IntentResource oldResource, IntentResource newResource);
+
+ /**
+ * Requests that the provider release an intent resource.
+ *
+ * @param resource intent resource
+ */
+ void release(IntentResource resource);
+
+ /**
+ * Requests that the provider apply the path from the intent resource.
+ *
+ * @param domainIntentResource request context
+ * @return intent resource that satisfies the intent
+ */
+ IntentResource apply(IntentResource domainIntentResource);
+
+ /**
+ * Requests that the provider cancel the path. Requests that are not applied
+ * will be eventually timed out by the provider.
+ *
+ * @param domainIntentResource the intent resource whose path should be cancelled.
+ */
+ void cancel(IntentResource domainIntentResource);
+
+ /**
+ * Returns all intent resources held by the provider.
+ *
+ * @return set of intent resources
+ */
+ Set<IntentResource> getResources();
+}
+
+
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainProviderRegistry.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainProviderRegistry.java
new file mode 100644
index 0000000..c3c597d
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainProviderRegistry.java
@@ -0,0 +1,25 @@
+/*
+ * 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.domain;
+
+import org.onosproject.net.provider.ProviderRegistry;
+
+/**
+ * Abstraction of a intent domain provider registry.
+ */
+public interface IntentDomainProviderRegistry
+ extends ProviderRegistry<IntentDomainProvider, IntentDomainProviderService> {
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainProviderService.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainProviderService.java
new file mode 100644
index 0000000..c74b483
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainProviderService.java
@@ -0,0 +1,26 @@
+/*
+ * 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.domain;
+
+import org.onosproject.net.provider.ProviderService;
+
+/**
+ * Service through which intent domain providers can report intent domain updates.
+ */
+public interface IntentDomainProviderService
+ extends ProviderService<IntentDomainProvider> {
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainService.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainService.java
new file mode 100644
index 0000000..0c010de
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentDomainService.java
@@ -0,0 +1,77 @@
+/*
+ * 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.domain;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.ListenerService;
+import org.onosproject.net.DeviceId;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Service for that maintains a graph of intent domains and a registry of intent
+ * domain providers.
+ */
+@Beta
+public interface IntentDomainService
+ extends ListenerService<IntentDomainEvent, IntentDomainListener> {
+
+ /**
+ * Returns the intent domain for the given id.
+ *
+ * @param id id to look up
+ * @return the intent domain; null if none found
+ */
+ IntentDomain getDomain(IntentDomainId id);
+
+ /**
+ * Returns a set of all intent domains.
+ *
+ * @return set of intent domains
+ */
+ Set<IntentDomain> getDomains();
+
+ /**
+ * Returns any network domains associated with the given device id.
+ *
+ * @param deviceId device id to look up
+ * @return set of intent domain
+ */
+ Set<IntentDomain> getDomains(DeviceId deviceId);
+
+ /**
+ * Requests an intent primitive from the intent domain.
+ *
+ * @param domainId id of target domain
+ * @param primitive intent primitive
+ * @return set of intent resources that satisfy the primitive
+ */
+ List<IntentResource> request(IntentDomainId domainId, IntentPrimitive primitive);
+
+ /**
+ * Submits an intent resource to the intent domain for installation.
+ *
+ * @param domainId id of target domain
+ * @param resource intent resource
+ */
+ void submit(IntentDomainId domainId, IntentResource resource);
+}
+
+
+
+
+
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentPrimitive.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentPrimitive.java
new file mode 100644
index 0000000..04164b5
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentPrimitive.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.domain;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.core.ApplicationId;
+
+/**
+ * Abstract base class for intent primitives.
+ */
+@Beta
+public abstract class IntentPrimitive {
+
+ private final ApplicationId appId;
+
+ public IntentPrimitive(ApplicationId appId) {
+ this.appId = appId;
+ }
+
+ /**
+ * The getter for the application ID associated with the intent primitive upon creation.
+ *
+ * @return the application ID associated with the intent primitive
+ */
+ public ApplicationId appId() {
+ return appId;
+ }
+}
\ No newline at end of file
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentResource.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentResource.java
new file mode 100644
index 0000000..aa6aef4
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/IntentResource.java
@@ -0,0 +1,88 @@
+/*
+ * 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.domain;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.ConnectPoint;
+
+
+/**
+ * The abstract base class for the resource that satisfies an intent primitive.
+ */
+@Beta
+public abstract class IntentResource {
+
+ private final IntentPrimitive primitive;
+
+ private final ApplicationId appId;
+ private final ConnectPoint ingress;
+ private final ConnectPoint egress;
+
+ //* QUESTIONABLE ADDITIONS *//
+
+ // TODO add other common fields
+ //String ingressTag;
+ //String egressTag;
+ //etc.
+
+ public IntentResource(IntentPrimitive primitive, ApplicationId appId,
+ ConnectPoint ingress, ConnectPoint egress) {
+ this.appId = appId;
+ this.ingress = ingress;
+ this.egress = egress;
+ this.primitive = primitive;
+ }
+
+ //TODO when is same package tunnelID should be of type tunnelID and netTunnelId not long.
+
+
+ /**
+ * Returns the intent primitive associated with this resource at creation.
+ *
+ * @return this resource's intent primitive.
+ */
+ public IntentPrimitive primitive() {
+ return primitive;
+ }
+
+ /**
+ * Returns the application ID associated with this resource at creation.
+ *
+ * @return this resource's application ID.
+ */
+ public ApplicationId appId() {
+ return appId;
+ }
+
+ /**
+ * Returns the ingress connect point associated with this resource at creation.
+ *
+ * @return this resource's ingress connect point.
+ */
+ public ConnectPoint ingress() {
+ return ingress;
+ }
+
+ /**
+ * Returns the egress connect point associated with this resource at creation.
+ *
+ * @return this resource's connect point.
+ */
+ public ConnectPoint egress() {
+ return egress;
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/TunnelPrimitive.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/TunnelPrimitive.java
new file mode 100644
index 0000000..5a5518e
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/TunnelPrimitive.java
@@ -0,0 +1,53 @@
+/*
+ * 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.domain;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.ConnectPoint;
+
+/**
+ * Provides connectivity through a domain.
+ */
+@Beta
+public class TunnelPrimitive extends IntentPrimitive {
+
+ private final ConnectPoint one;
+ private final ConnectPoint two;
+
+ public TunnelPrimitive(ApplicationId appId, ConnectPoint one, ConnectPoint two) {
+ super(appId);
+ this.one = one;
+ this.two = two;
+ }
+
+ /**
+ * The getter for the first connection point associated with a tunnel.
+ *
+ * @return the first connection point
+ */
+ public ConnectPoint one() {
+ return one;
+ }
+
+ /**
+ * The getter for the second connection point associated with a tunnel.
+ * @return the second connection point
+ */
+ public ConnectPoint two() {
+ return two;
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/package-info.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/package-info.java
new file mode 100644
index 0000000..c4092aa
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/domain/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.
+ */
+
+/**
+ * Subsystem for network intent domains.
+ */
+package org.onosproject.incubator.net.domain;
\ No newline at end of file
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
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultLabelStack.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultLabelStack.java
new file mode 100644
index 0000000..1c7ff8c
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultLabelStack.java
@@ -0,0 +1,68 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableList;
+import org.onosproject.incubator.net.resource.label.LabelResourceId;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Default implementation of label stack.
+ */
+public class DefaultLabelStack implements LabelStack {
+
+ private final List<LabelResourceId> labelResources;
+
+ /**
+ * Creates label stack.
+ *
+ * @param labelResources contiguous label ids that comprise the path
+ */
+ public DefaultLabelStack(List<LabelResourceId> labelResources) {
+ this.labelResources = ImmutableList.copyOf(labelResources);
+ }
+
+ @Override
+ public List<LabelResourceId> labelResources() {
+ return labelResources;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("labelResources", labelResources)
+ .toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return labelResources.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultLabelStack) {
+ final DefaultLabelStack other = (DefaultLabelStack) obj;
+ return Objects.equals(this.labelResources, other.labelResources);
+ }
+ return false;
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultOpticalTunnelEndPoint.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultOpticalTunnelEndPoint.java
new file mode 100644
index 0000000..c33d713
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultOpticalTunnelEndPoint.java
@@ -0,0 +1,131 @@
+/*
+ * 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.tunnel;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+import java.util.Objects;
+import java.util.Optional;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.AbstractModel;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.ElementId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * Default optical tunnel point model implementation.
+ */
+@Beta
+public class DefaultOpticalTunnelEndPoint extends AbstractModel implements OpticalTunnelEndPoint {
+ private final Optional<ElementId> elementId;
+ private final Optional<PortNumber> portNumber;
+ private final Optional<OpticalTunnelEndPoint> parentPoint;
+ private final Type type;
+ private final OpticalLogicId id;
+ private final boolean isGlobal;
+
+ /**
+ * Creates a optical tunnel point attributed to the specified provider (may be null).
+ * if provider is null, which means the optical tunnel point is not managed by the SB.
+ *
+ * @param providerId tunnelProvider Id
+ * @param elementId parent network element
+ * @param number port number
+ * @param parentPoint parent port or parent label
+ * @param type port type
+ * @param id LabelId
+ * @param isGlobal indicator whether the label is global significant or not
+ * @param annotations optional key/value annotations
+ */
+ public DefaultOpticalTunnelEndPoint(ProviderId providerId, Optional<ElementId> elementId,
+ Optional<PortNumber> number, Optional<OpticalTunnelEndPoint> parentPoint,
+ Type type, OpticalLogicId id, boolean isGlobal, Annotations... annotations) {
+ super(providerId, annotations);
+ this.elementId = elementId;
+ this.portNumber = number;
+ this.parentPoint = parentPoint;
+ this.id = id;
+ this.type = type;
+ this.isGlobal = isGlobal;
+ }
+
+ @Override
+ public OpticalLogicId id() {
+ return id;
+ }
+
+ @Override
+ public Optional<ElementId> elementId() {
+ return elementId;
+ }
+
+ @Override
+ public Optional<PortNumber> portNumber() {
+ return portNumber;
+ }
+
+ @Override
+ public Optional<OpticalTunnelEndPoint> parentPoint() {
+ return parentPoint;
+ }
+
+ @Override
+ public boolean isGlobal() {
+ return isGlobal;
+ }
+
+ @Override
+ public Type type() {
+ return type;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(elementId, portNumber, parentPoint, id);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultOpticalTunnelEndPoint) {
+ final DefaultOpticalTunnelEndPoint other = (DefaultOpticalTunnelEndPoint) obj;
+ return Objects.equals(this.id, other.id) &&
+ Objects.equals(this.type, other.type) &&
+ Objects.equals(this.isGlobal, other.isGlobal) &&
+ Objects.equals(this.elementId, other.elementId) &&
+ Objects.equals(this.portNumber, other.portNumber) &&
+ Objects.equals(this.parentPoint, other.parentPoint);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("elementId", elementId)
+ .add("portNumber", portNumber)
+ .add("parentPoint", parentPoint)
+ .add("type", type)
+ .add("id", id)
+ .add("isGlobal", isGlobal)
+ .toString();
+ }
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultTunnel.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultTunnel.java
new file mode 100644
index 0000000..7c639de
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultTunnel.java
@@ -0,0 +1,236 @@
+/*
+ * 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.tunnel;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+import java.util.Objects;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.core.GroupId;
+import org.onosproject.net.AbstractModel;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.Path;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * The default implementation of an network tunnel. supports for creating a
+ * tunnel by connect point ,IP address, MAC address, device and so on.
+ */
+@Beta
+public final class DefaultTunnel extends AbstractModel implements Tunnel {
+
+ private final TunnelEndPoint src; // a source point of tunnel.
+ private final TunnelEndPoint dst; // a destination point of tunnel.
+ private final State state;
+ private final Type type; // tunnel type
+ private final GroupId groupId; // represent for a group flow table
+ // which a tunnel match up
+ // tunnel producer
+ private final TunnelId tunnelId; // tunnel identify generated by
+ // ONOS as primary key
+ private final TunnelName tunnelName; // name of a tunnel
+ private final Path path;
+ private final NetworkResource networkRes; // network resource to carry label stack
+
+ /**
+ * Creates an active infrastructure tunnel using the supplied information.
+ *
+ * @param producerName provider identity
+ * @param src tunnel source
+ * @param dst tunnel destination
+ * @param type tunnel type
+ * @param groupId groupId
+ * @param tunnelId tunnelId
+ * @param tunnelName tunnel name
+ * @param path the path of tunnel
+ * @param annotations optional key/value annotations
+ */
+ public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
+ TunnelEndPoint dst, Type type, GroupId groupId,
+ TunnelId tunnelId, TunnelName tunnelName, Path path,
+ Annotations... annotations) {
+ this(producerName, src, dst, type, Tunnel.State.ACTIVE, groupId,
+ tunnelId, tunnelName, path, annotations);
+ }
+
+ /**
+ * Creates an tunnel using the supplied information.
+ *
+ * @param producerName provider identity
+ * @param src tunnel source
+ * @param dst tunnel destination
+ * @param type tunnel type
+ * @param state tunnel state
+ * @param groupId groupId
+ * @param tunnelId tunnelId
+ * @param tunnelName tunnel name
+ * @param path the path of tunnel
+ * @param annotations optional key/value annotations
+ */
+ public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
+ TunnelEndPoint dst, Type type, State state,
+ GroupId groupId, TunnelId tunnelId,
+ TunnelName tunnelName, Path path, Annotations... annotations) {
+ super(producerName, annotations);
+ this.src = src;
+ this.dst = dst;
+ this.type = type;
+ this.state = state;
+ this.groupId = groupId;
+ this.tunnelId = tunnelId;
+ this.tunnelName = tunnelName;
+ this.path = path;
+ this.networkRes = null;
+ }
+
+ /**
+ * Creates an active infrastructure tunnel using the supplied information.
+ *
+ * @param producerName provider identity
+ * @param src tunnel source
+ * @param dst tunnel destination
+ * @param type tunnel type
+ * @param groupId groupId
+ * @param tunnelId tunnelId
+ * @param tunnelName tunnel name
+ * @param path the path of tunnel
+ * @param networkRes network resource of tunnel
+ * @param annotations optional key/value annotations
+ */
+ public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
+ TunnelEndPoint dst, Type type, GroupId groupId,
+ TunnelId tunnelId, TunnelName tunnelName, Path path,
+ NetworkResource networkRes, Annotations... annotations) {
+ this(producerName, src, dst, type, Tunnel.State.ACTIVE, groupId,
+ tunnelId, tunnelName, path, networkRes, annotations);
+ }
+
+ /**
+ * Creates an tunnel using the supplied information.
+ *
+ * @param producerName provider identity
+ * @param src tunnel source
+ * @param dst tunnel destination
+ * @param type tunnel type
+ * @param state tunnel state
+ * @param groupId groupId
+ * @param tunnelId tunnelId
+ * @param tunnelName tunnel name
+ * @param path the path of tunnel
+ * @param networkRes network resource of tunnel
+ * @param annotations optional key/value annotations
+ */
+ public DefaultTunnel(ProviderId producerName, TunnelEndPoint src,
+ TunnelEndPoint dst, Type type, State state,
+ GroupId groupId, TunnelId tunnelId,
+ TunnelName tunnelName, Path path, NetworkResource networkRes,
+ Annotations... annotations) {
+ super(producerName, annotations);
+ this.src = src;
+ this.dst = dst;
+ this.type = type;
+ this.state = state;
+ this.groupId = groupId;
+ this.tunnelId = tunnelId;
+ this.tunnelName = tunnelName;
+ this.path = path;
+ this.networkRes = networkRes;
+ }
+
+ @Override
+ public TunnelEndPoint src() {
+ return src;
+ }
+
+ @Override
+ public TunnelEndPoint dst() {
+ return dst;
+ }
+
+ @Override
+ public Type type() {
+ return type;
+ }
+
+ @Override
+ public State state() {
+ return state;
+ }
+
+ @Override
+ public NetworkResource resource() {
+ return networkRes;
+ }
+
+ @Override
+ public TunnelId tunnelId() {
+ return tunnelId;
+ }
+
+ @Override
+ public GroupId groupId() {
+ return groupId;
+ }
+
+ @Override
+ public TunnelName tunnelName() {
+ return tunnelName;
+ }
+
+
+ @Override
+ public Path path() {
+ return path;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(src, dst, type, groupId, tunnelId, tunnelName,
+ state, path, networkRes);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultTunnel) {
+ final DefaultTunnel other = (DefaultTunnel) obj;
+ return Objects.equals(this.src, other.src)
+ && Objects.equals(this.dst, other.dst)
+ && Objects.equals(this.type, other.type)
+ && Objects.equals(this.groupId, other.groupId)
+ && Objects.equals(this.tunnelId, other.tunnelId)
+ && Objects.equals(this.tunnelName, other.tunnelName)
+ && Objects.equals(this.state, other.state)
+ && Objects.equals(this.path, other.path)
+ && Objects.equals(this.networkRes, other.networkRes);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this).add("src", src).add("dst", dst)
+ .add("type", type).add("state", state).add("groupId", groupId)
+ .add("producerTunnelId", tunnelId)
+ .add("tunnelName", tunnelName)
+ .add("path", path)
+ .add("networkResource", networkRes).toString();
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultTunnelDescription.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultTunnelDescription.java
new file mode 100644
index 0000000..505650a
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultTunnelDescription.java
@@ -0,0 +1,173 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.core.GroupId;
+import org.onosproject.net.AbstractDescription;
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.Path;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.provider.ProviderId;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Default implementation of immutable tunnel description entity.
+ */
+@Beta
+public class DefaultTunnelDescription extends AbstractDescription
+ implements TunnelDescription {
+
+ private final TunnelId tunnelId;
+ private final TunnelEndPoint src;
+ private final TunnelEndPoint dst;
+ private final Tunnel.Type type;
+ private final GroupId groupId; // represent for a group flow table
+ // which a tunnel match up
+ // tunnel producer
+ private final ProviderId producerName; // tunnel producer name
+ private final TunnelName tunnelName; // name of a tunnel
+ private final Path path;
+ private final NetworkResource networkRes;
+
+ /**
+ * Creates a tunnel description using the supplied information.
+ *
+ * @param id TunnelId
+ * @param src TunnelPoint source
+ * @param dst TunnelPoint destination
+ * @param type tunnel type
+ * @param groupId groupId
+ * @param producerName tunnel producer
+ * @param tunnelName tunnel name
+ * @param path the path of tunnel
+ * @param annotations optional key/value annotations
+ */
+ public DefaultTunnelDescription(TunnelId id, TunnelEndPoint src,
+ TunnelEndPoint dst, Tunnel.Type type,
+ GroupId groupId,
+ ProviderId producerName,
+ TunnelName tunnelName,
+ Path path,
+ SparseAnnotations... annotations) {
+ super(annotations);
+ this.tunnelId = id;
+ this.src = src;
+ this.dst = dst;
+ this.type = type;
+ this.groupId = groupId;
+ this.producerName = producerName;
+ this.tunnelName = tunnelName;
+ this.path = path;
+ this.networkRes = null;
+ }
+
+ /**
+ * Creates a tunnel description using the supplied information.
+ *
+ * @param id TunnelId
+ * @param src TunnelPoint source
+ * @param dst TunnelPoint destination
+ * @param type tunnel type
+ * @param groupId groupId
+ * @param producerName tunnel producer
+ * @param tunnelName tunnel name
+ * @param path the path of tunnel
+ * @param networkRes network resource of tunnel
+ * @param annotations optional key/value annotations
+ */
+ public DefaultTunnelDescription(TunnelId id, TunnelEndPoint src,
+ TunnelEndPoint dst, Tunnel.Type type,
+ GroupId groupId,
+ ProviderId producerName,
+ TunnelName tunnelName,
+ Path path,
+ NetworkResource networkRes,
+ SparseAnnotations... annotations) {
+ super(annotations);
+ this.tunnelId = id;
+ this.src = src;
+ this.dst = dst;
+ this.type = type;
+ this.groupId = groupId;
+ this.producerName = producerName;
+ this.tunnelName = tunnelName;
+ this.path = path;
+ this.networkRes = networkRes;
+ }
+
+ @Override
+ public TunnelId id() {
+ return tunnelId;
+ }
+
+ @Override
+ public TunnelEndPoint src() {
+ return src;
+ }
+
+ @Override
+ public TunnelEndPoint dst() {
+ return dst;
+ }
+
+ @Override
+ public Tunnel.Type type() {
+ return type;
+ }
+
+ @Override
+ public GroupId groupId() {
+ return groupId;
+ }
+
+ @Override
+ public ProviderId producerName() {
+ return producerName;
+ }
+
+ @Override
+ public TunnelName tunnelName() {
+ return tunnelName;
+ }
+
+
+ @Override
+ public Path path() {
+ return path;
+ }
+
+ @Override
+ public NetworkResource resource() {
+ return networkRes;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("tunnelId", id())
+ .add("src", src())
+ .add("dst", dst())
+ .add("type", type())
+ .add("tunnelName", tunnelName())
+ .add("producerName", producerName())
+ .add("groupId", groupId())
+ .add("path", path)
+ .add("resource", networkRes)
+ .toString();
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultTunnelStatistics.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultTunnelStatistics.java
new file mode 100644
index 0000000..07a8540
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DefaultTunnelStatistics.java
@@ -0,0 +1,169 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+
+import java.time.Duration;
+import java.util.List;
+
+/**
+ * Default implementation of immutable tunnel statistics.
+ */
+@Beta
+public final class DefaultTunnelStatistics implements TunnelStatistics {
+ private final TunnelId tunnelId;
+ private final double bwUtilization;
+ private final double packetLossRatio;
+ private final Duration flowDelay;
+ private final List<String> alarms;
+
+ private DefaultTunnelStatistics(TunnelId tunnelId,
+ double bwUtilization,
+ double packetLossRatio,
+ Duration flowDelay,
+ List<String> alarms) {
+ this.tunnelId = tunnelId;
+ this.bwUtilization = bwUtilization;
+ this.packetLossRatio = packetLossRatio;
+ this.flowDelay = flowDelay;
+ this.alarms = alarms;
+ }
+
+ private DefaultTunnelStatistics() {
+ this.tunnelId = null;
+ this.bwUtilization = 0;
+ this.packetLossRatio = 0;
+ this.flowDelay = null;
+ this.alarms = null;
+ }
+
+
+ @Override
+ public TunnelId id() {
+ return this.tunnelId;
+ }
+
+ @Override
+ public double bandwidthUtilization() {
+ return this.bwUtilization;
+ }
+
+ @Override
+ public double packetLossRate() {
+ return this.packetLossRatio;
+ }
+
+ @Override
+ public Duration flowDelay() {
+ return this.flowDelay;
+ }
+
+
+ @Override
+ public List<String> alarms() {
+ return this.alarms;
+ }
+
+ /**
+ * Builder for tunnelStatistics.
+ */
+ public static final class Builder {
+ TunnelId tunnelId;
+ double bwUtilization;
+ double packetLossRatio;
+ Duration flowDelay;
+ List<String> alarms;
+
+ public Builder() {
+
+ }
+
+ /**
+ * Set tunnel id.
+ *
+ * @param tunnelId tunnel id
+ * @return builder object
+ */
+ public Builder setTunnelId(TunnelId tunnelId) {
+ this.tunnelId = tunnelId;
+
+ return this;
+ }
+
+ /**
+ * set bandwidth utilization.
+ *
+ * @param bwUtilization bandwidth utilization
+ * @return builder object
+ */
+ public Builder setBwUtilization(double bwUtilization) {
+ this.bwUtilization = bwUtilization;
+
+ return this;
+ }
+
+ /**
+ * Set packet loss ratio.
+ *
+ * @param packetLossRatio packet loss ratio
+ * @return builder object
+ */
+ public Builder setPacketLossRatio(double packetLossRatio) {
+ this.packetLossRatio = packetLossRatio;
+
+ return this;
+ }
+
+ /**
+ * Set flow delay.
+ *
+ * @param flowDelay flow delay
+ * @return builder object
+ */
+ public Builder setFlowDelay(Duration flowDelay) {
+ this.flowDelay = flowDelay;
+
+ return this;
+ }
+
+ /**
+ * Set alarms.
+ *
+ * @param alarms alarms of a tunnel
+ * @return builder object
+ */
+ public Builder setAlarms(List<String> alarms) {
+ this.alarms = alarms;
+
+ return this;
+ }
+
+ /**
+ * Creates a TunnelStatistics object.
+ *
+ * @return DefaultTunnelStatistics
+ */
+ public DefaultTunnelStatistics build() {
+ return new DefaultTunnelStatistics(tunnelId,
+ bwUtilization,
+ packetLossRatio,
+ flowDelay,
+ alarms);
+ }
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DomainTunnelId.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DomainTunnelId.java
new file mode 100644
index 0000000..77e14fb
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/DomainTunnelId.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.tunnel;
+
+import org.onlab.util.Identifier;
+
+/**
+ * A wrapper class for a long used to identify domain level tunnels.
+ */
+public final class DomainTunnelId extends Identifier<Long> {
+
+ /**
+ * Creates a tunnel identifier from the specified tunnel.
+ *
+ * @param value long value
+ * @return domain tunnel identifier
+ */
+ public static DomainTunnelId valueOf(long value) {
+ return new DomainTunnelId(value);
+ }
+
+ /**
+ * Creates a tunnel identifier from the specified tunnel.
+ *
+ * @param value long value as a string
+ * @return domain tunnel identifier
+ */
+ public static DomainTunnelId valueOf(String value) {
+ return new DomainTunnelId(Long.parseLong(value));
+ }
+
+ /**
+ * Constructor for serializer.
+ */
+ protected DomainTunnelId() {
+ super(0L);
+ }
+
+ /**
+ * Constructs the Domain ID corresponding to a given long value.
+ *
+ * @param value the underlying value of this domain ID
+ */
+ public DomainTunnelId(long value) {
+ super(value);
+ }
+
+ @Override
+ public String toString() {
+ return "0x" + Long.toHexString(identifier);
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/IpTunnelEndPoint.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/IpTunnelEndPoint.java
new file mode 100644
index 0000000..c9f8ddf
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/IpTunnelEndPoint.java
@@ -0,0 +1,80 @@
+/*
+ * 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.tunnel;
+
+import java.util.Objects;
+
+import com.google.common.annotations.Beta;
+import org.onlab.packet.IpAddress;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represent for a tunnel point using ip address.
+ */
+@Beta
+public final class IpTunnelEndPoint implements TunnelEndPoint {
+
+ private final IpAddress ip;
+
+ /**
+ * Public construction is prohibited.
+ * @param ip ip address
+ */
+ private IpTunnelEndPoint(IpAddress ip) {
+ this.ip = ip;
+ }
+
+ /**
+ * Create a IP tunnel end point.
+ * @param ip IP address
+ * @return IpTunnelEndPoint
+ */
+ public static IpTunnelEndPoint ipTunnelPoint(IpAddress ip) {
+ return new IpTunnelEndPoint(ip);
+ }
+
+ /**
+ * Returns IP address.
+ * @return IP address
+ */
+ public IpAddress ip() {
+ return ip;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(ip);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof IpTunnelEndPoint) {
+ final IpTunnelEndPoint other = (IpTunnelEndPoint) obj;
+ return Objects.equals(this.ip, other.ip);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).add("ip", ip).toString();
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/LabelStack.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/LabelStack.java
new file mode 100644
index 0000000..7976218
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/LabelStack.java
@@ -0,0 +1,34 @@
+/*
+ * 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.tunnel;
+
+import org.onosproject.incubator.net.resource.label.LabelResourceId;
+import org.onosproject.net.NetworkResource;
+
+import java.util.List;
+
+/**
+ * Representation of a label stack in a network which represents the network path.
+ */
+public interface LabelStack extends NetworkResource {
+
+ /**
+ * Returns sequence of label resources comprising the path.
+ *
+ * @return list of links
+ */
+ List<LabelResourceId> labelResources();
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/NetworkTunnelId.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/NetworkTunnelId.java
new file mode 100644
index 0000000..868804e
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/NetworkTunnelId.java
@@ -0,0 +1,61 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
+
+/**
+ * Representation of a Network Tunnel Id.
+ */
+@Beta
+public final class NetworkTunnelId extends Identifier<Long> {
+ /**
+ * Creates an tunnel identifier from the specified tunnel.
+ *
+ * @param value long value
+ * @return tunnel identifier
+ */
+ public static NetworkTunnelId valueOf(long value) {
+ return new NetworkTunnelId(value);
+ }
+
+ public static NetworkTunnelId valueOf(String value) {
+ return new NetworkTunnelId(Long.parseLong(value));
+ }
+
+ /**
+ * Constructor for serializer.
+ */
+ NetworkTunnelId() {
+ super(0L);
+ }
+
+ /**
+ * Constructs the ID corresponding to a given long value.
+ *
+ * @param value the underlying value of this ID
+ */
+ public NetworkTunnelId(long value) {
+ super(value);
+ }
+
+ @Override
+ public String toString() {
+ return "0x" + Long.toHexString(identifier);
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalLogicId.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalLogicId.java
new file mode 100644
index 0000000..86e9321
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalLogicId.java
@@ -0,0 +1,59 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+import com.google.common.primitives.UnsignedLongs;
+import org.onlab.util.Identifier;
+
+/**
+ * Representation of a label Id, a logical port identifier.
+ */
+@Beta
+public final class OpticalLogicId extends Identifier<Long> {
+
+ /**
+ * Constructor, public creation is prohibited.
+ */
+ private OpticalLogicId(long id) {
+ super(id);
+ }
+
+ /**
+ * Returns the LabelId representing the specified long value.
+ *
+ * @param id identifier as long value
+ * @return LabelId
+ */
+ public static OpticalLogicId logicId(long id) {
+ return new OpticalLogicId(id);
+ }
+
+ /**
+ * Returns the LabelId representing the specified string value.
+ *
+ * @param string identifier as string value
+ * @return LabelId
+ */
+ public static OpticalLogicId logicId(String string) {
+ return new OpticalLogicId(UnsignedLongs.decode(string));
+ }
+
+ public long toLong() {
+ return identifier;
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalTunnelEndPoint.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalTunnelEndPoint.java
new file mode 100644
index 0000000..0dccd35
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalTunnelEndPoint.java
@@ -0,0 +1,90 @@
+/*
+ * 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.tunnel;
+
+import java.util.Optional;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.Annotated;
+import org.onosproject.net.ElementId;
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.Provided;
+
+/**
+ * Generic representation of a logical port entity in a consistent way,
+ * it is used to identify e.g., ODUk timeSlot, WDM lambda, etc.
+ * It supports nested case.
+ */
+@Beta
+public interface OpticalTunnelEndPoint extends TunnelEndPoint, Annotated, Provided, NetworkResource {
+
+ /** Represents coarse tunnel point type classification. */
+ public enum Type {
+ /**
+ * Signifies optical data unit-based tunnel point.
+ */
+ TIMESLOT,
+
+ /**
+ * Signifies optical wavelength-based tunnel point.
+ */
+ LAMBDA
+ }
+
+ /**
+ * Returns the identifier.
+ *
+ * @return identifier
+ */
+ OpticalLogicId id();
+
+ /**
+ * Returns the parent network element to which this tunnel point belongs.
+ *
+ * @return parent network element
+ */
+ Optional<ElementId> elementId();
+
+ /**
+ * Returns the parent network port to which this tunnel point belongs, can not be be null.
+ *
+ * @return port number
+ */
+ Optional<PortNumber> portNumber();
+
+ /**
+ * Returns the parent tunnel point to which this tunnel point belongs, optional.
+ *
+ * @return parent tunnel point, if it is null, the parent is a physical port
+ */
+ Optional<OpticalTunnelEndPoint> parentPoint();
+
+ /**
+ * Indicates whether or not the port is global significant.
+ *
+ * @return true if the port is global significant
+ */
+ boolean isGlobal();
+
+ /**
+ * Returns the tunnel point type.
+ *
+ * @return tunnel point type
+ */
+ Type type();
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/Tunnel.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/Tunnel.java
new file mode 100644
index 0000000..603f27a
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/Tunnel.java
@@ -0,0 +1,170 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.core.GroupId;
+import org.onosproject.net.Annotated;
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.Path;
+import org.onosproject.net.Provided;
+
+/**
+ * Abstraction of a generalized Tunnel entity (bandwidth pipe) for either L3/L2
+ * networks or L1/L0 networks, representation of e.g., VLAN, GRE tunnel, MPLS
+ * LSP, L1 ODUk connection, WDM OCH, etc.. Each Tunnel is associated with at
+ * least two tunnel end point objects that model the logical ports essentially.
+ * Note that it supports nested case.
+ */
+@Beta
+public interface Tunnel extends Annotated, Provided, NetworkResource {
+
+ /**
+ * Tunnel technology type.
+ */
+ enum Type {
+ /**
+ * Signifies that this is a MPLS tunnel.
+ */
+ MPLS,
+ /**
+ * Signifies that this is a L2 tunnel.
+ */
+ VLAN,
+ /**
+ * Signifies that this is a DC L2 extension tunnel.
+ */
+ VXLAN,
+ /**
+ * Signifies that this is a L3 tunnel.
+ */
+ GRE,
+ /**
+ * Signifies that this is a L1 OTN tunnel.
+ */
+ ODUK,
+ /**
+ * Signifies that this is a L0 OCH tunnel.
+ */
+ OCH
+ }
+
+ /**
+ * Representation of the tunnel state.
+ */
+ public enum State {
+ /**
+ * Signifies that a tunnel is currently in a initialized state.
+ */
+ INIT,
+ /**
+ * Signifies that a tunnel is currently established but no traffic.
+ */
+ ESTABLISHED,
+ /**
+ * Signifies that a tunnel is currently active. This state means that
+ * this tunnel is available. It can be borrowed by consumer.
+ */
+ ACTIVE,
+ /**
+ * Signifies that a tunnel is currently out of service.
+ */
+ FAILED,
+ /**
+ * Signifies that a tunnel is currently inactive. This state means that
+ * this tunnel can not be borrowed by consumer.
+ */
+ INACTIVE,
+
+ /**
+ * Signifies that the tunnel's state is unreliable and should be setup again.
+ */
+ UNSTABLE,
+
+ /**
+ * Signifies that a tunnel is being established.
+ */
+ ESTABLISHING,
+
+ /**
+ * Signifies that a tunnel is being removed.
+ */
+ REMOVING
+ }
+
+ /**
+ * Returns the tunnel state.
+ *
+ * @return tunnel state
+ */
+ State state();
+
+ /**
+ * the origin of a tunnel.
+ *
+ * @return the origin of a tunnel
+ */
+ TunnelEndPoint src();
+
+ /**
+ * the terminal of a tunnel.
+ *
+ * @return the terminal of a tunnel
+ */
+ TunnelEndPoint dst();
+
+ /**
+ * Returns the tunnel type.
+ *
+ * @return tunnel type
+ */
+ Type type();
+
+ /**
+ * Returns group flow table id which a tunnel match up.
+ *
+ * @return OpenFlowGroupId
+ */
+ GroupId groupId();
+
+ /**
+ * Returns tunnel identify generated by ONOS as primary key.
+ *
+ * @return TunnelId
+ */
+ TunnelId tunnelId();
+
+ /**
+ * Return the name of a tunnel.
+ *
+ * @return Tunnel Name
+ */
+ TunnelName tunnelName();
+
+ /**
+ * Network resource backing the tunnel, e.g. lambda, VLAN id, MPLS tag.
+ *
+ * @return backing resource
+ */
+ NetworkResource resource();
+
+ /**
+ * Returns the path of the tunnel.
+ *
+ * @return the path of the tunnel
+ */
+ Path path();
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelAdminService.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelAdminService.java
new file mode 100644
index 0000000..12246a5
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelAdminService.java
@@ -0,0 +1,72 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.Path;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * Service for administering the inventory of provisioned tunnels.
+ */
+@Beta
+public interface TunnelAdminService {
+
+ /**
+ * Removes the provisioned tunnel.
+ *
+ * @param tunnelId tunnel ID
+ */
+ void removeTunnel(TunnelId tunnelId);
+
+ /**
+ * Removes the provisioned tunnel leading to and from the
+ * specified labels.
+ *
+ * @param src source label
+ * @param dst destination label
+ * @param producerName producer name
+ */
+ void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, ProviderId producerName);
+
+ /**
+ * Removes all provisioned tunnels leading to and from the
+ * specified connection point.
+ *
+ * @param src source connection point
+ * @param dst destination connection point
+ * @param type tunnel type
+ * @param producerName producer name
+ */
+ void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Tunnel.Type type, ProviderId producerName);
+
+ /**
+ * Invokes the core to update a tunnel based on specified tunnel parameters.
+ *
+ * @param tunnel Tunnel
+ * @param path explicit route (path changed) or null (path not changed) for the tunnel
+ */
+ void updateTunnel(Tunnel tunnel, Path path);
+
+ /**
+ * Updates the state of a tunnel.
+ *
+ * @param tunnel tunnel to be changed
+ * @param state new state of the tunnel
+ */
+ void updateTunnelState(Tunnel tunnel, Tunnel.State state);
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelDescription.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelDescription.java
new file mode 100644
index 0000000..0444c38
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelDescription.java
@@ -0,0 +1,95 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.core.GroupId;
+import org.onosproject.incubator.net.tunnel.Tunnel.Type;
+import org.onosproject.net.Annotated;
+import org.onosproject.net.Description;
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.Path;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * Describes a tunnel.
+ */
+@Beta
+public interface TunnelDescription extends Description, Annotated {
+
+ /**
+ * Returns the tunnel id.
+ *
+ * @return tunnelId
+ */
+ TunnelId id();
+
+ /**
+ * Returns the connection point source.
+ *
+ * @return tunnel source ConnectionPoint
+ */
+ TunnelEndPoint src();
+
+ /**
+ * Returns the connection point destination.
+ *
+ * @return tunnel destination
+ */
+ TunnelEndPoint dst();
+
+ /**
+ * Returns the tunnel type.
+ *
+ * @return tunnel type
+ */
+ Type type();
+
+ /**
+ * Returns group flow table id which a tunnel match up.
+ *
+ * @return OpenFlowGroupId
+ */
+ GroupId groupId();
+
+ /**
+ * Returns tunnel producer name.
+ *
+ * @return producer name
+ */
+ ProviderId producerName();
+
+ /**
+ * Return the name of a tunnel.
+ *
+ * @return Tunnel Name
+ */
+ TunnelName tunnelName();
+
+ /**
+ * Returns the path of the tunnel.
+ *
+ * @return the path of the tunnel
+ */
+ Path path();
+
+ /**
+ * Returns the network resource backing the tunnel, e.g. lambda, VLAN id, MPLS tag, label stack.
+ *
+ * @return backing resource
+ */
+ NetworkResource resource();
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelEndPoint.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelEndPoint.java
new file mode 100644
index 0000000..4d6fe68
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelEndPoint.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.tunnel;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * Represents for source end point or destination end point of a tunnel. Maybe a tunnel
+ * based on ConnectPoint, IpAddress, MacAddress and so on is built.
+ */
+@Beta
+public interface TunnelEndPoint {
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelEndPointFormatter.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelEndPointFormatter.java
new file mode 100644
index 0000000..ac1cd07
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelEndPointFormatter.java
@@ -0,0 +1,61 @@
+/*
+ * 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.tunnel;
+
+
+import com.google.common.annotations.Beta;
+import org.onosproject.ui.table.CellFormatter;
+import org.onosproject.ui.table.cell.AbstractCellFormatter;
+
+import java.util.Optional;
+
+/**
+ * Formats an optical tunnel endpoint as "(type)/(element-id)/(port)".
+ * Formats an IP tunnel endpoint as "ip".
+ */
+@Beta
+public final class TunnelEndPointFormatter extends AbstractCellFormatter {
+ //non-instantiable
+ private TunnelEndPointFormatter() {
+ }
+
+ private String safeOptional(Optional<?> optional) {
+ return optional.isPresent() ? optional.get().toString() : QUERY;
+ }
+
+ @Override
+ protected String nonNullFormat(Object value) {
+
+ if (value instanceof DefaultOpticalTunnelEndPoint) {
+ DefaultOpticalTunnelEndPoint ep =
+ (DefaultOpticalTunnelEndPoint) value;
+
+ String e = safeOptional(ep.elementId());
+ String p = safeOptional(ep.portNumber());
+ return ep.type() + SLASH + e + SLASH + p;
+
+ } else if (value instanceof IpTunnelEndPoint) {
+ IpTunnelEndPoint cp = (IpTunnelEndPoint) value;
+ return cp.ip().toString();
+ }
+ return EMPTY;
+ }
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellFormatter INSTANCE = new TunnelEndPointFormatter();
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelEvent.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelEvent.java
new file mode 100644
index 0000000..5d97ba8
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelEvent.java
@@ -0,0 +1,70 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Describes tunnel events.
+ */
+@Beta
+public final class TunnelEvent extends AbstractEvent<TunnelEvent.Type, Tunnel> {
+
+ /**
+ * Type of tunnel events.
+ */
+ public enum Type {
+ /**
+ * Signifies that a new tunnel has been added.
+ */
+ TUNNEL_ADDED,
+
+ /**
+ * Signifies that a tunnel has been updated or changed state.
+ */
+ TUNNEL_UPDATED,
+
+ /**
+ * Signifies that a tunnel has been removed.
+ */
+ TUNNEL_REMOVED
+ }
+
+ /**
+ * Creates an event of a given type and for the specified tunnel.
+ *
+ * @param type tunnel event type
+ * @param tunnel event tunnel subject
+ */
+ public TunnelEvent(Type type, Tunnel tunnel) {
+ super(type, tunnel);
+ }
+
+ /**
+ * Creates an event of a given type and for the specified link and
+ * the current time.
+ *
+ * @param type tunnel event type
+ * @param tunnel event tunnel subject
+ * @param time occurrence time
+ */
+ public TunnelEvent(Type type, Tunnel tunnel, long time) {
+ super(type, tunnel, time);
+ }
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelId.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelId.java
new file mode 100644
index 0000000..a28b53c
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelId.java
@@ -0,0 +1,57 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
+
+/**
+ * Representation of a Tunnel Id.
+ */
+@Beta
+public final class TunnelId extends Identifier<String> {
+ /**
+ * Creates an tunnel identifier from the specified tunnel.
+ *
+ * @param value string value
+ * @return tunnel identifier
+ */
+ public static TunnelId valueOf(String value) {
+ return new TunnelId(value);
+ }
+
+ /**
+ * Constructor for serializer.
+ */
+ TunnelId() {
+ super("0");
+ }
+
+ /**
+ * Constructs the ID corresponding to a given string value.
+ *
+ * @param value the underlying value of this ID
+ */
+ TunnelId(String value) {
+ super(value);
+ }
+
+ @Override
+ public String toString() {
+ return id();
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelListener.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelListener.java
new file mode 100644
index 0000000..3394dfd
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelListener.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.tunnel;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.EventListener;
+
+/**
+ * Entity capable of receiving tunnel related events.
+ */
+@Beta
+public interface TunnelListener extends EventListener<TunnelEvent> {
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelName.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelName.java
new file mode 100644
index 0000000..f15d47b
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelName.java
@@ -0,0 +1,79 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+
+import java.util.Objects;
+
+/**
+ * Represents for a unique tunnel name. TunnelId is generated by ONOS while
+ * TunnelName is given by producer. The consumer can borrow tunnels with
+ * TunnelId or TunnelName.
+ */
+@Beta
+public final class TunnelName {
+ private final String str;
+
+ // Default constructor for serialization
+ private TunnelName(String tunnelName) {
+ this.str = tunnelName;
+ }
+
+
+ /**
+ * Creates a tunnel name using the supplied URI string.
+ *
+ * @param tunnelName tunnel name string
+ * @return tunnel name object
+ */
+ public static TunnelName tunnelName(String tunnelName) {
+ return new TunnelName(tunnelName);
+ }
+
+ /**
+ * The string of tunnel name.
+ *
+ * @return the string of tunnel name
+ */
+ public String value() {
+ return str;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(str);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof TunnelName) {
+ final TunnelName that = (TunnelName) obj;
+ return this.getClass() == that.getClass()
+ && Objects.equals(this.str, that.str);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return str;
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelProvider.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelProvider.java
new file mode 100644
index 0000000..05d2783
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelProvider.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.tunnel;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.ElementId;
+import org.onosproject.net.Path;
+import org.onosproject.net.provider.Provider;
+
+/**
+ * Abstraction of an entity providing tunnel setup/release services to the core.
+ */
+@Beta
+public interface TunnelProvider extends Provider {
+
+ /**
+ * Instructs the provider to setup a tunnel. It's used by consumers.
+ *
+ * @param tunnel Tunnel
+ * @param path explicit route or null for the tunnel
+ */
+ void setupTunnel(Tunnel tunnel, Path path);
+
+ /**
+ * Instructs the provider to setup a tunnel given the respective device.
+ * It's used by consumers.
+ *
+ * @param srcElement device
+ * @param tunnel Tunnel
+ * @param path explicit route (not null) for the tunnel
+ */
+ void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path);
+
+ /**
+ * Instructs the provider to release a tunnel. It's used by consumers.
+ *
+ * @param tunnel Tunnel
+ */
+ void releaseTunnel(Tunnel tunnel);
+
+ /**
+ * Instructs the provider to release a tunnel given the respective device.
+ * It's used by consumers.
+ *
+ * @param srcElement device
+ * @param tunnel Tunnel
+ */
+ void releaseTunnel(ElementId srcElement, Tunnel tunnel);
+
+ /**
+ * Instructs the provider to update a tunnel. It's used by consumers. Maybe
+ * some consumers enable to update a tunnel.
+ *
+ * @param tunnel Tunnel
+ * @param path explicit route (path changed) or null (path not changed) for
+ * the tunnel
+ */
+ void updateTunnel(Tunnel tunnel, Path path);
+
+ /**
+ * Instructs the provider to update a tunnel given the respective device.
+ * It's used by consumers. Maybe some consumers enable to update a tunnel.
+ *
+ * @param srcElement device
+ * @param tunnel Tunnel
+ * @param path explicit route (path changed) or null (path not changed) for
+ * the tunnel
+ */
+ void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path);
+
+ /**
+ * Signals that the provider has added a tunnel. It's used by producers.
+ *
+ * @param tunnel tunnel information
+ * @return tunnel identity
+ */
+ TunnelId tunnelAdded(TunnelDescription tunnel);
+
+ /**
+ * Signals that the provider has removed a tunnel. It's used by producers.
+ *
+ * @param tunnel tunnel information
+ */
+ void tunnelRemoved(TunnelDescription tunnel);
+
+ /**
+ * Signals that the a tunnel was changed (e.g., sensing changes of
+ * tunnel).It's used by producers.
+ *
+ * @param tunnel tunnel information
+ */
+ void tunnelUpdated(TunnelDescription tunnel);
+
+ /**
+ * Signals that the a tunnel was queried.
+ * It's used by producers.
+ * @param tunnelId tunnel identity
+ * @return tunnel entity
+ */
+ Tunnel tunnelQueryById(TunnelId tunnelId);
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelProviderRegistry.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelProviderRegistry.java
new file mode 100644
index 0000000..740e257
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelProviderRegistry.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.tunnel;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.provider.ProviderRegistry;
+
+/**
+ * Abstraction of an tunnel provider registry.
+ */
+@Beta
+public interface TunnelProviderRegistry
+ extends ProviderRegistry<TunnelProvider, TunnelProviderService> {
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelProviderService.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelProviderService.java
new file mode 100644
index 0000000..3dcdd29
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelProviderService.java
@@ -0,0 +1,78 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+
+import org.onosproject.incubator.net.tunnel.Tunnel.State;
+import org.onosproject.net.provider.ProviderService;
+
+/**
+ * APIs for tunnel provider to notify the tunnel subSystem.
+ */
+@Beta
+public interface TunnelProviderService extends ProviderService<TunnelProvider> {
+
+ /**
+ * Signals that the provider has added a tunnel.
+ *
+ * @param tunnel tunnel information
+ * @return tunnel identity
+ */
+ TunnelId tunnelAdded(TunnelDescription tunnel);
+
+ /**
+ * Signals that the provider has added a tunnel with a status which may not
+ * be default, hence is provided as an input.
+ *
+ * @param tunnel tunnel information
+ * @param state tunnel working status
+ * @return tunnel identity
+ */
+ TunnelId tunnelAdded(TunnelDescription tunnel, State state);
+
+ /**
+ * Signals that the provider has removed a tunnel.
+ *
+ * @param tunnel tunnel information
+ */
+ void tunnelRemoved(TunnelDescription tunnel);
+
+ /**
+ * Signals that the a tunnel was changed (e.g., sensing changes of tunnel).
+ *
+ * @param tunnel tunnel information
+ */
+ void tunnelUpdated(TunnelDescription tunnel);
+
+ /**
+ * Signals that the tunnel was changed with tunnel status change.
+ *
+ * @param tunnel tunnel information
+ * @param state tunnel working status
+ */
+ void tunnelUpdated(TunnelDescription tunnel, State state);
+
+ /**
+ * Signals that the a tunnel was queried.
+ *
+ * @param tunnelId tunnel identity
+ * @return tunnel entity
+ */
+ Tunnel tunnelQueryById(TunnelId tunnelId);
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelService.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelService.java
new file mode 100644
index 0000000..cee6310
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelService.java
@@ -0,0 +1,224 @@
+/*
+ * 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.tunnel;
+
+import java.util.Collection;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.event.ListenerService;
+import org.onosproject.incubator.net.tunnel.Tunnel.Type;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.ElementId;
+import org.onosproject.net.Path;
+
+/**
+ * Service for interacting with the inventory of tunnels.
+ */
+@Beta
+public interface TunnelService
+ extends ListenerService<TunnelEvent, TunnelListener> {
+
+ /**
+ * 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 consumerId a tunnel consumer
+ * @param tunnelId tunnel identify generated by onos
+ * @param annotations Annotations
+ * @return Tunnel subscribed tunnel
+ */
+ Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId,
+ Annotations... annotations);
+
+ /**
+ * 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 consumerId a tunnel consumer
+ * @param tunnelName tunnel name
+ * @param annotations Annotations
+ * @return collection of subscribed Tunnels
+ */
+ Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelName tunnelName,
+ Annotations... annotations);
+
+ /**
+ * 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.
+ *
+ * @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
+ */
+ Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src,
+ TunnelEndPoint dst, Annotations... annotations);
+
+ /**
+ * 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 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
+ */
+ Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src,
+ TunnelEndPoint dst, Type type,
+ Annotations... annotations);
+
+ /**
+ * Creates a tunnel with given path and default initial state. The state changes
+ * in due course of time based on changes happening in the network.
+ *
+ * @param producerId a tunnel producer
+ * @param srcElementId element id of the source
+ * @param tunnel to be created
+ * @param path path of the tunnel
+ * @return generated tunnel identity
+ */
+ TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path);
+
+ /**
+ * Triggers removal of specified tunnel.
+ *
+ * @param producerId a tunnel producer
+ * @param tunnelId identity for the tunnel to be triggered for removal
+ * @return success or failure
+ */
+ boolean downTunnel(ApplicationId producerId, TunnelId tunnelId);
+
+ /**
+ * Returns back a specific tunnel to store.
+ *
+ * @param consumerId a tunnel consumer
+ * @param tunnelId tunnel identify generated by ONOS
+ * @param annotations Annotations
+ * @return success or fail
+ */
+ 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 Collection of tunnels
+ */
+ Collection<Tunnel> queryAllTunnels();
+
+ /**
+ * Returns all tunnels.
+ *
+ * @return all tunnels
+ */
+ int tunnelCount();
+
+ /**
+ * Returns the collection of tunnels applied on the specified device.
+ *
+ * @param deviceId device identifier
+ * @return collection of tunnels
+ */
+ Iterable<Tunnel> getTunnels(DeviceId deviceId);
+
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelStatistics.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelStatistics.java
new file mode 100644
index 0000000..d260d26
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelStatistics.java
@@ -0,0 +1,64 @@
+/*
+ * 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.tunnel;
+
+import com.google.common.annotations.Beta;
+
+import java.time.Duration;
+import java.util.List;
+
+/**
+ * Statistics of a tunnel.
+ */
+@Beta
+public interface TunnelStatistics {
+
+ /**
+ * Returns the tunnel id.
+ *
+ * @return tunnelId id of tunnel
+ */
+ TunnelId id();
+
+ /**
+ * Returns the bandwidth utilization of a tunnel.
+ *
+ * @return bandwidth utilization
+ */
+ double bandwidthUtilization();
+
+ /**
+ * Returns the packet loss ratio of a tunnel.
+ *
+ * @return tunnel packet loss ratio
+ */
+ double packetLossRate();
+
+ /**
+ * Returns the end-to-end traffic flow delay of a tunnel.
+ *
+ * @return tunnel flow delay
+ */
+ Duration flowDelay();
+
+ /**
+ * Returns the alarms on a tunnel.
+ *
+ * @return tunnel alarms
+ */
+ List<String> alarms();
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelStore.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelStore.java
new file mode 100644
index 0000000..b4f4a8c
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelStore.java
@@ -0,0 +1,239 @@
+/*
+ * 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.tunnel;
+
+import java.util.Collection;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.incubator.net.tunnel.Tunnel.State;
+import org.onosproject.incubator.net.tunnel.Tunnel.Type;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.store.Store;
+
+/**
+ * Manages inventory of tunnel; not intended for direct use.
+ */
+@Beta
+public interface TunnelStore extends Store<TunnelEvent, TunnelStoreDelegate> {
+ /**
+ * Creates or updates a tunnel.
+ *
+ * @param tunnel tunnel
+ * @return tunnel identity
+ */
+ TunnelId createOrUpdateTunnel(Tunnel tunnel);
+
+ /**
+ * Creates a tunnel or updates a tunnel with the new state given in input.
+ *
+ * @param tunnel tunnel
+ * @param state tunnel state
+ * @return tunnel identity
+ */
+ TunnelId createOrUpdateTunnel(Tunnel tunnel, State state);
+
+ /**
+ * Deletes a tunnel by a specific tunnel identifier.
+ *
+ * @param tunnelId tunnel unique identifier generated by ONOS
+ */
+ void deleteTunnel(TunnelId tunnelId);
+
+ /**
+ * Deletes all tunnels between source point and destination point.
+ *
+ * @param src a source point of tunnel.
+ * @param dst a destination point of tunnel.
+ * @param producerName producerName
+ */
+ void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst,
+ ProviderId producerName);
+
+ /**
+ * Deletes all specific type tunnels between source point and destination
+ * point.
+ *
+ * @param src a source point of tunnel.
+ * @param dst a destination point of tunnel.
+ * @param type tunnel type
+ * @param producerName producerName
+ */
+ void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst,
+ Tunnel.Type type, ProviderId producerName);
+
+ /**
+ * 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 consumerId a tunnel consumer
+ * @param tunnelId tunnel identify generated by onos
+ * @param annotations parameter
+ * @return Tunnel subscribed tunnel
+ */
+ Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId,
+ Annotations... annotations);
+
+ /**
+ * 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 consumerId a tunnel consumer
+ * @param tunnelName tunnel name
+ * @param annotations parameter
+ * @return collection of subscribed Tunnels
+ */
+ Collection<Tunnel> borrowTunnel(ApplicationId consumerId,
+ TunnelName tunnelName,
+ Annotations... annotations);
+
+ /**
+ * 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 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
+ */
+ Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src,
+ TunnelEndPoint dst, Annotations... annotations);
+
+ /**
+ * 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 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
+ */
+ Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src,
+ TunnelEndPoint dst, Type type,
+ Annotations... annotations);
+
+ /**
+ * Returns back a specific tunnel to store.
+ *
+ * @param consumerId a tunnel consumer
+ * @param tunnelId tunnel identify generated by ONOS
+ * @param annotations Annotations
+ * @return success or fail
+ */
+ 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 Collection of tunnels
+ */
+ Collection<Tunnel> queryAllTunnels();
+
+ /**
+ * Returns all tunnels.
+ * @return all tunnels
+ */
+ int tunnelCount();
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelStoreDelegate.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelStoreDelegate.java
new file mode 100644
index 0000000..e94cfaa
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelStoreDelegate.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.tunnel;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * Tunnel store delegate abstraction.
+ */
+@Beta
+public interface TunnelStoreDelegate extends StoreDelegate<TunnelEvent> {
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelSubscription.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelSubscription.java
new file mode 100644
index 0000000..b0e5384
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/TunnelSubscription.java
@@ -0,0 +1,156 @@
+/*
+ * 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.tunnel;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Objects;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.AbstractAnnotated;
+import org.onosproject.net.Annotations;
+import org.onosproject.incubator.net.tunnel.Tunnel.Type;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents for a order that consumer subscribe tunnel. ONOS maintains request
+ * information, it means ONOS knows how much resource echo consumer uses in the
+ * ONOS. Although there is no a tunnel that consumer want to use, when producer
+ * creates a new tunnel, ONOS will notify the consumers that want to use it.
+ */
+@Beta
+public final class TunnelSubscription extends AbstractAnnotated {
+ private final ApplicationId consumerId;
+ private final TunnelEndPoint src;
+ private final TunnelEndPoint dst;
+ private final Type type;
+ private final TunnelId tunnelId;
+ private final TunnelName tunnelName;
+
+ /**
+ * Creates a TunnelSubscription.
+ *
+ * @param consumerId consumer identity
+ * @param src source tunnel end point of tunnel
+ * @param dst destination tunnel end point of tunnel
+ * @param tunnelId tunnel identity
+ * @param type tunnel type
+ * @param tunnelName the name of a tunnel
+ * @param annotations parameter
+ */
+ public TunnelSubscription(ApplicationId consumerId, TunnelEndPoint src,
+ TunnelEndPoint dst, TunnelId tunnelId, Type type,
+ TunnelName tunnelName, Annotations... annotations) {
+ super(annotations);
+ checkNotNull(consumerId, "consumerId cannot be null");
+ this.consumerId = consumerId;
+ this.src = src;
+ this.dst = dst;
+ this.type = type;
+ this.tunnelId = tunnelId;
+ this.tunnelName = tunnelName;
+ }
+
+ /**
+ * Returns consumer identity.
+ *
+ * @return consumerId consumer id
+ */
+ public ApplicationId consumerId() {
+ return consumerId;
+ }
+
+ /**
+ * Returns source point of tunnel.
+ *
+ * @return source point
+ */
+ public TunnelEndPoint src() {
+ return src;
+ }
+
+ /**
+ * Returns destination point of tunnel.
+ *
+ * @return destination point
+ */
+ public TunnelEndPoint dst() {
+ return dst;
+ }
+
+ /**
+ * Returns tunnel type.
+ *
+ * @return tunnel type
+ */
+ public Type type() {
+ return type;
+ }
+
+ /**
+ * Returns tunnel identity.
+ *
+ * @return tunnel id
+ */
+ public TunnelId tunnelId() {
+ return tunnelId;
+ }
+
+ /**
+ * Returns tunnel name.
+ *
+ * @return tunnel name
+ */
+ public TunnelName tunnelName() {
+ return tunnelName;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(consumerId, src, dst, type, tunnelId, tunnelName);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof TunnelSubscription) {
+ final TunnelSubscription other = (TunnelSubscription) obj;
+ return Objects.equals(this.src, other.src)
+ && Objects.equals(this.dst, other.dst)
+ && Objects.equals(this.consumerId, other.consumerId)
+ && Objects.equals(this.type, other.type)
+ && Objects.equals(this.tunnelId, other.tunnelId)
+ && Objects.equals(this.tunnelName, other.tunnelName);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("src", src)
+ .add("dst", dst)
+ .add("consumerId", consumerId)
+ .add("type", type)
+ .add("tunnelId", tunnelId)
+ .add("tunnelName", tunnelName).toString();
+ }
+}
diff --git a/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/package-info.java b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/package-info.java
new file mode 100644
index 0000000..86e21f8
--- /dev/null
+++ b/apps/tunnel/api/src/main/java/org/onosproject/incubator/net/tunnel/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.
+ */
+
+/**
+ * Tunnel model related services and providers API definitions.
+ */
+package org.onosproject.incubator.net.tunnel;