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/app/src/main/java/org/onosproject/incubator/net/domain/impl/IntentDomainManager.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/domain/impl/IntentDomainManager.java
new file mode 100644
index 0000000..5d0270b
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/domain/impl/IntentDomainManager.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2015-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.impl;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+import org.onosproject.incubator.net.domain.IntentDomain;
+import org.onosproject.incubator.net.domain.IntentDomainEvent;
+import org.onosproject.incubator.net.domain.IntentDomainId;
+import org.onosproject.incubator.net.domain.IntentDomainListener;
+import org.onosproject.incubator.net.domain.IntentDomainProvider;
+import org.onosproject.incubator.net.domain.IntentDomainProviderRegistry;
+import org.onosproject.incubator.net.domain.IntentDomainProviderService;
+import org.onosproject.incubator.net.domain.IntentDomainService;
+import org.onosproject.incubator.net.domain.IntentPrimitive;
+import org.onosproject.incubator.net.domain.IntentResource;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.provider.AbstractListenerProviderRegistry;
+import org.onosproject.net.provider.AbstractProviderService;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
+
+/**
+ * Implementation of the intent domain service.
+ */
+@Component(immediate = true, service = {IntentDomainService.class, IntentDomainProviderRegistry.class})
+public class IntentDomainManager
+        extends AbstractListenerProviderRegistry<IntentDomainEvent, IntentDomainListener,
+                    IntentDomainProvider, IntentDomainProviderService>
+        implements IntentDomainService, IntentDomainProviderRegistry {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final ConcurrentMap<IntentDomainId, IntentDomain> domains = Maps.newConcurrentMap();
+
+    @Activate
+    protected void activate() {
+        log.info("Started");
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        log.info("Stopped");
+    }
+
+    @Override
+    public IntentDomain getDomain(IntentDomainId id) {
+        return domains.get(id);
+    }
+
+    @Override
+    public Set<IntentDomain> getDomains() {
+        return ImmutableSet.copyOf(domains.values());
+    }
+
+    @Override
+    public Set<IntentDomain> getDomains(DeviceId deviceId) {
+        return domains.values().stream()
+                .filter(domain ->
+                                domain.internalDevices().contains(deviceId) ||
+                                        domain.edgePorts().stream()
+                                                .map(ConnectPoint::deviceId)
+                                                .anyMatch(d -> d.equals(deviceId)))
+                .collect(Collectors.toSet());
+    }
+
+    @Override
+    public List<IntentResource> request(IntentDomainId domainId, IntentPrimitive primitive) {
+        IntentDomain domain = getDomain(domainId);
+        return domain.provider().request(domain, primitive);
+    }
+
+    @Override
+    public void submit(IntentDomainId domainId, IntentResource resource) {
+        getDomain(domainId).provider().apply(resource);
+    }
+
+    @Override
+    protected IntentDomainProviderService createProviderService(IntentDomainProvider provider) {
+        return new InternalDomainProviderService(provider);
+    }
+
+    private class InternalDomainProviderService
+            extends AbstractProviderService<IntentDomainProvider>
+            implements IntentDomainProviderService {
+
+        InternalDomainProviderService(IntentDomainProvider provider) {
+            super(provider);
+        }
+    }
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/domain/impl/package-info.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/domain/impl/package-info.java
new file mode 100644
index 0000000..17b9f86
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/domain/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015-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.
+ */
+
+/**
+ * Implementation of the intent domain subsystem.
+ */
+package org.onosproject.incubator.net.domain.impl;
\ No newline at end of file
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelApplyCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelApplyCommand.java
new file mode 100644
index 0000000..c5d9e8e
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelApplyCommand.java
@@ -0,0 +1,56 @@
+/*
+ * 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.cli;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.resource.label.DefaultLabelResource;
+import org.onosproject.incubator.net.resource.label.LabelResource;
+import org.onosproject.incubator.net.resource.label.LabelResourceService;
+
+@Service
+@Command(scope = "onos", name = "global-label-apply",
+      description = "Apply global labels from global resource pool")
+public class GlobalLabelApplyCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "applyNum",
+            description = "Applying number means how many labels applications want to use.",
+            required = true, multiValued = false)
+    String applyNum = null;
+
+    private static final String FMT = "deviceid=%s, labelresourceid=%s";
+
+    @Override
+    protected void doExecute() {
+        LabelResourceService lrs = get(LabelResourceService.class);
+        Collection<LabelResource> result =
+                lrs.applyFromGlobalPool(Long.parseLong(applyNum));
+        if (!result.isEmpty()) {
+            for (Iterator<LabelResource> iterator = result.iterator(); iterator
+                    .hasNext();) {
+                DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator
+                        .next();
+                print(FMT, defaultLabelResource.deviceId().toString(),
+                      defaultLabelResource.labelResourceId().toString());
+            }
+        }
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelCommand.java
new file mode 100644
index 0000000..d93bf6f
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelCommand.java
@@ -0,0 +1,44 @@
+/*
+ * 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.cli;
+
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.resource.label.LabelResourcePool;
+import org.onosproject.incubator.net.resource.label.LabelResourceService;
+
+@Service
+@Command(scope = "onos", name = "global-label-pool",
+      description = "Gets global label resource pool information.")
+public class GlobalLabelCommand extends AbstractShellCommand {
+    private static final String FMT = "deviceid=%s, beginLabel=%s,"
+            + "endLabel=%s, totalNum=%s, usedNum=%s, currentUsedMaxLabelId=%s,"
+            + "releaseLabelIds=%s";
+
+    @Override
+    protected void doExecute() {
+        LabelResourceService lrs = get(LabelResourceService.class);
+        LabelResourcePool pool = lrs.getGlobalLabelResourcePool();
+        if (pool != null) {
+            print(FMT, pool.deviceId().toString(), pool.beginLabel(),
+                  pool.endLabel(), pool.totalNum(), pool.usedNum(),
+                  pool.currentUsedMaxLabelId(), pool.releaseLabelId()
+                          .toString());
+        }
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelPoolCreateCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelPoolCreateCommand.java
new file mode 100644
index 0000000..605f7c2
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelPoolCreateCommand.java
@@ -0,0 +1,49 @@
+/*
+ * 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.cli;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
+import org.onosproject.incubator.net.resource.label.LabelResourceId;
+
+/**
+ * create label resource pool by specific device id.
+ */
+@Service
+@Command(scope = "onos", name = "global-label-pool-create",
+description = "Creates global label resource pool.")
+public class GlobalLabelPoolCreateCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "beginLabel",
+            description = "The first label of global label resource pool.",
+            required = true, multiValued = false)
+    String beginLabel = null;
+    @Argument(index = 1, name = "endLabel",
+            description = "The last label of global label resource pool.",
+            required = true, multiValued = false)
+    String endLabel = null;
+
+    @Override
+    protected void doExecute() {
+        LabelResourceAdminService lrs = get(LabelResourceAdminService.class);
+        lrs.createGlobalPool(LabelResourceId.labelResourceId(Long
+                .parseLong(beginLabel)), LabelResourceId.labelResourceId(Long
+                .parseLong(endLabel)));
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelPoolDestroyCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelPoolDestroyCommand.java
new file mode 100644
index 0000000..09c70375
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelPoolDestroyCommand.java
@@ -0,0 +1,33 @@
+/*
+ * 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.cli;
+
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
+
+@Service
+@Command(scope = "onos", name = "global-label-pool-destroy",
+description = "Destroys global label resource pool")
+public class GlobalLabelPoolDestroyCommand extends AbstractShellCommand {
+    @Override
+    protected void doExecute() {
+        LabelResourceAdminService lrs = get(LabelResourceAdminService.class);
+        lrs.destroyGlobalPool();
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelReleaseCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelReleaseCommand.java
new file mode 100644
index 0000000..3a692be
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/GlobalLabelReleaseCommand.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.cli;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.resource.label.LabelResourceId;
+import org.onosproject.incubator.net.resource.label.LabelResourceService;
+
+@Service
+@Command(scope = "onos", name = "global-label-release",
+description = "Releases labels to global label resource pool.")
+public class GlobalLabelReleaseCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "releaseLabelIds",
+            description = "Represents for the label ids that are released. They are splited by dot symbol",
+            required = true, multiValued = false)
+    String releaseLabelIds = null;
+
+    @Override
+    protected void doExecute() {
+        LabelResourceService lrs = get(LabelResourceService.class);
+        Set<LabelResourceId> release = new HashSet<LabelResourceId>();
+        String[] labelIds = releaseLabelIds.split(",");
+        LabelResourceId resource = null;
+        for (int i = 0; i < labelIds.length; i++) {
+            resource = LabelResourceId.labelResourceId(Long.parseLong(labelIds[i]));
+            release.add(resource);
+        }
+        lrs.releaseToGlobalPool(release);
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelApplyCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelApplyCommand.java
new file mode 100644
index 0000000..c7634fa
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelApplyCommand.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.resource.label.cli;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.incubator.net.resource.label.DefaultLabelResource;
+import org.onosproject.incubator.net.resource.label.LabelResource;
+import org.onosproject.incubator.net.resource.label.LabelResourceService;
+
+@Service
+@Command(scope = "onos", name = "label-apply",
+      description = "Apply label resource from device pool by specific device id")
+public class LabelApplyCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "deviceId",
+            description = "Device identity",
+            required = true, multiValued = false)
+    String deviceId = null;
+    @Argument(index = 1, name = "applyNum",
+            description = "Applying number means how many labels applications want to use.",
+            required = true, multiValued = false)
+    String applyNum = null;
+
+    private static final String FMT = "deviceid=%s, labelresourceid=%s";
+
+    @Override
+    protected void doExecute() {
+        LabelResourceService lrs = get(LabelResourceService.class);
+        Collection<LabelResource> result = lrs.applyFromDevicePool(DeviceId
+                .deviceId(deviceId), Long.parseLong(applyNum));
+        if (!result.isEmpty()) {
+            for (Iterator<LabelResource> iterator = result.iterator(); iterator
+                    .hasNext();) {
+                DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator
+                        .next();
+                print(FMT, defaultLabelResource.deviceId().toString(),
+                      defaultLabelResource.labelResourceId().toString());
+            }
+        }
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelPoolCreateCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelPoolCreateCommand.java
new file mode 100644
index 0000000..775c269
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelPoolCreateCommand.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.cli;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
+import org.onosproject.incubator.net.resource.label.LabelResourceId;
+
+/**
+ * create label resource pool by specific device id.
+ */
+@Service
+@Command(scope = "onos", name = "label-pool-create",
+     description = "Creates label resource pool by a specific device id")
+public class LabelPoolCreateCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "deviceId", description = "Device identity", required = true, multiValued = false)
+    String deviceId = null;
+    @Argument(index = 1, name = "beginLabel",
+            description = "The first label of global label resource pool.", required = true, multiValued = false)
+    String beginLabel = null;
+    @Argument(index = 2, name = "endLabel",
+            description = "The last label of global label resource pool.", required = true, multiValued = false)
+    String endLabel = null;
+
+    @Override
+    protected void doExecute() {
+        LabelResourceAdminService lrs = get(LabelResourceAdminService.class);
+        lrs.createDevicePool(DeviceId.deviceId(deviceId), LabelResourceId
+                .labelResourceId(Long.parseLong(beginLabel)), LabelResourceId
+                .labelResourceId(Long.parseLong(endLabel)));
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelPoolDestroyCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelPoolDestroyCommand.java
new file mode 100644
index 0000000..c875cd8
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelPoolDestroyCommand.java
@@ -0,0 +1,38 @@
+/*
+ * 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.cli;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
+
+@Service
+@Command(scope = "onos", name = "label-pool-destroy",
+    description = "Destroys label resource pool by a specific device id")
+public class LabelPoolDestroyCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "deviceId", description = "Device identity", required = true, multiValued = false)
+    String deviceId = null;
+
+    @Override
+    protected void doExecute() {
+        LabelResourceAdminService lrs = get(LabelResourceAdminService.class);
+        lrs.destroyDevicePool(DeviceId.deviceId(deviceId));
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelReleaseCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelReleaseCommand.java
new file mode 100644
index 0000000..c511642
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelReleaseCommand.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.resource.label.cli;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.incubator.net.resource.label.DefaultLabelResource;
+import org.onosproject.incubator.net.resource.label.LabelResource;
+import org.onosproject.incubator.net.resource.label.LabelResourceId;
+import org.onosproject.incubator.net.resource.label.LabelResourceService;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
+@Service
+@Command(scope = "onos", name = "label-release",
+description = "Releases label ids to label resource pool by a specific device id")
+public class LabelReleaseCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "deviceId",
+            description = "Device identity",
+            required = true, multiValued = false)
+    String deviceId = null;
+    @Argument(index = 1, name = "releaseLabelIds",
+            description = "Represents for the label ids that are released. They are splited by dot symbol",
+            required = true, multiValued = false)
+    String releaseLabelIds = null;
+
+    @Override
+    protected void doExecute() {
+        LabelResourceService lrs = get(LabelResourceService.class);
+        Multimap<DeviceId, LabelResource> map = ArrayListMultimap
+                .create();
+        String[] labelIds = releaseLabelIds.split(",");
+        DefaultLabelResource resource = null;
+        for (int i = 0; i < labelIds.length; i++) {
+            resource = new DefaultLabelResource(
+                                                DeviceId.deviceId(deviceId),
+                                                LabelResourceId.labelResourceId(Long
+                                                        .parseLong(labelIds[i])));
+            map.put(DeviceId.deviceId(deviceId), resource);
+        }
+        lrs.releaseToDevicePool(map);
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelResourceCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelResourceCommand.java
new file mode 100644
index 0000000..84c8f65
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/LabelResourceCommand.java
@@ -0,0 +1,52 @@
+/*
+ * 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.cli;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.incubator.net.resource.label.LabelResourcePool;
+import org.onosproject.incubator.net.resource.label.LabelResourceService;
+
+@Service
+@Command(scope = "onos", name = "label-pool",
+      description = "Gets label resource pool information by a specific device id")
+public class LabelResourceCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "deviceId",
+            description = "Device identity", required = true, multiValued = false)
+    String deviceId = null;
+    private static final String FMT = "deviceid=%s, beginLabel=%s,"
+            + "endLabel=%s, totalNum=%s, usedNum=%s, currentUsedMaxLabelId=%s,"
+            + "releaseLabelIds=%s";
+
+    @Override
+    protected void doExecute() {
+        LabelResourceService lrs = get(LabelResourceService.class);
+        LabelResourcePool pool = lrs.getDeviceLabelResourcePool(DeviceId
+                .deviceId(deviceId));
+        if (pool != null) {
+            print(FMT, pool.deviceId().toString(), pool.beginLabel(),
+                  pool.endLabel(), pool.totalNum(), pool.usedNum(),
+                  pool.currentUsedMaxLabelId(), pool.releaseLabelId()
+                          .toString());
+        } else {
+            print(FMT, deviceId, null, null, null, null, null, null);
+        }
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/package-info.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/package-info.java
new file mode 100644
index 0000000..0e8608f
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/cli/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.
+ */
+
+/**
+ * CLIs for the resource label subsystem.
+ */
+package org.onosproject.incubator.net.resource.label.cli;
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/impl/LabelResourceManager.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/impl/LabelResourceManager.java
new file mode 100644
index 0000000..ad9a133
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/impl/LabelResourceManager.java
@@ -0,0 +1,233 @@
+/*
+ * Copyright 2015-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.impl;
+
+import com.google.common.collect.Multimap;
+import org.onosproject.incubator.net.resource.label.LabelResource;
+import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
+import org.onosproject.incubator.net.resource.label.LabelResourceDelegate;
+import org.onosproject.incubator.net.resource.label.LabelResourceEvent;
+import org.onosproject.incubator.net.resource.label.LabelResourceId;
+import org.onosproject.incubator.net.resource.label.LabelResourceListener;
+import org.onosproject.incubator.net.resource.label.LabelResourcePool;
+import org.onosproject.incubator.net.resource.label.LabelResourceProvider;
+import org.onosproject.incubator.net.resource.label.LabelResourceProviderRegistry;
+import org.onosproject.incubator.net.resource.label.LabelResourceProviderService;
+import org.onosproject.incubator.net.resource.label.LabelResourceService;
+import org.onosproject.incubator.net.resource.label.LabelResourceStore;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceEvent.Type;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.provider.AbstractListenerProviderRegistry;
+import org.onosproject.net.provider.AbstractProviderService;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * provides implementation of the label resource NB &amp; SB APIs.
+ *
+ */
+@Component(immediate = true,
+           service = {LabelResourceService.class, LabelResourceAdminService.class, LabelResourceProviderRegistry.class})
+public class LabelResourceManager
+        extends AbstractListenerProviderRegistry<LabelResourceEvent, LabelResourceListener,
+                                                 LabelResourceProvider, LabelResourceProviderService>
+        implements LabelResourceService, LabelResourceAdminService, LabelResourceProviderRegistry {
+    private final Logger log = getLogger(getClass());
+    private final LabelResourceDelegate delegate = new InternalLabelResourceDelegate();
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected LabelResourceStore store;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected DeviceService deviceService;
+
+    private DeviceListener deviceListener = new InternalDeviceListener();
+
+    @Activate
+    public void activate() {
+        store.setDelegate(delegate);
+        eventDispatcher.addSink(LabelResourceEvent.class, listenerRegistry);
+        deviceService.addListener(deviceListener);
+        log.info("Started");
+
+    }
+
+    @Deactivate
+    public void deactivate() {
+        deviceService.removeListener(deviceListener);
+        store.unsetDelegate(delegate);
+        eventDispatcher.removeSink(LabelResourceEvent.class);
+        log.info("Stopped");
+    }
+
+    @Override
+    public boolean createDevicePool(DeviceId deviceId,
+                                    LabelResourceId beginLabel,
+                                    LabelResourceId endLabel) {
+        checkNotNull(deviceId, "deviceId is not null");
+        checkNotNull(beginLabel, "beginLabel is not null");
+        checkNotNull(endLabel, "endLabel is not null");
+        checkArgument(beginLabel.labelId() >= 0 || endLabel.labelId() >= 0,
+                      "The value of beginLabel and the value of endLabel must be both positive number.");
+        checkArgument(beginLabel.labelId() < endLabel.labelId(),
+                      "The value of endLabel must be greater than the value of beginLabel.");
+        return store.createDevicePool(deviceId, beginLabel, endLabel);
+    }
+
+    @Override
+    public boolean createGlobalPool(LabelResourceId beginLabel,
+                                    LabelResourceId endLabel) {
+        checkNotNull(beginLabel, "beginLabel is not null");
+        checkNotNull(endLabel, "endLabel is not null");
+        checkArgument(beginLabel.labelId() >= 0 && endLabel.labelId() >= 0,
+                      "The value of beginLabel and the value of endLabel must be both positive number.");
+        checkArgument(beginLabel.labelId() < endLabel.labelId(),
+                      "The value of endLabel must be greater than the value of beginLabel.");
+        return store.createGlobalPool(beginLabel, endLabel);
+    }
+
+    @Override
+    public boolean destroyDevicePool(DeviceId deviceId) {
+        checkNotNull(deviceId, "deviceId is not null");
+        return store.destroyDevicePool(deviceId);
+    }
+
+    @Override
+    public boolean destroyGlobalPool() {
+        return store.destroyGlobalPool();
+    }
+
+    @Override
+    public Collection<LabelResource> applyFromDevicePool(DeviceId deviceId,
+                                                         long applyNum) {
+        checkNotNull(deviceId, "deviceId is not null");
+        return store.applyFromDevicePool(deviceId, applyNum);
+    }
+
+    @Override
+    public Collection<LabelResource> applyFromGlobalPool(long applyNum) {
+        return store.applyFromGlobalPool(applyNum);
+    }
+
+    @Override
+    public boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release) {
+        checkNotNull(release, "release is not null");
+        return store.releaseToDevicePool(release);
+    }
+
+    @Override
+    public boolean releaseToGlobalPool(Set<LabelResourceId> release) {
+        checkNotNull(release, "release is not null");
+        return store.releaseToGlobalPool(release);
+    }
+
+    @Override
+    public boolean isDevicePoolFull(DeviceId deviceId) {
+        checkNotNull(deviceId, "deviceId is not null");
+        return store.isDevicePoolFull(deviceId);
+    }
+
+    @Override
+    public boolean isGlobalPoolFull() {
+        return store.isGlobalPoolFull();
+    }
+
+    @Override
+    public long getFreeNumOfDevicePool(DeviceId deviceId) {
+        checkNotNull(deviceId, "deviceId is not null");
+        return store.getFreeNumOfDevicePool(deviceId);
+    }
+
+    @Override
+    public long getFreeNumOfGlobalPool() {
+        return store.getFreeNumOfGlobalPool();
+    }
+
+    @Override
+    public LabelResourcePool getDeviceLabelResourcePool(DeviceId deviceId) {
+        checkNotNull(deviceId, "deviceId is not null");
+        return store.getDeviceLabelResourcePool(deviceId);
+    }
+
+    @Override
+    public LabelResourcePool getGlobalLabelResourcePool() {
+        return store.getGlobalLabelResourcePool();
+    }
+
+    private class InternalLabelResourceDelegate implements LabelResourceDelegate {
+        @Override
+        public void notify(LabelResourceEvent event) {
+            post(event);
+        }
+
+    }
+
+    private class InternalDeviceListener implements DeviceListener {
+        @Override
+        public void event(DeviceEvent event) {
+            Device device = event.subject();
+            if (Type.DEVICE_REMOVED.equals(event.type())) {
+                destroyDevicePool(device.id());
+            }
+        }
+    }
+
+    private class InternalLabelResourceProviderService
+            extends AbstractProviderService<LabelResourceProvider>
+            implements LabelResourceProviderService {
+
+        protected InternalLabelResourceProviderService(LabelResourceProvider provider) {
+            super(provider);
+        }
+
+        @Override
+        public void deviceLabelResourcePoolDetected(DeviceId deviceId,
+                                                    LabelResourceId beginLabel,
+                                                    LabelResourceId endLabel) {
+            checkNotNull(deviceId, "deviceId is not null");
+            checkNotNull(beginLabel, "beginLabel is not null");
+            checkNotNull(endLabel, "endLabel is not null");
+            createDevicePool(deviceId, beginLabel, endLabel);
+        }
+
+        @Override
+        public void deviceLabelResourcePoolDestroyed(DeviceId deviceId) {
+            checkNotNull(deviceId, "deviceId is not null");
+            destroyDevicePool(deviceId);
+        }
+
+    }
+
+    @Override
+    protected LabelResourceProviderService createProviderService(LabelResourceProvider provider) {
+        return new InternalLabelResourceProviderService(provider);
+    }
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/impl/package-info.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/impl/package-info.java
new file mode 100644
index 0000000..6df566f
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015-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.
+ */
+
+/**
+ * Implementation of the label resource subsystem.
+ */
+package org.onosproject.incubator.net.resource.label.impl;
\ No newline at end of file
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/store/impl/DistributedLabelResourceStore.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/store/impl/DistributedLabelResourceStore.java
new file mode 100644
index 0000000..aa7133a
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/store/impl/DistributedLabelResourceStore.java
@@ -0,0 +1,530 @@
+/*
+ * 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.store.impl;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Multimap;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.incubator.net.resource.label.DefaultLabelResource;
+import org.onosproject.incubator.net.resource.label.LabelResource;
+import org.onosproject.incubator.net.resource.label.LabelResourceDelegate;
+import org.onosproject.incubator.net.resource.label.LabelResourceEvent;
+import org.onosproject.incubator.net.resource.label.LabelResourceEvent.Type;
+import org.onosproject.incubator.net.resource.label.LabelResourceId;
+import org.onosproject.incubator.net.resource.label.LabelResourcePool;
+import org.onosproject.incubator.net.resource.label.LabelResourceRequest;
+import org.onosproject.incubator.net.resource.label.LabelResourceStore;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.store.AbstractStore;
+import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.Versioned;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.onlab.util.Tools.groupedThreads;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Manages label resources using copycat.
+ */
+@Component(immediate = true, service = LabelResourceStore.class)
+public class DistributedLabelResourceStore
+        extends AbstractStore<LabelResourceEvent, LabelResourceDelegate>
+        implements LabelResourceStore {
+    private final Logger log = getLogger(getClass());
+
+    private static final String POOL_MAP_NAME = "onos-label-resource-pool";
+
+    private static final String GLOBAL_RESOURCE_POOL_DEVICE_ID = "global_resource_pool_device_id";
+
+    private ConsistentMap<DeviceId, LabelResourcePool> resourcePool = null;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected StorageService storageService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected MastershipService mastershipService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected ClusterCommunicationService clusterCommunicator;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected ClusterService clusterService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected DeviceService deviceService;
+
+    private ExecutorService messageHandlingExecutor;
+    private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 8;
+    private static final long PEER_REQUEST_TIMEOUT_MS = 5000;
+
+    private static final Serializer SERIALIZER = Serializer
+            .using(new KryoNamespace.Builder().register(KryoNamespaces.API)
+                    .register(LabelResourceEvent.class)
+                    .register(LabelResourcePool.class)
+                    .register(LabelResourceRequest.class)
+                    .register(LabelResourceRequest.Type.class)
+                    .register(LabelResourceEvent.Type.class)
+                    .register(DefaultLabelResource.class)
+                    .register(LabelResourceId.class)
+                    .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID).build());
+
+    @Activate
+    public void activate() {
+
+        resourcePool = storageService
+                .<DeviceId, LabelResourcePool>consistentMapBuilder()
+                .withName(POOL_MAP_NAME).withSerializer(SERIALIZER).build();
+        messageHandlingExecutor = Executors
+                .newFixedThreadPool(MESSAGE_HANDLER_THREAD_POOL_SIZE,
+                                    groupedThreads("onos/store/flow",
+                                                   "message-handlers",
+                                                   log));
+        clusterCommunicator
+                .addSubscriber(LabelResourceMessageSubjects.LABEL_POOL_CREATED,
+                        SERIALIZER::<LabelResourcePool>decode,
+                        operation -> {
+                            log.trace("received get flow entry request for {}", operation);
+                            return internalCreate(operation);
+                        },
+                        SERIALIZER::<Boolean>encode,
+                        messageHandlingExecutor);
+        clusterCommunicator
+                .addSubscriber(LabelResourceMessageSubjects.LABEL_POOL_DESTROYED,
+                        SERIALIZER::<DeviceId>decode,
+                        deviceId -> {
+                            log.trace("received get flow entry request for {}", deviceId);
+                            return internalDestroy(deviceId);
+                        },
+                        SERIALIZER::<Boolean>encode,
+                        messageHandlingExecutor);
+        clusterCommunicator
+                .addSubscriber(LabelResourceMessageSubjects.LABEL_POOL_APPLY,
+                        SERIALIZER::<LabelResourceRequest>decode,
+                        request -> {
+                            log.trace("received get flow entry request for {}", request);
+                            return internalApply(request);
+
+                        },
+                        SERIALIZER::<Collection<LabelResource>>encode,
+                        messageHandlingExecutor);
+        clusterCommunicator
+                .addSubscriber(LabelResourceMessageSubjects.LABEL_POOL_RELEASE,
+                        SERIALIZER::<LabelResourceRequest>decode,
+                        request -> {
+                            log.trace("received get flow entry request for {}",
+                                    request);
+                            return internalRelease(request);
+                        },
+                        SERIALIZER::<Boolean>encode,
+                        messageHandlingExecutor);
+        log.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        clusterCommunicator
+                .removeSubscriber(LabelResourceMessageSubjects.LABEL_POOL_CREATED);
+        clusterCommunicator
+                .removeSubscriber(LabelResourceMessageSubjects.LABEL_POOL_APPLY);
+        clusterCommunicator
+                .removeSubscriber(LabelResourceMessageSubjects.LABEL_POOL_DESTROYED);
+        clusterCommunicator
+                .removeSubscriber(LabelResourceMessageSubjects.LABEL_POOL_RELEASE);
+        messageHandlingExecutor.shutdown();
+        log.info("Stopped");
+    }
+
+    @Override
+    public boolean createDevicePool(DeviceId deviceId,
+                                    LabelResourceId beginLabel,
+                                    LabelResourceId endLabel) {
+        LabelResourcePool pool = new LabelResourcePool(deviceId.toString(),
+                                                       beginLabel.labelId(),
+                                                       endLabel.labelId());
+        return this.create(pool);
+    }
+
+    @Override
+    public boolean createGlobalPool(LabelResourceId beginLabel,
+                                    LabelResourceId endLabel) {
+        LabelResourcePool pool = new LabelResourcePool(GLOBAL_RESOURCE_POOL_DEVICE_ID,
+                                                       beginLabel.labelId(),
+                                                       endLabel.labelId());
+        return this.internalCreate(pool);
+    }
+
+    private boolean create(LabelResourcePool pool) {
+        Device device = deviceService.getDevice(pool.deviceId());
+        if (device == null) {
+            return false;
+        }
+
+        NodeId master = mastershipService.getMasterFor(pool.deviceId());
+
+        if (master == null) {
+            log.warn("Failed to create label resource pool: No master for {}", pool);
+            return false;
+        }
+
+        if (master.equals(clusterService.getLocalNode().id())) {
+            return internalCreate(pool);
+        }
+
+        log.trace("Forwarding getFlowEntries to {}, which is the primary (master) for device {}",
+                  master, pool.deviceId());
+
+        return complete(clusterCommunicator
+                .sendAndReceive(pool,
+                                LabelResourceMessageSubjects.LABEL_POOL_CREATED,
+                                SERIALIZER::encode, SERIALIZER::decode,
+                                master));
+    }
+
+    private boolean internalCreate(LabelResourcePool pool) {
+        Versioned<LabelResourcePool> poolOld = resourcePool
+                .get(pool.deviceId());
+        if (poolOld == null) {
+            resourcePool.put(pool.deviceId(), pool);
+            LabelResourceEvent event = new LabelResourceEvent(Type.POOL_CREATED,
+                                                              pool);
+            notifyDelegate(event);
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public boolean destroyDevicePool(DeviceId deviceId) {
+        Device device = deviceService.getDevice(deviceId);
+        if (device == null) {
+            return false;
+        }
+
+        NodeId master = mastershipService.getMasterFor(deviceId);
+
+        if (master == null) {
+            log.warn("Failed to destroyDevicePool. No master for {}", deviceId);
+            return false;
+        }
+
+        if (master.equals(clusterService.getLocalNode().id())) {
+            return internalDestroy(deviceId);
+        }
+
+        log.trace("Forwarding request to {}, which is the primary (master) for device {}",
+                  master, deviceId);
+
+        return complete(clusterCommunicator
+                .sendAndReceive(deviceId,
+                                LabelResourceMessageSubjects.LABEL_POOL_DESTROYED,
+                                SERIALIZER::encode, SERIALIZER::decode,
+                                master));
+    }
+
+    private boolean internalDestroy(DeviceId deviceId) {
+        Versioned<LabelResourcePool> poolOld = resourcePool.get(deviceId);
+        if (poolOld != null) {
+            resourcePool.remove(deviceId);
+            LabelResourceEvent event = new LabelResourceEvent(Type.POOL_DESTROYED,
+                                                              poolOld.value());
+            notifyDelegate(event);
+        }
+        log.info("success to destroy the label resource pool of device id {}",
+                 deviceId);
+        return true;
+    }
+
+    @Override
+    public Collection<LabelResource> applyFromDevicePool(DeviceId deviceId,
+                                                         long applyNum) {
+        Device device = deviceService.getDevice(deviceId);
+        if (device == null) {
+            return Collections.emptyList();
+        }
+        LabelResourceRequest request = new LabelResourceRequest(deviceId,
+                                                                LabelResourceRequest.Type.APPLY,
+                                                                applyNum, null);
+        NodeId master = mastershipService.getMasterFor(deviceId);
+
+        if (master == null) {
+            log.warn("Failed to applyFromDevicePool: No master for {}", deviceId);
+            return Collections.emptyList();
+        }
+
+        if (master.equals(clusterService.getLocalNode().id())) {
+            return internalApply(request);
+        }
+
+        log.trace("Forwarding request to {}, which is the primary (master) for device {}",
+                  master, deviceId);
+
+        return complete(clusterCommunicator
+                .sendAndReceive(request,
+                                LabelResourceMessageSubjects.LABEL_POOL_APPLY,
+                                SERIALIZER::encode, SERIALIZER::decode,
+                                master));
+    }
+
+    private Collection<LabelResource> internalApply(LabelResourceRequest request) {
+        DeviceId deviceId = request.deviceId();
+        long applyNum = request.applyNum();
+        Versioned<LabelResourcePool> poolOld = resourcePool.get(deviceId);
+        if (poolOld == null) {
+            log.info("label resource pool not allocated for deviceId {}.", deviceId);
+            return Collections.emptyList();
+        }
+        LabelResourcePool pool = poolOld.value();
+        Collection<LabelResource> result = new HashSet<>();
+        long freeNum = this.getFreeNumOfDevicePool(deviceId);
+        if (applyNum > freeNum) {
+            log.info("the free number of the label resource pool of deviceId {} is not enough.");
+            return Collections.emptyList();
+        }
+        Set<LabelResource> releaseLabels = new HashSet<>(pool.releaseLabelId());
+        long tmp = releaseLabels.size() > applyNum ? applyNum : releaseLabels
+                .size();
+        LabelResource resource = null;
+        for (int i = 0; i < tmp; i++) {
+            Iterator<LabelResource> it = releaseLabels.iterator();
+            if (it.hasNext()) {
+                resource = it.next();
+                releaseLabels.remove(resource);
+            }
+            result.add(resource);
+        }
+        for (long j = pool.currentUsedMaxLabelId().labelId(); j < pool
+                .currentUsedMaxLabelId().labelId() + applyNum - tmp; j++) {
+            resource = new DefaultLabelResource(deviceId,
+                                                LabelResourceId
+                                                        .labelResourceId(j));
+            result.add(resource);
+        }
+        long beginLabel = pool.beginLabel().labelId();
+        long endLabel = pool.endLabel().labelId();
+        long totalNum = pool.totalNum();
+        long current = pool.currentUsedMaxLabelId().labelId() + applyNum - tmp;
+        long usedNum = pool.usedNum() + applyNum;
+        ImmutableSet<LabelResource> freeLabel = ImmutableSet
+                .copyOf(releaseLabels);
+        LabelResourcePool newPool = new LabelResourcePool(deviceId.toString(),
+                                                          beginLabel, endLabel,
+                                                          totalNum, usedNum,
+                                                          current, freeLabel);
+        resourcePool.put(deviceId, newPool);
+        log.info("success to apply label resource");
+        return result;
+    }
+
+    @Override
+    public boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release) {
+        Map<DeviceId, Collection<LabelResource>> maps = release.asMap();
+        Set<DeviceId> deviceIdSet = maps.keySet();
+        LabelResourceRequest request = null;
+        for (Iterator<DeviceId> it = deviceIdSet.iterator(); it.hasNext();) {
+            DeviceId deviceId = it.next();
+            Device device = deviceService.getDevice(deviceId);
+            if (device == null) {
+                continue;
+            }
+            ImmutableSet<LabelResource> collection = ImmutableSet.copyOf(maps
+                    .get(deviceId));
+            request = new LabelResourceRequest(deviceId,
+                                               LabelResourceRequest.Type.RELEASE,
+                                               0, collection);
+            NodeId master = mastershipService.getMasterFor(deviceId);
+
+            if (master == null) {
+                log.warn("Failed to releaseToDevicePool: No master for {}", deviceId);
+                return false;
+            }
+
+            if (master.equals(clusterService.getLocalNode().id())) {
+                return internalRelease(request);
+            }
+
+            log.trace("Forwarding request to {}, which is the primary (master) for device {}",
+                      master, deviceId);
+
+            return complete(clusterCommunicator
+                    .sendAndReceive(request,
+                                    LabelResourceMessageSubjects.LABEL_POOL_RELEASE,
+                                    SERIALIZER::encode, SERIALIZER::decode,
+                                    master));
+        }
+        return false;
+    }
+
+    private boolean internalRelease(LabelResourceRequest request) {
+        DeviceId deviceId = request.deviceId();
+        Collection<LabelResource> release = request.releaseCollection();
+        Versioned<LabelResourcePool> poolOld = resourcePool.get(deviceId);
+        if (poolOld == null) {
+            log.info("the label resource pool of device id {} not allocated");
+            return false;
+        }
+        LabelResourcePool pool = poolOld.value();
+        if (pool == null) {
+            log.info("the label resource pool of device id {} does not exist");
+            return false;
+        }
+        Set<LabelResource> storeSet = new HashSet<>(pool.releaseLabelId());
+        LabelResource labelResource = null;
+        long realReleasedNum = 0;
+        for (Iterator<LabelResource> it = release.iterator(); it.hasNext();) {
+            labelResource = it.next();
+            if (labelResource.labelResourceId().labelId() < pool.beginLabel()
+                    .labelId()
+                    || labelResource.labelResourceId().labelId() > pool
+                            .endLabel().labelId()) {
+                continue;
+            }
+            if (pool.currentUsedMaxLabelId().labelId() > labelResource
+                    .labelResourceId().labelId()
+                    || !storeSet.contains(labelResource)) {
+                storeSet.add(labelResource);
+                realReleasedNum++;
+            }
+        }
+        long beginNum = pool.beginLabel().labelId();
+        long endNum = pool.endLabel().labelId();
+        long totalNum = pool.totalNum();
+        long usedNum = pool.usedNum() - realReleasedNum;
+        long current = pool.currentUsedMaxLabelId().labelId();
+        ImmutableSet<LabelResource> s = ImmutableSet.copyOf(storeSet);
+        LabelResourcePool newPool = new LabelResourcePool(deviceId.toString(),
+                                                          beginNum, endNum,
+                                                          totalNum, usedNum,
+                                                          current, s);
+        resourcePool.put(deviceId, newPool);
+        log.info("success to release label resource");
+        return true;
+    }
+
+    @Override
+    public boolean isDevicePoolFull(DeviceId deviceId) {
+        Versioned<LabelResourcePool> pool = resourcePool.get(deviceId);
+        if (pool == null) {
+            return true;
+        }
+        return pool.value().currentUsedMaxLabelId() == pool.value().endLabel()
+                && pool.value().releaseLabelId().size() == 0 ? true : false;
+    }
+
+    @Override
+    public long getFreeNumOfDevicePool(DeviceId deviceId) {
+        Versioned<LabelResourcePool> pool = resourcePool.get(deviceId);
+        if (pool == null) {
+            return 0;
+        }
+        return pool.value().endLabel().labelId()
+                - pool.value().currentUsedMaxLabelId().labelId()
+                + pool.value().releaseLabelId().size();
+    }
+
+    @Override
+    public LabelResourcePool getDeviceLabelResourcePool(DeviceId deviceId) {
+        Versioned<LabelResourcePool> pool = resourcePool.get(deviceId);
+        return pool == null ? null : pool.value();
+    }
+
+    @Override
+    public boolean destroyGlobalPool() {
+        return this.internalDestroy(DeviceId
+                .deviceId(GLOBAL_RESOURCE_POOL_DEVICE_ID));
+    }
+
+    @Override
+    public Collection<LabelResource> applyFromGlobalPool(long applyNum) {
+        LabelResourceRequest request = new LabelResourceRequest(DeviceId.deviceId(GLOBAL_RESOURCE_POOL_DEVICE_ID),
+                                                                LabelResourceRequest.Type.APPLY,
+                                                                applyNum, null);
+        return this.internalApply(request);
+    }
+
+    @Override
+    public boolean releaseToGlobalPool(Set<LabelResourceId> release) {
+        Set<LabelResource> set = new HashSet<>();
+        DefaultLabelResource resource = null;
+        for (LabelResourceId labelResource : release) {
+            resource = new DefaultLabelResource(DeviceId.deviceId(GLOBAL_RESOURCE_POOL_DEVICE_ID),
+                                                labelResource);
+            set.add(resource);
+        }
+        LabelResourceRequest request = new LabelResourceRequest(DeviceId.deviceId(GLOBAL_RESOURCE_POOL_DEVICE_ID),
+                                                                LabelResourceRequest.Type.RELEASE,
+                                                                0,
+                                                                ImmutableSet.copyOf(set));
+        return this.internalRelease(request);
+    }
+
+    @Override
+    public boolean isGlobalPoolFull() {
+        return this.isDevicePoolFull(DeviceId
+                .deviceId(GLOBAL_RESOURCE_POOL_DEVICE_ID));
+    }
+
+    @Override
+    public long getFreeNumOfGlobalPool() {
+        return this.getFreeNumOfDevicePool(DeviceId
+                .deviceId(GLOBAL_RESOURCE_POOL_DEVICE_ID));
+    }
+
+    @Override
+    public LabelResourcePool getGlobalLabelResourcePool() {
+        return this.getDeviceLabelResourcePool(DeviceId
+                .deviceId(GLOBAL_RESOURCE_POOL_DEVICE_ID));
+    }
+
+    private <T> T complete(Future<T> future) {
+        try {
+            return future.get(PEER_REQUEST_TIMEOUT_MS, TimeUnit.MILLISECONDS);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            log.error("Interrupted while waiting for operation to complete.", e);
+            return null;
+        } catch (TimeoutException | ExecutionException e) {
+            log.error("Failed remote operation", e);
+            return null;
+        }
+    }
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/store/impl/LabelResourceMessageSubjects.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/store/impl/LabelResourceMessageSubjects.java
new file mode 100644
index 0000000..cd89233
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/store/impl/LabelResourceMessageSubjects.java
@@ -0,0 +1,32 @@
+/*
+ * 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.store.impl;
+
+import org.onosproject.store.cluster.messaging.MessageSubject;
+
+public final class LabelResourceMessageSubjects {
+
+    private LabelResourceMessageSubjects() {
+    }
+    public static final MessageSubject LABEL_POOL_CREATED
+                        = new MessageSubject("label-resource-pool-created");
+    public static final MessageSubject LABEL_POOL_DESTROYED
+                        = new MessageSubject("label-resource-pool-destroyed");
+    public static final MessageSubject LABEL_POOL_APPLY
+                        = new MessageSubject("label-resource-pool-apply");
+    public static final MessageSubject LABEL_POOL_RELEASE
+                        = new MessageSubject("label-resource-pool-release");
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/store/impl/package-info.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/store/impl/package-info.java
new file mode 100644
index 0000000..b97e9bc
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/resource/label/store/impl/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.
+ */
+
+/**
+ * Implementation of the label resource distributed store.
+ */
+package org.onosproject.incubator.net.resource.label.store.impl;
\ No newline at end of file
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/AddTunnelCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/AddTunnelCommand.java
new file mode 100644
index 0000000..86eb5f4
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/AddTunnelCommand.java
@@ -0,0 +1,69 @@
+/*
+ * 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.cli;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.domain.IntentDomainId;
+import org.onosproject.incubator.net.domain.IntentDomainService;
+import org.onosproject.incubator.net.domain.TunnelPrimitive;
+import org.onosproject.net.ConnectPoint;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Installs intent domain tunnel primitive.
+ */
+@Service
+@Command(scope = "onos", name = "add-domain-tunnel",
+         description = "Installs intent domain tunnel primitive")
+public class AddTunnelCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "one",
+              description = "Port one",
+              required = true, multiValued = false)
+    String oneString = null;
+
+    @Argument(index = 1, name = "two",
+              description = "Port two",
+              required = true, multiValued = false)
+    String twoString = null;
+
+    @Override
+    protected void doExecute() {
+        IntentDomainService service = get(IntentDomainService.class);
+
+        ConnectPoint one = ConnectPoint.deviceConnectPoint(oneString);
+        ConnectPoint two = ConnectPoint.deviceConnectPoint(twoString);
+
+        TunnelPrimitive tunnel = new TunnelPrimitive(appId(), one, two);
+
+        // get the first domain (there should only be one)
+        final IntentDomainId domainId;
+        try {
+            domainId = service.getDomains().iterator().next().id();
+        } catch (NoSuchElementException | NullPointerException e) {
+            print("No domains found");
+            return;
+        }
+
+        service.request(domainId, tunnel).forEach(r -> service.submit(domainId, r));
+
+        print("Intent domain tunnel submitted:\n%s", tunnel);
+    }
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelBorrowCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelBorrowCommand.java
new file mode 100644
index 0000000..4934c11
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelBorrowCommand.java
@@ -0,0 +1,214 @@
+/*
+ * 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.cli;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Optional;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.action.Option;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.DefaultApplicationId;
+import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.OpticalLogicId;
+import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.incubator.net.tunnel.TunnelService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * Borrows tunnels. It's used by consumers.
+ */
+@Service
+@Command(scope = "onos", name = "tunnel-borrow", description = "Borrows tunnels. It's used by consumers.")
+public class TunnelBorrowCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "consumerId",
+            description = "consumer id means application id.", required = true, multiValued = false)
+    String consumerId = null;
+
+    @Option(name = "-s", aliases = "--src", description = "Source tunnel point."
+            + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
+            + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
+            + " Otherwise src means IP address.", required = false, multiValued = false)
+    String src = null;
+
+    @Option(name = "-d", aliases = "--dst", description = "Destination tunnel point."
+            + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
+            + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
+            + " Otherwise dst means IP address.", required = false, multiValued = false)
+    String dst = null;
+
+    @Option(name = "-t", aliases = "--type", description = "The type of tunnels,"
+            + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = false, multiValued = false)
+    String type = null;
+
+    @Option(name = "-i", aliases = "--tunnelId",
+            description = "the tunnel identity.", required = false, multiValued = false)
+    String tunnelId = null;
+
+    @Option(name = "-n", aliases = "--tunnelName",
+            description = "The name of tunnels", required = false, multiValued = false)
+    String tunnelName = null;
+    private static final String FMT = "src=%s, dst=%s,"
+            + "type=%s, state=%s, producerName=%s, tunnelName=%s,"
+            + "groupId=%s";
+
+    @Override
+    protected void doExecute() {
+        Collection<Tunnel> tunnelSet = null;
+        Tunnel.Type trueType = null;
+        TunnelService service = get(TunnelService.class);
+        ApplicationId appId = new DefaultApplicationId(1, consumerId);
+        ProviderId producerName = new ProviderId("default",
+                                                 "org.onosproject.provider.tunnel.default");
+        if (!isNull(src) && !isNull(dst) && !isNull(type)) {
+            TunnelEndPoint srcPoint = null;
+            TunnelEndPoint dstPoint = null;
+            if ("MPLS".equals(type)) {
+                trueType = Tunnel.Type.MPLS;
+                srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(src));
+                dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(dst));
+            } else if ("VXLAN".equals(type)) {
+                trueType = Tunnel.Type.VXLAN;
+                srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(src));
+                dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(dst));
+            } else if ("GRE".equals(type)) {
+                trueType = Tunnel.Type.GRE;
+                srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(src));
+                dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(dst));
+            } else if ("VLAN".equals(type)) {
+                trueType = Tunnel.Type.VLAN;
+                String[] srcArray = src.split("-");
+                String[] dstArray = dst.split("-");
+                srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(srcArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(srcArray[1])),
+                                                            null,
+                                                            null,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+                dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(dstArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(dstArray[1])),
+                                                            null,
+                                                            null,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+            } else if ("ODUK".equals(type)) {
+                trueType = Tunnel.Type.ODUK;
+                String[] srcArray = src.split("-");
+                String[] dstArray = dst.split("-");
+                srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(srcArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(srcArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.LAMBDA,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+                dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(dstArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(dstArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.LAMBDA,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+            } else if ("OCH".equals(type)) {
+                trueType = Tunnel.Type.OCH;
+                String[] srcArray = src.split("-");
+                String[] dstArray = dst.split("-");
+                srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(srcArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(srcArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.TIMESLOT,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+                dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(dstArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(dstArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.TIMESLOT,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+            } else {
+                print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
+                return;
+            }
+            tunnelSet = service.borrowTunnel(appId, srcPoint, dstPoint, trueType);
+        }
+        if (!isNull(tunnelId)) {
+            TunnelId id = TunnelId.valueOf(tunnelId);
+            Tunnel tunnel = service.borrowTunnel(appId, id);
+            tunnelSet = new HashSet<Tunnel>();
+            tunnelSet.add(tunnel);
+        }
+        if (!isNull(tunnelName)) {
+            TunnelName name = TunnelName.tunnelName(tunnelName);
+            tunnelSet = service.borrowTunnel(appId, name);
+        }
+        for (Tunnel tunnel : tunnelSet) {
+            print(FMT, tunnel.src(), tunnel.dst(), tunnel.type(),
+                  tunnel.state(), tunnel.providerId(), tunnel.tunnelName(),
+                  tunnel.groupId());
+        }
+    }
+
+    private boolean isNull(String s) {
+        return s == null || "".equals(s);
+    }
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelCreateCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelCreateCommand.java
new file mode 100644
index 0000000..259998a
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelCreateCommand.java
@@ -0,0 +1,207 @@
+/*
+ * 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.cli;
+
+import java.util.Optional;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.action.Option;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.core.GroupId;
+import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.OpticalLogicId;
+import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelDescription;
+import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.incubator.net.tunnel.TunnelProvider;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * Supports for creating a tunnel by using IP address and optical as tunnel end
+ * point.
+ */
+@Service
+@Command(scope = "onos", name = "tunnel-create",
+description = "Supports for creating a tunnel by using IP address and optical as tunnel end point now.")
+public class TunnelCreateCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "src", description = "Source tunnel point."
+            + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
+            + " If creates a ODUK or OCH or VLAN type tunnel, the formatter of this argument is DeviceId-PortNumber."
+            + " Otherwise src means IP address.", required = true, multiValued = false)
+    String src = null;
+
+    @Argument(index = 1, name = "dst", description = "Destination tunnel point."
+            + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
+            + " If creates a ODUK or OCH or VLAN type tunnel, the formatter of this argument is DeviceId-PortNumber."
+            + " Otherwise dst means IP address.", required = true, multiValued = false)
+    String dst = null;
+    @Argument(index = 2, name = "type", description = "The type of tunnels,"
+            + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false)
+    String type = null;
+    @Option(name = "-g", aliases = "--groupId",
+            description = "Group flow table id which a tunnel match up", required = false, multiValued = false)
+    String groupId = "0";
+
+    @Option(name = "-n", aliases = "--tunnelName",
+            description = "The name of tunnels", required = false, multiValued = false)
+    String tunnelName = "onos";
+
+    @Option(name = "-b", aliases = "--bandwidth",
+            description = "The bandwidth attribute of tunnel", required = false, multiValued = false)
+    String bandwidth = "1024";
+
+    private static final String FMT = "The tunnel identity is %s";
+
+    @Override
+    protected void doExecute() {
+        TunnelProvider service = get(TunnelProvider.class);
+        ProviderId producerName = new ProviderId("default",
+                                                 "org.onosproject.provider.tunnel.default");
+        TunnelEndPoint srcPoint = null;
+        TunnelEndPoint dstPoint = null;
+        Tunnel.Type trueType = null;
+        if ("MPLS".equals(type)) {
+            trueType = Tunnel.Type.MPLS;
+            srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
+            dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
+        } else if ("VLAN".equals(type)) {
+            trueType = Tunnel.Type.VLAN;
+            String[] srcArray = src.split("/");
+            String[] dstArray = dst.split("/");
+            srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                        producerName,
+                                                        Optional.of(DeviceId
+                                                                .deviceId(srcArray[0])),
+                                                        Optional.of(PortNumber
+                                                                .portNumber(srcArray[1])),
+                                                        null,
+                                                        null,
+                                                        OpticalLogicId
+                                                                .logicId(0),
+                                                        true);
+            dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                        producerName,
+                                                        Optional.of(DeviceId
+                                                                .deviceId(dstArray[0])),
+                                                        Optional.of(PortNumber
+                                                                .portNumber(dstArray[1])),
+                                                        null,
+                                                        null,
+                                                        OpticalLogicId
+                                                                .logicId(0),
+                                                        true);
+        } else if ("VXLAN".equals(type)) {
+            trueType = Tunnel.Type.VXLAN;
+            srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
+            dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
+        } else if ("GRE".equals(type)) {
+            trueType = Tunnel.Type.GRE;
+            srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
+            dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
+        } else if ("ODUK".equals(type)) {
+            trueType = Tunnel.Type.ODUK;
+            String[] srcArray = src.split("/");
+            String[] dstArray = dst.split("/");
+            srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                        producerName,
+                                                        Optional.of(DeviceId
+                                                                .deviceId(srcArray[0])),
+                                                        Optional.of(PortNumber
+                                                                .portNumber(srcArray[1])),
+                                                        null,
+                                                        OpticalTunnelEndPoint.Type.LAMBDA,
+                                                        OpticalLogicId
+                                                                .logicId(0),
+                                                        true);
+            dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                        producerName,
+                                                        Optional.of(DeviceId
+                                                                .deviceId(dstArray[0])),
+                                                        Optional.of(PortNumber
+                                                                .portNumber(dstArray[1])),
+                                                        null,
+                                                        OpticalTunnelEndPoint.Type.LAMBDA,
+                                                        OpticalLogicId
+                                                                .logicId(0),
+                                                        true);
+        } else if ("OCH".equals(type)) {
+            trueType = Tunnel.Type.OCH;
+            String[] srcArray = src.split("/");
+            String[] dstArray = dst.split("/");
+            srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                        producerName,
+                                                        Optional.of(DeviceId
+                                                                .deviceId(srcArray[0])),
+                                                        Optional.of(PortNumber
+                                                                .portNumber(srcArray[1])),
+                                                        null,
+                                                        OpticalTunnelEndPoint.Type.TIMESLOT,
+                                                        OpticalLogicId
+                                                                .logicId(0),
+                                                        true);
+            dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                        producerName,
+                                                        Optional.of(DeviceId
+                                                                .deviceId(dstArray[0])),
+                                                        Optional.of(PortNumber
+                                                                .portNumber(dstArray[1])),
+                                                        null,
+                                                        OpticalTunnelEndPoint.Type.TIMESLOT,
+                                                        OpticalLogicId
+                                                                .logicId(0),
+                                                        true);
+        } else {
+            print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
+            return;
+        }
+
+        SparseAnnotations annotations = DefaultAnnotations
+                .builder()
+                .set("bandwidth", bandwidth == null || "".equals(bandwidth) ? "0" : bandwidth)
+                .build();
+        TunnelDescription tunnel = new DefaultTunnelDescription(
+                                                                null,
+                                                                srcPoint,
+                                                                dstPoint,
+                                                                trueType,
+                                                                new GroupId(Integer.parseInt(groupId)),
+                                                                producerName,
+                                                                TunnelName
+                                                                        .tunnelName(tunnelName),
+                                                                        null,
+                                                                annotations);
+        TunnelId tunnelId = service.tunnelAdded(tunnel);
+        if (tunnelId == null) {
+            error("Create tunnel failed.");
+            return;
+        }
+        print(FMT, tunnelId.id());
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelQueryCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelQueryCommand.java
new file mode 100644
index 0000000..166929b
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelQueryCommand.java
@@ -0,0 +1,226 @@
+/*
+ * 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.cli;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Optional;
+
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.action.Option;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.OpticalLogicId;
+import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.Path;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * Supports for querying tunnels. It's used by consumers.
+ */
+@Service
+@Command(scope = "onos", name = "tunnels", description = "Supports for querying tunnels."
+        + " It's used by consumers.")
+public class TunnelQueryCommand extends AbstractShellCommand {
+    @Option(name = "-s", aliases = "--src", description = "Source tunnel point."
+            + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
+            + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
+            + " Otherwise src means IP address.", required = false, multiValued = false)
+    String src = null;
+    @Option(name = "-d", aliases = "--dst", description = "Destination tunnel point."
+            + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
+            + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
+            + " Otherwise dst means IP address.", required = false, multiValued = false)
+    String dst = null;
+
+    @Option(name = "-t", aliases = "--type", description = "The type of tunnels,"
+            + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = false, multiValued = false)
+    String type = null;
+
+    @Option(name = "-i", aliases = "--tunnelId",
+            description = "the tunnel identity.", required = false, multiValued = false)
+    String tunnelId = null;
+
+    private static final String FMT = "tunnelId=%s, src=%s, dst=%s,"
+            + "type=%s, state=%s, producerName=%s, tunnelName=%s,"
+            + "groupId=%s, path=%s%s";
+
+    @Override
+    protected void doExecute() {
+        Tunnel.Type trueType = null;
+        TunnelService service = get(TunnelService.class);
+        ProviderId producerName = new ProviderId("default",
+                                                 "org.onosproject.provider.tunnel.default");
+        Collection<Tunnel> tunnelSet = null;
+        if (isNull(src) && isNull(dst) && isNull(type) && isNull(tunnelId)) {
+            tunnelSet = service.queryAllTunnels();
+        }
+
+        if (!isNull(src) && !isNull(dst) && !isNull(type)) {
+            TunnelEndPoint srcPoint = null;
+            TunnelEndPoint dstPoint = null;
+            if ("MPLS".equals(type) || "VXLAN".equals(type)
+                    || "GRE".equals(type)) {
+                srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(src));
+                dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(dst));
+            } else if ("VLAN".equals(type)) {
+                String[] srcArray = src.split("/");
+                String[] dstArray = dst.split("/");
+                srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(srcArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(srcArray[1])),
+                                                            null,
+                                                            null,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+                dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(dstArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(dstArray[1])),
+                                                            null,
+                                                            null,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+            } else if ("ODUK".equals(type)) {
+                String[] srcArray = src.split("/");
+                String[] dstArray = dst.split("/");
+                srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(srcArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(srcArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.LAMBDA,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+                dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(dstArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(dstArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.LAMBDA,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+            } else if ("OCH".equals(type)) {
+                String[] srcArray = src.split("/");
+                String[] dstArray = dst.split("/");
+                srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(srcArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(srcArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.TIMESLOT,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+                dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(dstArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(dstArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.TIMESLOT,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+            } else {
+                print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
+                return;
+            }
+            tunnelSet = service.queryTunnel(srcPoint, dstPoint);
+        }
+        if (!isNull(type)) {
+            if ("MPLS".equals(type)) {
+                trueType = Tunnel.Type.MPLS;
+            } else if ("VLAN".equals(type)) {
+                trueType = Tunnel.Type.VLAN;
+            } else if ("VXLAN".equals(type)) {
+                trueType = Tunnel.Type.VXLAN;
+            } else if ("GRE".equals(type)) {
+                trueType = Tunnel.Type.GRE;
+            } else if ("ODUK".equals(type)) {
+                trueType = Tunnel.Type.ODUK;
+            } else if ("OCH".equals(type)) {
+                trueType = Tunnel.Type.OCH;
+            } else {
+                print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
+                return;
+            }
+            tunnelSet = service.queryTunnel(trueType);
+        }
+        if (!isNull(tunnelId)) {
+            TunnelId id = TunnelId.valueOf(tunnelId);
+            Tunnel tunnel = service.queryTunnel(id);
+            tunnelSet = new HashSet<Tunnel>();
+            tunnelSet.add(tunnel);
+        }
+        if (tunnelSet != null) {
+            for (Tunnel tunnel : tunnelSet) {
+                print(FMT, tunnel.tunnelId().id(), tunnel.src().toString(), tunnel.dst().toString(),
+                      tunnel.type(), tunnel.state(), tunnel.providerId(),
+                      tunnel.tunnelName(), tunnel.groupId(),
+                      showPath(tunnel.path()),
+                      annotations(tunnel.annotations()));
+            }
+        }
+    }
+
+    private String showPath(Path path) {
+        if (path == null) {
+            return "null";
+        }
+        StringBuilder builder = new StringBuilder("(");
+        for (Link link : path.links()) {
+            builder.append("(DeviceId:" + link.src().deviceId() + " Port:"
+                    + link.src().port().toString());
+            builder.append(" DeviceId:" + link.dst().deviceId() + " Port:"
+                    + link.dst().port().toString() + ")");
+        }
+        builder.append(annotations(path.annotations()) + ")");
+        return builder.toString();
+    }
+
+    private boolean isNull(String s) {
+        return s == null || "".equals(s);
+    }
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelQuerySubscriptionCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelQuerySubscriptionCommand.java
new file mode 100644
index 0000000..bc6df51
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelQuerySubscriptionCommand.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.tunnel.cli;
+
+import java.util.Collection;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.DefaultApplicationId;
+import org.onosproject.incubator.net.tunnel.TunnelService;
+import org.onosproject.incubator.net.tunnel.TunnelSubscription;
+
+/**
+ * Query all tunnel subscriptions of consumer by consumer id.
+ * It's used by consumers.
+ */
+@Service
+@Command(scope = "onos", name = "tunnel-subscriptions",
+      description = "Query all request orders of consumer by consumer id. It's used by consumers.")
+public class TunnelQuerySubscriptionCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "consumerId",
+            description = "consumer id means provider id",
+            required = true, multiValued = false)
+    String consumerId = null;
+    private static final String FMT = "appId=%s, src=%s, dst=%s,"
+            + "type=%s, tunnelId=%s";
+
+    @Override
+    protected void doExecute() {
+        TunnelService service = get(TunnelService.class);
+        ApplicationId applicationId = new DefaultApplicationId(1, consumerId);
+        Collection<TunnelSubscription> tunnelSet = service.queryTunnelSubscription(applicationId);
+        for (TunnelSubscription order : tunnelSet) {
+            print(FMT, order.consumerId(), order.src(), order.dst(),
+                  order.type(), order.tunnelId());
+        }
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelRemoveCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelRemoveCommand.java
new file mode 100644
index 0000000..446d526
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelRemoveCommand.java
@@ -0,0 +1,205 @@
+/*
+ * 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.cli;
+
+import java.util.Collection;
+import java.util.Optional;
+
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.action.Option;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.OpticalLogicId;
+import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelDescription;
+import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelProvider;
+import org.onosproject.incubator.net.tunnel.TunnelService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * Supports for removing tunnels. It's used by producers.
+ */
+@Service
+@Command(scope = "onos", name = "tunnel-remove", description = "Supports for removing tunnels. It's used by producers.")
+public class TunnelRemoveCommand extends AbstractShellCommand {
+    @Option(name = "-s", aliases = "--src", description = "Source tunnel point."
+            + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
+            + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
+            + " Otherwise src means IP address.", required = false, multiValued = false)
+    String src = null;
+    @Option(name = "-d", aliases = "--dst", description = "Destination tunnel point."
+            + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
+            + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
+            + " Otherwise dst means IP address.", required = false, multiValued = false)
+    String dst = null;
+
+    @Option(name = "-t", aliases = "--type", description = "The type of tunnels,"
+            + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = false, multiValued = false)
+    String type = null;
+
+    @Option(name = "-i", aliases = "--tunnelId",
+            description = "the tunnel identity.", required = false, multiValued = false)
+    String tunnelId = null;
+
+    @Override
+    protected void doExecute() {
+        TunnelDescription tunnel = null;
+        TunnelProvider service = get(TunnelProvider.class);
+        ProviderId producerName = new ProviderId("default",
+                                                 "org.onosproject.provider.tunnel.default");
+        if (!isNull(src) && !isNull(dst) && !isNull(type)) {
+            TunnelEndPoint srcPoint = null;
+            TunnelEndPoint dstPoint = null;
+            Tunnel.Type trueType = null;
+            if ("MPLS".equals(type)) {
+                trueType = Tunnel.Type.MPLS;
+                srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(src));
+                dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(dst));
+            } else if ("VLAN".equals(type)) {
+                trueType = Tunnel.Type.VLAN;
+                srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(src));
+                dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(dst));
+            } else if ("VXLAN".equals(type)) {
+                trueType = Tunnel.Type.VXLAN;
+                srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(src));
+                dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(dst));
+            } else if ("GRE".equals(type)) {
+                trueType = Tunnel.Type.GRE;
+                srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(src));
+                dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(dst));
+            } else if ("ODUK".equals(type)) {
+                trueType = Tunnel.Type.ODUK;
+                String[] srcArray = src.split("/");
+                String[] dstArray = dst.split("/");
+                srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(srcArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(srcArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.LAMBDA,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+                dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(dstArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(dstArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.LAMBDA,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+            } else if ("OCH".equals(type)) {
+                trueType = Tunnel.Type.OCH;
+                String[] srcArray = src.split("/");
+                String[] dstArray = dst.split("/");
+                srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(srcArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(srcArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.LAMBDA,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+                dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(dstArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(dstArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.LAMBDA,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+            } else {
+                print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
+                return;
+            }
+
+            tunnel = new DefaultTunnelDescription(null, srcPoint, dstPoint,
+                                                  trueType, null, producerName,
+                                                  null, null);
+            service.tunnelRemoved(tunnel);
+            return;
+        }
+        if (!isNull(tunnelId)) {
+            TunnelId id = TunnelId.valueOf(tunnelId);
+            tunnel = new DefaultTunnelDescription(id, null, null, null, null,
+                                                  producerName, null, null);
+            service.tunnelRemoved(tunnel);
+            return;
+        }
+
+        if (!isNull(type)) {
+            Tunnel.Type trueType = null;
+            Collection<Tunnel> tunnelSet = null;
+            TunnelService tunnelService = get(TunnelService.class);
+            if ("MPLS".equals(type)) {
+                trueType = Tunnel.Type.MPLS;
+            } else if ("VLAN".equals(type)) {
+                trueType = Tunnel.Type.VLAN;
+            } else if ("VXLAN".equals(type)) {
+                trueType = Tunnel.Type.VXLAN;
+            } else if ("GRE".equals(type)) {
+                trueType = Tunnel.Type.GRE;
+            } else if ("ODUK".equals(type)) {
+                trueType = Tunnel.Type.ODUK;
+            } else if ("OCH".equals(type)) {
+                trueType = Tunnel.Type.OCH;
+            } else {
+                print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
+                return;
+            }
+            tunnelSet = tunnelService.queryTunnel(trueType);
+            if (tunnelSet != null) {
+                for (Tunnel tunnelTemp : tunnelSet) {
+                    tunnel = new DefaultTunnelDescription(tunnelTemp.tunnelId(), null, null, null, null,
+                                                          producerName, null, null);
+                    service.tunnelRemoved(tunnel);
+                }
+            }
+        }
+    }
+
+    private boolean isNull(String s) {
+        return s == null || "".equals(s);
+    }
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelReturnCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelReturnCommand.java
new file mode 100644
index 0000000..ce0f5c3
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelReturnCommand.java
@@ -0,0 +1,200 @@
+/*
+ * 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.cli;
+
+import java.util.Optional;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.action.Option;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.DefaultApplicationId;
+import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.OpticalLogicId;
+import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.incubator.net.tunnel.TunnelService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * Returns tunnels. It's used by consumers.
+ */
+@Service
+@Command(scope = "onos", name = "tunnel-return",
+description = "Returns tunnels. It's used by consumers.")
+public class TunnelReturnCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "consumerId",
+            description = "consumer id means application id.", required = true, multiValued = false)
+    String consumerId = null;
+
+    @Option(name = "-s", aliases = "--src", description = "Source tunnel point."
+            + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
+            + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
+            + " Otherwise src means IP address.", required = false, multiValued = false)
+    String src = null;
+
+    @Option(name = "-d", aliases = "--dst", description = "Destination tunnel point."
+            + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
+            + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
+            + " Otherwise dst means IP address.", required = false, multiValued = false)
+    String dst = null;
+
+    @Option(name = "-t", aliases = "--type", description = "The type of tunnels,"
+            + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = false, multiValued = false)
+    String type = null;
+
+    @Option(name = "-i", aliases = "--tunnelId",
+            description = "the tunnel identity.", required = false, multiValued = false)
+    String tunnelId = null;
+
+    @Option(name = "-n", aliases = "--tunnelName",
+            description = "The name of tunnels", required = false, multiValued = false)
+    String tunnelName = null;
+
+    @Override
+    protected void doExecute() {
+        Tunnel.Type trueType = null;
+        TunnelService service = get(TunnelService.class);
+        ApplicationId appId = new DefaultApplicationId(1, consumerId);
+        ProviderId producerName = new ProviderId("default",
+                                                 "org.onosproject.provider.tunnel.default");
+        if (!isNull(src) && !isNull(dst) && !isNull(type)) {
+            TunnelEndPoint srcPoint = null;
+            TunnelEndPoint dstPoint = null;
+            if ("MPLS".equals(type)) {
+                trueType = Tunnel.Type.MPLS;
+                srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(src));
+                dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(dst));
+            } else if ("VXLAN".equals(type)) {
+                trueType = Tunnel.Type.VXLAN;
+                srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(src));
+                dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(dst));
+            } else if ("GRE".equals(type)) {
+                trueType = Tunnel.Type.GRE;
+                srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(src));
+                dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                        .valueOf(dst));
+            } else if ("VLAN".equals(type)) {
+                trueType = Tunnel.Type.VLAN;
+                String[] srcArray = src.split("-");
+                String[] dstArray = dst.split("-");
+                srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(srcArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(srcArray[1])),
+                                                            null,
+                                                            null,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+                dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(dstArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(dstArray[1])),
+                                                            null,
+                                                            null,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+            } else if ("ODUK".equals(type)) {
+                trueType = Tunnel.Type.ODUK;
+                String[] srcArray = src.split("-");
+                String[] dstArray = dst.split("-");
+                srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(srcArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(srcArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.LAMBDA,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+                dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(dstArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(dstArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.LAMBDA,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+            } else if ("OCH".equals(type)) {
+                trueType = Tunnel.Type.OCH;
+                String[] srcArray = src.split("-");
+                String[] dstArray = dst.split("-");
+                srcPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(srcArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(srcArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.TIMESLOT,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+                dstPoint = new DefaultOpticalTunnelEndPoint(
+                                                            producerName,
+                                                            Optional.of(DeviceId
+                                                                    .deviceId(dstArray[0])),
+                                                            Optional.of(PortNumber
+                                                                    .portNumber(dstArray[1])),
+                                                            null,
+                                                            OpticalTunnelEndPoint.Type.TIMESLOT,
+                                                            OpticalLogicId
+                                                                    .logicId(0),
+                                                            true);
+            } else {
+                print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
+                return;
+            }
+            service.returnTunnel(appId, srcPoint, dstPoint, trueType);
+        }
+        if (!isNull(tunnelId)) {
+            TunnelId id = TunnelId.valueOf(tunnelId);
+            service.returnTunnel(appId, id);
+        }
+        if (!isNull(tunnelName)) {
+            TunnelName name = TunnelName.tunnelName(tunnelName);
+            service.returnTunnel(appId, name);
+        }
+    }
+    private boolean isNull(String s) {
+        return s == null || "".equals(s);
+    }
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelUpdateCommand.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelUpdateCommand.java
new file mode 100644
index 0000000..601281a
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/TunnelUpdateCommand.java
@@ -0,0 +1,63 @@
+/*
+ * 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.cli;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.action.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription;
+import org.onosproject.incubator.net.tunnel.TunnelDescription;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelProvider;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.SparseAnnotations;
+
+/**
+ * Supports for updating a tunnel by tunnel identity.
+ * It's used by producers.
+ */
+@Service
+@Command(scope = "onos", name = "tunnel-update",
+description = "Supports for updating a tunnel by tunnel identity."
+        + " It's used by producers.")
+public class TunnelUpdateCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "tunnelId", description = "the tunnel identity.",
+            required = true, multiValued = false)
+    String tunnelId = null;
+
+    @Option(name = "-b", aliases = "--bandwidth",
+            description = "The bandwidth attribute of tunnel", required = false, multiValued = false)
+    String bandwidth = null;
+
+    @Override
+    protected void doExecute() {
+        TunnelProvider service = get(TunnelProvider.class);
+        TunnelId id = TunnelId.valueOf(tunnelId);
+        SparseAnnotations annotations = DefaultAnnotations
+                .builder()
+                .set("bandwidth", bandwidth)
+                .build();
+        TunnelDescription tunnel = new DefaultTunnelDescription(id, null,
+                                                                null,
+                                                                null, null,
+                                                                null,
+                                                                null, null, annotations);
+        service.tunnelUpdated(tunnel);
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/package-info.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/package-info.java
new file mode 100644
index 0000000..8980c62
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/cli/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.
+ */
+
+/**
+ * CLIs for the tunnel subsystem.
+ */
+package org.onosproject.incubator.net.tunnel.cli;
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/impl/TunnelManager.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/impl/TunnelManager.java
new file mode 100644
index 0000000..623d005
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/impl/TunnelManager.java
@@ -0,0 +1,446 @@
+/*
+ * 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.impl;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.incubator.net.tunnel.DefaultTunnel;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.Tunnel.State;
+import org.onosproject.incubator.net.tunnel.Tunnel.Type;
+import org.onosproject.incubator.net.tunnel.TunnelAdminService;
+import org.onosproject.incubator.net.tunnel.TunnelDescription;
+import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.TunnelEvent;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelListener;
+import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.incubator.net.tunnel.TunnelProvider;
+import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry;
+import org.onosproject.incubator.net.tunnel.TunnelProviderService;
+import org.onosproject.incubator.net.tunnel.TunnelService;
+import org.onosproject.incubator.net.tunnel.TunnelStore;
+import org.onosproject.incubator.net.tunnel.TunnelStoreDelegate;
+import org.onosproject.incubator.net.tunnel.TunnelSubscription;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.ElementId;
+import org.onosproject.net.Path;
+import org.onosproject.net.provider.AbstractListenerProviderRegistry;
+import org.onosproject.net.provider.AbstractProviderService;
+import org.onosproject.net.provider.ProviderId;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Provides implementation of the tunnel NB/SB APIs.
+ */
+@Component(immediate = true, service = {TunnelService.class, TunnelAdminService.class, TunnelProviderRegistry.class})
+public class TunnelManager
+        extends AbstractListenerProviderRegistry<TunnelEvent, TunnelListener,
+                                                 TunnelProvider, TunnelProviderService>
+        implements TunnelService, TunnelAdminService, TunnelProviderRegistry {
+
+    private static final String TUNNNEL_ID_NULL = "Tunnel ID cannot be null";
+    private static final String TUNNNEL_NULL = "Tunnel cannot be null";
+
+    private final Logger log = getLogger(getClass());
+
+    private final TunnelStoreDelegate delegate = new InternalStoreDelegate();
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected TunnelStore store;
+
+
+    @Activate
+    public void activate() {
+        store.setDelegate(delegate);
+        eventDispatcher.addSink(TunnelEvent.class, listenerRegistry);
+        log.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        store.unsetDelegate(delegate);
+        eventDispatcher.removeSink(TunnelEvent.class);
+        log.info("Stopped");
+    }
+
+    @Override
+    public void removeTunnel(TunnelId tunnelId) {
+        checkNotNull(tunnelId, TUNNNEL_ID_NULL);
+        Tunnel tunnel = store.queryTunnel(tunnelId);
+        if (tunnel != null) {
+            store.deleteTunnel(tunnelId);
+            if (tunnel.providerId() != null) {
+                TunnelProvider provider = getProvider(tunnel.providerId());
+                if (provider != null) {
+                    provider.releaseTunnel(tunnel);
+                }
+            } else {
+                Set<ProviderId> ids = getProviders();
+                for (ProviderId providerId : ids) {
+                    TunnelProvider provider = getProvider(providerId);
+                    provider.releaseTunnel(tunnel);
+                }
+            }
+        }
+    }
+
+    @Override
+    public void updateTunnel(Tunnel tunnel, Path path) {
+        store.createOrUpdateTunnel(tunnel);
+        if (tunnel.providerId() != null) {
+            TunnelProvider provider = getProvider(tunnel.providerId());
+            if (provider != null) {
+                provider.updateTunnel(tunnel, path);
+            }
+        } else {
+            Set<ProviderId> ids = getProviders();
+            for (ProviderId providerId : ids) {
+                TunnelProvider provider = getProvider(providerId);
+                provider.updateTunnel(tunnel, path);
+            }
+        }
+    }
+
+    @Override
+    public void updateTunnelState(Tunnel tunnel, State state) {
+        Tunnel storedTunnel = store.queryTunnel(tunnel.tunnelId());
+        store.createOrUpdateTunnel(storedTunnel, state);
+    }
+
+    @Override
+    public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst,
+                              ProviderId producerName) {
+        Collection<Tunnel> setTunnels = store.queryTunnel(src, dst);
+        if (!setTunnels.isEmpty()) {
+            store.deleteTunnel(src, dst, producerName);
+            for (Tunnel tunnel : setTunnels) {
+                if (producerName != null
+                        && !tunnel.providerId().equals(producerName)) {
+                    continue;
+                }
+                if (tunnel.providerId() != null) {
+                    TunnelProvider provider = getProvider(tunnel.providerId());
+                    if (provider != null) {
+                        provider.releaseTunnel(tunnel);
+                    }
+                } else {
+                    Set<ProviderId> ids = getProviders();
+                    for (ProviderId providerId : ids) {
+                        TunnelProvider provider = getProvider(providerId);
+                        provider.releaseTunnel(tunnel);
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type,
+                              ProviderId producerName) {
+        Collection<Tunnel> setTunnels = store.queryTunnel(src, dst);
+        if (!setTunnels.isEmpty()) {
+            store.deleteTunnel(src, dst, type, producerName);
+            for (Tunnel tunnel : setTunnels) {
+                if (producerName != null
+                        && !tunnel.providerId().equals(producerName)
+                        || !type.equals(tunnel.type())) {
+                    continue;
+                }
+                if (tunnel.providerId() != null) {
+                    TunnelProvider provider = getProvider(tunnel.providerId());
+                    if (provider != null) {
+                        provider.releaseTunnel(tunnel);
+                    }
+                } else {
+                    Set<ProviderId> ids = getProviders();
+                    for (ProviderId providerId : ids) {
+                        TunnelProvider provider = getProvider(providerId);
+                        provider.releaseTunnel(tunnel);
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    public Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId,
+                                  Annotations... annotations) {
+        return store.borrowTunnel(consumerId, tunnelId, annotations);
+    }
+
+    @Override
+    public Collection<Tunnel> borrowTunnel(ApplicationId consumerId,
+                                              TunnelName tunnelName,
+                                              Annotations... annotations) {
+        return store.borrowTunnel(consumerId, tunnelName, annotations);
+    }
+
+    @Override
+    public Collection<Tunnel> borrowTunnel(ApplicationId consumerId,
+                                              TunnelEndPoint src, TunnelEndPoint dst,
+                                              Annotations... annotations) {
+        Collection<Tunnel> tunnels = store.borrowTunnel(consumerId, src,
+                                                           dst, annotations);
+        if (tunnels == null || tunnels.isEmpty()) {
+            Tunnel tunnel = new DefaultTunnel(null, src, dst, null, null, null,
+                                              null, null, annotations);
+            Set<ProviderId> ids = getProviders();
+            for (ProviderId providerId : ids) {
+                TunnelProvider provider = getProvider(providerId);
+                provider.setupTunnel(tunnel, null);
+            }
+        }
+        return tunnels;
+    }
+
+    @Override
+    public Collection<Tunnel> borrowTunnel(ApplicationId consumerId,
+                                              TunnelEndPoint src, TunnelEndPoint dst,
+                                              Type type, Annotations... annotations) {
+        Collection<Tunnel> tunnels = store.borrowTunnel(consumerId, src,
+                                                           dst, type,
+                                                           annotations);
+        if (tunnels == null || tunnels.isEmpty()) {
+            Tunnel tunnel = new DefaultTunnel(null, src, dst, type, null, null,
+                                              null, null, annotations);
+            Set<ProviderId> ids = getProviders();
+            for (ProviderId providerId : ids) {
+                TunnelProvider provider = getProvider(providerId);
+                provider.setupTunnel(tunnel, null);
+            }
+        }
+        return tunnels;
+    }
+
+    @Override
+    public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
+        // TODO: producerId to check if really required to consider while setup the tunnel.
+        checkNotNull(tunnel, TUNNNEL_NULL);
+        TunnelId tunnelId = store.createOrUpdateTunnel(tunnel, State.INIT);
+        if (tunnelId != null) {
+            Set<ProviderId> ids = getProviders();
+            Tunnel newT = queryTunnel(tunnelId);
+            for (ProviderId providerId : ids) {
+                TunnelProvider provider = getProvider(providerId);
+                provider.setupTunnel(srcElementId, newT, path);
+            }
+        }
+        return tunnelId;
+    }
+
+    @Override
+    public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) {
+        // TODO: producerId to check if really required to consider while deleting the tunnel.
+        checkNotNull(tunnelId, TUNNNEL_ID_NULL);
+        Tunnel tunnel = store.queryTunnel(tunnelId);
+        if (tunnel != null) {
+            TunnelId updtTunnelId = store.createOrUpdateTunnel(tunnel, State.INACTIVE);
+            if (updtTunnelId != null) {
+                Set<ProviderId> ids = getProviders();
+                for (ProviderId providerId : ids) {
+                    TunnelProvider provider = getProvider(providerId);
+                    provider.releaseTunnel(tunnel);
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public boolean returnTunnel(ApplicationId consumerId,
+                                     TunnelId tunnelId, Annotations... annotations) {
+        return store.returnTunnel(consumerId, tunnelId, annotations);
+    }
+
+    @Override
+    public boolean returnTunnel(ApplicationId consumerId,
+                                     TunnelName tunnelName,
+                                     Annotations... annotations) {
+        return store.returnTunnel(consumerId, tunnelName, annotations);
+    }
+
+    @Override
+    public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src,
+                                     TunnelEndPoint dst, Type type,
+                                     Annotations... annotations) {
+        return store.returnTunnel(consumerId, src, dst, type, annotations);
+    }
+
+    @Override
+    public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src,
+                                     TunnelEndPoint dst, Annotations... annotations) {
+        return store.returnTunnel(consumerId, src, dst, annotations);
+    }
+
+    @Override
+    public Tunnel queryTunnel(TunnelId tunnelId) {
+        return store.queryTunnel(tunnelId);
+    }
+
+    @Override
+    public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId consumerId) {
+        return store.queryTunnelSubscription(consumerId);
+    }
+
+    @Override
+    public Collection<Tunnel> queryTunnel(Type type) {
+        return store.queryTunnel(type);
+    }
+
+    @Override
+    public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
+        return store.queryTunnel(src, dst);
+    }
+
+
+    @Override
+    public Collection<Tunnel> queryAllTunnels() {
+        return store.queryAllTunnels();
+    }
+
+    @Override
+    public int tunnelCount() {
+        return store.tunnelCount();
+    }
+
+    @Override
+    protected TunnelProviderService createProviderService(TunnelProvider provider) {
+        return new InternalTunnelProviderService(provider);
+    }
+
+    private class InternalTunnelProviderService
+            extends AbstractProviderService<TunnelProvider>
+            implements TunnelProviderService {
+        protected InternalTunnelProviderService(TunnelProvider provider) {
+            super(provider);
+        }
+
+
+        @Override
+        public TunnelId tunnelAdded(TunnelDescription tunnel) {
+            Tunnel storedTunnel = new DefaultTunnel(provider().id(),
+                                                    tunnel.src(), tunnel.dst(),
+                                                    tunnel.type(),
+                                                    tunnel.groupId(),
+                                                    tunnel.id(),
+                                                    tunnel.tunnelName(),
+                                                    tunnel.path(),
+                                                    tunnel.resource(),
+                                                    tunnel.annotations());
+            return store.createOrUpdateTunnel(storedTunnel);
+        }
+
+        @Override
+        public TunnelId tunnelAdded(TunnelDescription tunnel, State state) {
+            Tunnel storedTunnel = new DefaultTunnel(provider().id(),
+                                                    tunnel.src(), tunnel.dst(),
+                                                    tunnel.type(),
+                                                    state,
+                                                    tunnel.groupId(),
+                                                    tunnel.id(),
+                                                    tunnel.tunnelName(),
+                                                    tunnel.path(),
+                                                    tunnel.resource(),
+                                                    tunnel.annotations());
+            return store.createOrUpdateTunnel(storedTunnel);
+        }
+
+        @Override
+        public void tunnelUpdated(TunnelDescription tunnel) {
+            Tunnel storedTunnel = new DefaultTunnel(provider().id(),
+                                                    tunnel.src(), tunnel.dst(),
+                                                    tunnel.type(),
+                                                    tunnel.groupId(),
+                                                    tunnel.id(),
+                                                    tunnel.tunnelName(),
+                                                    tunnel.path(),
+                                                    tunnel.resource(),
+                                                    tunnel.annotations());
+            store.createOrUpdateTunnel(storedTunnel);
+        }
+
+        @Override
+        public void tunnelUpdated(TunnelDescription tunnel, State state) {
+            Tunnel storedTunnel = new DefaultTunnel(provider().id(),
+                                                    tunnel.src(), tunnel.dst(),
+                                                    tunnel.type(),
+                                                    state,
+                                                    tunnel.groupId(),
+                                                    tunnel.id(),
+                                                    tunnel.tunnelName(),
+                                                    tunnel.path(),
+                                                    tunnel.resource(),
+                                                    tunnel.annotations());
+            store.createOrUpdateTunnel(storedTunnel, state);
+        }
+
+        @Override
+        public void tunnelRemoved(TunnelDescription tunnel) {
+            if (tunnel.id() != null) {
+                store.deleteTunnel(tunnel.id());
+                return;
+            }
+            if (tunnel.src() != null && tunnel.dst() != null
+                    && tunnel.type() != null) {
+                store.deleteTunnel(tunnel.src(), tunnel.dst(), tunnel.type(),
+                                   provider().id());
+                return;
+            }
+            if (tunnel.src() != null && tunnel.dst() != null
+                    && tunnel.type() == null) {
+                store.deleteTunnel(tunnel.src(), tunnel.dst(), provider().id());
+                return;
+            }
+        }
+
+
+        @Override
+        public Tunnel tunnelQueryById(TunnelId tunnelId) {
+            return store.queryTunnel(tunnelId);
+        }
+
+
+    }
+
+    private class InternalStoreDelegate implements TunnelStoreDelegate {
+        @Override
+        public void notify(TunnelEvent event) {
+            if (event != null) {
+                post(event);
+            }
+        }
+    }
+
+    @Override
+    public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
+        return Collections.emptyList();
+    }
+
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/impl/package-info.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/impl/package-info.java
new file mode 100644
index 0000000..5926b0a
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/impl/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.
+ */
+
+/**
+ * Core subsystem for tracking global inventory of tunnels.
+ */
+package org.onosproject.incubator.net.tunnel.impl;
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/store/impl/DistributedTunnelStore.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/store/impl/DistributedTunnelStore.java
new file mode 100644
index 0000000..3bf5e35
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/store/impl/DistributedTunnelStore.java
@@ -0,0 +1,583 @@
+/*
+ * 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.store.impl;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.incubator.net.tunnel.DefaultTunnel;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.Tunnel.State;
+import org.onosproject.incubator.net.tunnel.Tunnel.Type;
+import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.TunnelEvent;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.incubator.net.tunnel.TunnelStore;
+import org.onosproject.incubator.net.tunnel.TunnelStoreDelegate;
+import org.onosproject.incubator.net.tunnel.TunnelSubscription;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.store.AbstractStore;
+import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.EventuallyConsistentMap;
+import org.onosproject.store.service.EventuallyConsistentMapEvent;
+import org.onosproject.store.service.EventuallyConsistentMapListener;
+import org.onosproject.store.service.MultiValuedTimestamp;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.WallClockTimestamp;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT;
+import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Manages inventory of tunnel in distributed data store that uses optimistic
+ * replication and gossip based techniques.
+ */
+@Component(immediate = true, service = TunnelStore.class)
+public class DistributedTunnelStore
+        extends AbstractStore<TunnelEvent, TunnelStoreDelegate>
+        implements TunnelStore {
+
+    private final Logger log = getLogger(getClass());
+
+    /**
+     * The topic used for obtaining globally unique ids.
+     */
+    private String tunnelOpTopic = "tunnel-ops-ids";
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected ClusterCommunicationService clusterCommunicator;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected ClusterService clusterService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected CoreService coreService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY)
+    protected StorageService storageService;
+
+    // tunnel identity as map key in the store.
+    private EventuallyConsistentMap<TunnelId, Tunnel> tunnelIdAsKeyStore;
+    // maintains records that app subscribes tunnel.
+    private EventuallyConsistentMap<ApplicationId, Set<TunnelSubscription>> orderRelationship;
+
+    // tunnel name as map key.
+    private final Map<TunnelName, Set<TunnelId>> tunnelNameAsKeyMap = Maps.newConcurrentMap();
+    // maintains all the tunnels between source and destination.
+    private final Map<TunnelKey, Set<TunnelId>> srcAndDstKeyMap = Maps.newConcurrentMap();
+    // maintains all the tunnels by tunnel type.
+    private final Map<Tunnel.Type, Set<TunnelId>> typeKeyMap = Maps.newConcurrentMap();
+
+    private IdGenerator idGenerator;
+
+    private EventuallyConsistentMapListener<TunnelId, Tunnel> tunnelUpdateListener =
+            new InternalTunnelChangeEventListener();
+
+    @Activate
+    public void activate() {
+        KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
+                .register(KryoNamespaces.API)
+                .register(MultiValuedTimestamp.class);
+        tunnelIdAsKeyStore = storageService
+                .<TunnelId, Tunnel>eventuallyConsistentMapBuilder()
+                .withName("all_tunnel").withSerializer(serializer)
+                .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
+        orderRelationship = storageService
+                .<ApplicationId, Set<TunnelSubscription>>eventuallyConsistentMapBuilder()
+                .withName("type_tunnel").withSerializer(serializer)
+                .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
+        idGenerator = coreService.getIdGenerator(tunnelOpTopic);
+        tunnelIdAsKeyStore.addListener(tunnelUpdateListener);
+        log.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        tunnelIdAsKeyStore.removeListener(tunnelUpdateListener);
+        orderRelationship.destroy();
+        tunnelIdAsKeyStore.destroy();
+        srcAndDstKeyMap.clear();
+        typeKeyMap.clear();
+        tunnelNameAsKeyMap.clear();
+        log.info("Stopped");
+    }
+
+    @Override
+    public TunnelId createOrUpdateTunnel(Tunnel tunnel) {
+        return handleCreateOrUpdateTunnel(tunnel, null);
+    }
+
+    @Override
+    public TunnelId createOrUpdateTunnel(Tunnel tunnel, State state) {
+        return handleCreateOrUpdateTunnel(tunnel, state);
+    }
+
+    private TunnelId handleCreateOrUpdateTunnel(Tunnel tunnel, State state) {
+        // tunnelIdAsKeyStore.
+        if (tunnel.tunnelId() != null && !"".equals(tunnel.tunnelId().toString())) {
+            Tunnel old = tunnelIdAsKeyStore.get(tunnel.tunnelId());
+            if (old == null) {
+                log.info("This tunnel[" + tunnel.tunnelId() + "] is not available.");
+                return tunnel.tunnelId();
+            }
+            DefaultAnnotations oldAnno = (DefaultAnnotations) old.annotations();
+            SparseAnnotations newAnno = (SparseAnnotations) tunnel.annotations();
+            State newTunnelState = (state != null) ? state : old.state();
+            Tunnel newT = new DefaultTunnel(old.providerId(), old.src(),
+                                            old.dst(), old.type(),
+                                            newTunnelState, old.groupId(),
+                                            old.tunnelId(),
+                                            old.tunnelName(),
+                                            old.path(),
+                                            old.resource(),
+                                            DefaultAnnotations.merge(oldAnno, newAnno));
+            tunnelIdAsKeyStore.put(tunnel.tunnelId(), newT);
+            TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED,
+                                                tunnel);
+            notifyDelegate(event);
+            return tunnel.tunnelId();
+        } else {
+            TunnelId tunnelId = TunnelId.valueOf(String.valueOf(idGenerator.getNewId()));
+            State tunnelState = (state != null) ? state : tunnel.state();
+            Tunnel newT = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
+                                            tunnel.dst(), tunnel.type(),
+                                            tunnelState, tunnel.groupId(),
+                                            tunnelId,
+                                            tunnel.tunnelName(),
+                                            tunnel.path(),
+                                            tunnel.resource(),
+                                            tunnel.annotations());
+            tunnelIdAsKeyStore.put(tunnelId, newT);
+
+            TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED,
+                                                tunnel);
+            notifyDelegate(event);
+            return tunnelId;
+        }
+    }
+
+    @Override
+    public void deleteTunnel(TunnelId tunnelId) {
+        Tunnel deletedTunnel = tunnelIdAsKeyStore.get(tunnelId);
+        if (deletedTunnel == null) {
+            return;
+        }
+
+        tunnelIdAsKeyStore.remove(tunnelId);
+
+        TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED,
+                                            deletedTunnel);
+        notifyDelegate(event);
+    }
+
+    @Override
+    public void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst,
+                             ProviderId producerName) {
+        TunnelKey key = TunnelKey.tunnelKey(src, dst);
+        Set<TunnelId> idSet = srcAndDstKeyMap.get(key);
+        if (idSet == null) {
+            return;
+        }
+        Tunnel deletedTunnel = null;
+        TunnelEvent event = null;
+        List<TunnelEvent> ls = new ArrayList<TunnelEvent>();
+        for (TunnelId id : idSet) {
+            deletedTunnel = tunnelIdAsKeyStore.get(id);
+
+            if (producerName == null || producerName.equals(deletedTunnel.providerId())) {
+                tunnelIdAsKeyStore.remove(deletedTunnel.tunnelId());
+
+                event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED,
+                                        deletedTunnel);
+                ls.add(event);
+            }
+        }
+
+        if (!ls.isEmpty()) {
+            notifyDelegate(ls);
+        }
+    }
+
+    @Override
+    public void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst, Type type,
+                             ProviderId producerName) {
+        TunnelKey key = TunnelKey.tunnelKey(src, dst);
+        Set<TunnelId> idSet = srcAndDstKeyMap.get(key);
+        if (idSet == null) {
+            return;
+        }
+        Tunnel deletedTunnel = null;
+        TunnelEvent event = null;
+        List<TunnelEvent> ls = new ArrayList<TunnelEvent>();
+        for (TunnelId id : idSet) {
+            deletedTunnel = tunnelIdAsKeyStore.get(id);
+
+            if (type.equals(deletedTunnel.type()) && (producerName == null ||
+                    producerName.equals(deletedTunnel.providerId()))) {
+                tunnelIdAsKeyStore.remove(deletedTunnel.tunnelId());
+
+                event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED,
+                                        deletedTunnel);
+                ls.add(event);
+            }
+        }
+
+        if (!ls.isEmpty()) {
+            notifyDelegate(ls);
+        }
+    }
+
+    @Override
+    public Tunnel borrowTunnel(ApplicationId appId, TunnelId tunnelId,
+                               Annotations... annotations) {
+        Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
+        if (orderSet == null) {
+            orderSet = new HashSet<TunnelSubscription>();
+        }
+        TunnelSubscription order = new TunnelSubscription(appId, null, null, tunnelId, null, null,
+                                annotations);
+        Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
+        if (result == null || Tunnel.State.INACTIVE.equals(result.state())) {
+            return null;
+        }
+
+        orderSet.add(order);
+        orderRelationship.put(appId, orderSet);
+        return result;
+    }
+
+    @Override
+    public Collection<Tunnel> borrowTunnel(ApplicationId appId,
+                                           TunnelEndPoint src,
+                                           TunnelEndPoint dst,
+                                           Annotations... annotations) {
+        Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
+        if (orderSet == null) {
+            orderSet = new HashSet<TunnelSubscription>();
+        }
+        TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, null, null, annotations);
+        boolean isExist = orderSet.contains(order);
+        if (!isExist) {
+            orderSet.add(order);
+        }
+        orderRelationship.put(appId, orderSet);
+        TunnelKey key = TunnelKey.tunnelKey(src, dst);
+        Set<TunnelId> idSet = srcAndDstKeyMap.get(key);
+        if (idSet == null || idSet.isEmpty()) {
+            return Collections.emptySet();
+        }
+        Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
+        for (TunnelId tunnelId : idSet) {
+            Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
+            if (Tunnel.State.ACTIVE.equals(result.state())) {
+                tunnelSet.add(result);
+            }
+        }
+        return tunnelSet;
+    }
+
+    @Override
+    public Collection<Tunnel> borrowTunnel(ApplicationId appId,
+                                           TunnelEndPoint src,
+                                           TunnelEndPoint dst, Type type,
+                                           Annotations... annotations) {
+        Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
+        if (orderSet == null) {
+            orderSet = new HashSet<TunnelSubscription>();
+        }
+        TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, type, null, annotations);
+        boolean isExist = orderSet.contains(order);
+        if (!isExist) {
+            orderSet.add(order);
+        }
+        orderRelationship.put(appId, orderSet);
+        TunnelKey key = TunnelKey.tunnelKey(src, dst);
+        Set<TunnelId> idSet = srcAndDstKeyMap.get(key);
+        if (idSet == null || idSet.isEmpty()) {
+            return Collections.emptySet();
+        }
+        Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
+        for (TunnelId tunnelId : idSet) {
+            Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
+            if (type.equals(result.type())
+                    && Tunnel.State.ACTIVE.equals(result.state())) {
+                tunnelSet.add(result);
+            }
+        }
+        return tunnelSet;
+    }
+
+    @Override
+    public Collection<Tunnel> borrowTunnel(ApplicationId appId,
+                                           TunnelName tunnelName,
+                                           Annotations... annotations) {
+        Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
+        if (orderSet == null) {
+            orderSet = new HashSet<TunnelSubscription>();
+        }
+        TunnelSubscription order = new TunnelSubscription(appId, null, null, null, null, tunnelName,
+                                annotations);
+        boolean isExist = orderSet.contains(order);
+
+        Set<TunnelId> idSet = tunnelNameAsKeyMap.get(tunnelName);
+        if (idSet == null || idSet.isEmpty()) {
+            return Collections.emptySet();
+        }
+        Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
+        for (TunnelId tunnelId : idSet) {
+            Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
+            if (Tunnel.State.ACTIVE.equals(result.state())) {
+                tunnelSet.add(result);
+            }
+        }
+
+        if (!tunnelSet.isEmpty() && !isExist) {
+            orderSet.add(order);
+            orderRelationship.put(appId, orderSet);
+        }
+
+        return tunnelSet;
+    }
+
+    @Override
+    public boolean returnTunnel(ApplicationId appId, TunnelName tunnelName,
+                                Annotations... annotations) {
+        TunnelSubscription order = new TunnelSubscription(appId, null, null, null, null, tunnelName,
+                                annotations);
+        return deleteOrder(order);
+    }
+
+    @Override
+    public boolean returnTunnel(ApplicationId appId, TunnelId tunnelId,
+                                Annotations... annotations) {
+        TunnelSubscription order = new TunnelSubscription(appId, null, null, tunnelId, null, null,
+                                annotations);
+        return deleteOrder(order);
+    }
+
+    @Override
+    public boolean returnTunnel(ApplicationId appId, TunnelEndPoint src,
+                                TunnelEndPoint dst, Type type,
+                                Annotations... annotations) {
+        TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, type, null, annotations);
+        return deleteOrder(order);
+    }
+
+    @Override
+    public boolean returnTunnel(ApplicationId appId, TunnelEndPoint src,
+                                TunnelEndPoint dst, Annotations... annotations) {
+        TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, null, null, annotations);
+        return deleteOrder(order);
+    }
+
+    private boolean deleteOrder(TunnelSubscription order) {
+        Set<TunnelSubscription> orderSet = orderRelationship.get(order.consumerId());
+        if (orderSet == null) {
+            return true;
+        }
+        if (orderSet.contains(order)) {
+            orderSet.remove(order);
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public Tunnel queryTunnel(TunnelId tunnelId) {
+        return tunnelIdAsKeyStore.get(tunnelId);
+    }
+
+    @Override
+    public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId appId) {
+        return orderRelationship.get(appId) != null ? ImmutableSet.copyOf(orderRelationship
+                .get(appId)) : Collections.emptySet();
+    }
+
+    @Override
+    public Collection<Tunnel> queryTunnel(Type type) {
+        Collection<Tunnel> result = new HashSet<Tunnel>();
+        Set<TunnelId> tunnelIds = typeKeyMap.get(type);
+        if (tunnelIds == null) {
+            return Collections.emptySet();
+        }
+        for (TunnelId id : tunnelIds) {
+            result.add(tunnelIdAsKeyStore.get(id));
+        }
+        return result.isEmpty() ? Collections.emptySet() : ImmutableSet
+                .copyOf(result);
+    }
+
+    @Override
+    public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
+        Collection<Tunnel> result = new HashSet<Tunnel>();
+        TunnelKey key = TunnelKey.tunnelKey(src, dst);
+        Set<TunnelId> tunnelIds = srcAndDstKeyMap.get(key);
+        if (tunnelIds == null) {
+            return Collections.emptySet();
+        }
+        for (TunnelId id : tunnelIds) {
+            result.add(tunnelIdAsKeyStore.get(id));
+        }
+        return result.isEmpty() ? Collections.emptySet() : ImmutableSet
+                .copyOf(result);
+    }
+
+    @Override
+    public Collection<Tunnel> queryAllTunnels() {
+        return tunnelIdAsKeyStore.values();
+    }
+
+    @Override
+    public int tunnelCount() {
+        return tunnelIdAsKeyStore.size();
+    }
+
+    /**
+     * Uses source TunnelPoint and destination TunnelPoint as map key.
+     */
+    private static final class TunnelKey {
+        private final TunnelEndPoint src;
+        private final TunnelEndPoint dst;
+
+        private TunnelKey(TunnelEndPoint src, TunnelEndPoint dst) {
+            this.src = src;
+            this.dst = dst;
+
+        }
+
+        /**
+         * create a map key.
+         *
+         * @param src
+         * @param dst
+         * @return a key using source ip and destination ip
+         */
+        static TunnelKey tunnelKey(TunnelEndPoint src, TunnelEndPoint dst) {
+            return new TunnelKey(src, dst);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(src, dst);
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj instanceof TunnelKey) {
+                final TunnelKey other = (TunnelKey) obj;
+                return Objects.equals(this.src, other.src)
+                        && Objects.equals(this.dst, other.dst);
+            }
+            return false;
+        }
+
+        @Override
+        public String toString() {
+            return MoreObjects.toStringHelper(getClass()).add("src", src)
+                    .add("dst", dst).toString();
+        }
+    }
+
+    /**
+     * Eventually consistent map listener for tunnel change event which updated the local map based on event.
+     */
+    private class InternalTunnelChangeEventListener
+            implements EventuallyConsistentMapListener<TunnelId, Tunnel> {
+        @Override
+        public void event(EventuallyConsistentMapEvent<TunnelId, Tunnel> event) {
+            TunnelId tunnelId = event.key();
+            Tunnel tunnel = event.value();
+
+            if (event.type() == PUT) {
+
+                // Update tunnel name map
+                Set<TunnelId> tunnelNameSet = tunnelNameAsKeyMap.get(tunnel
+                        .tunnelName());
+                if (tunnelNameSet == null) {
+                    tunnelNameSet = new HashSet<TunnelId>();
+                }
+                tunnelNameSet.add(tunnelId);
+                tunnelNameAsKeyMap.put(tunnel.tunnelName(), tunnelNameSet);
+
+                // Update tunnel source and destination map
+                TunnelKey key = TunnelKey.tunnelKey(tunnel.src(), tunnel.dst());
+                Set<TunnelId> srcAndDstKeySet = srcAndDstKeyMap.get(key);
+                if (srcAndDstKeySet == null) {
+                    srcAndDstKeySet = new HashSet<TunnelId>();
+                }
+                srcAndDstKeySet.add(tunnelId);
+                srcAndDstKeyMap.put(key, srcAndDstKeySet);
+
+                // Update tunnel type map
+                Set<TunnelId> typeKeySet = typeKeyMap.get(tunnel.type());
+                if (typeKeySet == null) {
+                    typeKeySet = new HashSet<TunnelId>();
+                }
+                typeKeySet.add(tunnelId);
+                typeKeyMap.put(tunnel.type(), typeKeySet);
+            } else if (event.type() == REMOVE) {
+
+                // Update tunnel name map
+                tunnelNameAsKeyMap.get(tunnel.tunnelName()).remove(tunnelId);
+                if (tunnelNameAsKeyMap.get(tunnel.tunnelName()).isEmpty()) {
+                    tunnelNameAsKeyMap.remove(tunnel.tunnelName());
+                }
+
+                // Update tunnel source and destination map
+                TunnelKey key = TunnelKey.tunnelKey(tunnel.src(), tunnel.dst());
+                srcAndDstKeyMap.get(key).remove(tunnelId);
+                if (srcAndDstKeyMap.get(key).isEmpty()) {
+                    srcAndDstKeyMap.remove(key);
+                }
+
+                // Update tunnel type map
+                typeKeyMap.get(tunnel.type()).remove(tunnelId);
+                if (typeKeyMap.get(tunnel.type()).isEmpty()) {
+                    typeKeyMap.remove(tunnel.type());
+                }
+            }
+        }
+    }
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/store/impl/package-info.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/store/impl/package-info.java
new file mode 100644
index 0000000..09d5277
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/store/impl/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.
+ */
+
+/**
+ * Implementation of distributed tunnel store using p2p synchronization protocol.
+ */
+package org.onosproject.incubator.net.tunnel.store.impl;
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/ui/TunnelViewMessageHandler.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/ui/TunnelViewMessageHandler.java
new file mode 100644
index 0000000..7ffd50d
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/ui/TunnelViewMessageHandler.java
@@ -0,0 +1,102 @@
+/*
+ * 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.ui;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelEndPointFormatter;
+import org.onosproject.incubator.net.tunnel.TunnelService;
+import org.onosproject.ui.RequestHandler;
+import org.onosproject.ui.UiMessageHandler;
+import org.onosproject.ui.table.TableModel;
+import org.onosproject.ui.table.TableRequestHandler;
+import org.onosproject.ui.table.cell.EnumFormatter;
+
+import java.util.Collection;
+
+public class TunnelViewMessageHandler extends UiMessageHandler {
+    private static final String TUNNEL_DATA_REQ = "tunnelDataRequest";
+    private static final String TUNNEL_DATA_RESP = "tunnelDataResponse";
+    private static final String TUNNELS = "tunnels";
+    private static final String ID = "id";
+    private static final String NAME = "name";
+    private static final String ONE = "one";
+    private static final String TWO = "two";
+    private static final String TYPE = "type";
+    private static final String GROUP_ID = "group_id";
+
+    private static final String BANDWIDTH = "bandwidth";
+    private static final String PATH = "path";
+
+
+    private static final String[] COL_IDS = {
+            ID, NAME, ONE, TWO, TYPE, GROUP_ID,
+            BANDWIDTH, PATH
+    };
+
+    @Override
+    protected Collection<RequestHandler> createRequestHandlers() {
+        return ImmutableSet.of(new TunnelDataRequestHandler());
+    }
+
+    private final class TunnelDataRequestHandler extends TableRequestHandler {
+
+        private static final String NO_ROWS_MESSAGE = "No tunnels found";
+
+        public TunnelDataRequestHandler() {
+            super(TUNNEL_DATA_REQ, TUNNEL_DATA_RESP, TUNNELS);
+        }
+
+        @Override
+        protected String[] getColumnIds() {
+            return COL_IDS;
+        }
+
+        @Override
+        protected String noRowsMessage(ObjectNode payload) {
+            return NO_ROWS_MESSAGE;
+        }
+
+        @Override
+        protected TableModel createTableModel() {
+            TableModel tm = super.createTableModel();
+            //TODO add more formater class so that we can get a more readable table
+            tm.setFormatter(ONE, TunnelEndPointFormatter.INSTANCE);
+            tm.setFormatter(TWO, TunnelEndPointFormatter.INSTANCE);
+            tm.setFormatter(TYPE, EnumFormatter.INSTANCE);
+            return tm;
+        }
+
+        @Override
+        protected void populateTable(TableModel tm, ObjectNode payload) {
+            TunnelService ts = get(TunnelService.class);
+            ts.queryAllTunnels().forEach(tunnel -> populateRow(tm.addRow(), tunnel));
+        }
+
+    }
+
+    private void populateRow(TableModel.Row row, Tunnel tunnel) {
+        row.cell(ID, tunnel.tunnelId().id())
+                .cell(NAME, tunnel.tunnelName().value())
+                .cell(ONE, tunnel.src())
+                .cell(TWO, tunnel.dst())
+                .cell(TYPE, tunnel.type())
+                .cell(GROUP_ID, tunnel.groupId().id())
+                .cell(BANDWIDTH, tunnel.annotations().value(BANDWIDTH))
+                .cell(PATH, tunnel.path());
+    }
+}
diff --git a/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/ui/package-info.java b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/ui/package-info.java
new file mode 100644
index 0000000..1b7baa0
--- /dev/null
+++ b/apps/tunnel/app/src/main/java/org/onosproject/incubator/net/tunnel/ui/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.
+ */
+
+/**
+ * GUI for the tunnel subsystem.
+ */
+package org.onosproject.incubator.net.tunnel.ui;