[ONOS-1925]
1.fix javadocs bugs.
2.add pcep tunnel provider;
3.change pcep to pcep app;
4.fix some bugs according to review suggestions.

Change-Id: I4b90d9bf871dee3be70615d66db3d74f2fd85389
diff --git a/providers/pcep/app/app.xml b/providers/pcep/app/app.xml
new file mode 100644
index 0000000..e5e3db0
--- /dev/null
+++ b/providers/pcep/app/app.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2015 Open Networking Laboratory
+  ~
+  ~ 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.
+  -->
+<app name="org.onosproject.pcep" origin="ON.Lab" version="${project.version}"
+     featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
+     features="${project.artifactId}">
+    <description>${project.description}</description>
+    <artifact>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</artifact>
+    <artifact>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</artifact>
+    <artifact>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</artifact>
+</app>
diff --git a/providers/pcep/app/features.xml b/providers/pcep/app/features.xml
new file mode 100644
index 0000000..6557463
--- /dev/null
+++ b/providers/pcep/app/features.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  ~ Copyright 2015 Open Networking Laboratory                                
+  ~                                                                          
+  ~ 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.
+  -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+    <repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository>
+    <feature name="${project.artifactId}" version="${project.version}"
+             description="${project.description}">
+        <feature>onos-api</feature>
+        <bundle>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</bundle>
+        <bundle>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</bundle>
+        <bundle>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</bundle>
+    </feature>
+</features>
diff --git a/providers/pcep/app/pom.xml b/providers/pcep/app/pom.xml
new file mode 100644
index 0000000..f9a5d66
--- /dev/null
+++ b/providers/pcep/app/pom.xml
@@ -0,0 +1,29 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.onosproject</groupId>
+		<artifactId>onos-pcep-providers</artifactId>
+		<version>1.2.0-SNAPSHOT</version>
+		<relativePath>../pom.xml</relativePath>
+	</parent>
+	<artifactId>onos-pcep</artifactId>
+	<packaging>pom</packaging>
+	<dependencies>
+		<dependency>
+			<groupId>org.onosproject</groupId>
+			<artifactId>onos-app-pcep-api</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.onosproject</groupId>
+			<artifactId>onos-pcep-provider-topology</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.onosproject</groupId>
+			<artifactId>onos-pcep-provider-tunnel</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+
+	</dependencies>
+</project>
\ No newline at end of file
diff --git a/providers/pcep/pom.xml b/providers/pcep/pom.xml
new file mode 100644
index 0000000..41f7c9b
--- /dev/null
+++ b/providers/pcep/pom.xml
@@ -0,0 +1,16 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.onosproject</groupId>
+    <artifactId>onos-providers</artifactId>
+    <version>1.2.0-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+  <artifactId>onos-pcep-providers</artifactId>
+  <packaging>pom</packaging>
+  <modules>
+  	<module>topology</module>
+  	<module>tunnel</module>
+  	<module>app</module>
+  </modules>
+</project>
\ No newline at end of file
diff --git a/providers/pcep/topology/pom.xml b/providers/pcep/topology/pom.xml
new file mode 100644
index 0000000..8d2a781
--- /dev/null
+++ b/providers/pcep/topology/pom.xml
@@ -0,0 +1,17 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.onosproject</groupId>
+    <artifactId>onos-pcep-providers</artifactId>
+    <version>1.2.0-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+  <artifactId>onos-pcep-provider-topology</artifactId>
+  <packaging>bundle</packaging>
+  	<dependencies>
+		<dependency>
+			<groupId>org.onosproject</groupId>
+			<artifactId>onos-app-pcep-api</artifactId>
+		</dependency>
+	</dependencies>
+</project>
\ No newline at end of file
diff --git a/providers/pcep/topology/src/main/java/org/onosproject/provider/pcep/topology/impl/PcepTopologyProvider.java b/providers/pcep/topology/src/main/java/org/onosproject/provider/pcep/topology/impl/PcepTopologyProvider.java
new file mode 100644
index 0000000..9ef9412
--- /dev/null
+++ b/providers/pcep/topology/src/main/java/org/onosproject/provider/pcep/topology/impl/PcepTopologyProvider.java
@@ -0,0 +1,340 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * 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.provider.pcep.topology.impl;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.packet.ChassisId;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.mastership.MastershipAdminService;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.Link.Type;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DefaultDeviceDescription;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.DeviceDescription;
+import org.onosproject.net.device.DeviceProvider;
+import org.onosproject.net.device.DeviceProviderRegistry;
+import org.onosproject.net.device.DeviceProviderService;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.link.DefaultLinkDescription;
+import org.onosproject.net.link.LinkDescription;
+import org.onosproject.net.link.LinkProvider;
+import org.onosproject.net.link.LinkProviderRegistry;
+import org.onosproject.net.link.LinkProviderService;
+import org.onosproject.net.link.LinkService;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.pcep.api.PcepController;
+import org.onosproject.pcep.api.PcepDpid;
+import org.onosproject.pcep.api.PcepLink;
+import org.onosproject.pcep.api.PcepLinkListener;
+import org.onosproject.pcep.api.PcepOperator.OperationType;
+import org.onosproject.pcep.api.PcepSwitch;
+import org.onosproject.pcep.api.PcepSwitchListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.net.DeviceId.deviceId;
+import static org.onosproject.pcep.api.PcepDpid.uri;
+
+/**
+ * Provider which uses an PCEP controller to detect network infrastructure
+ * topology.
+ */
+@Component(immediate = true)
+public class PcepTopologyProvider extends AbstractProvider
+        implements LinkProvider, DeviceProvider {
+
+    public PcepTopologyProvider() {
+        super(new ProviderId("pcep", "org.onosproject.provider.pcep"));
+    }
+
+    private static final Logger log = LoggerFactory
+            .getLogger(PcepTopologyProvider.class);
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected LinkProviderRegistry linkProviderRegistry;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceProviderRegistry deviceProviderRegistry;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected PcepController controller;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceService deviceService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected LinkService linkService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected MastershipAdminService mastershipAdminService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected MastershipService mastershipService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected ClusterService clusterService;
+
+    private DeviceProviderService deviceProviderService;
+    private LinkProviderService linkProviderService;
+    // List<Long> srcportList = new ArrayList<Long>();
+    HashSet<Long> portSet = new HashSet<>();
+    private InternalLinkProvider listener = new InternalLinkProvider();
+
+    @Activate
+    public void activate() {
+        linkProviderService = linkProviderRegistry.register(this);
+        deviceProviderService = deviceProviderRegistry.register(this);
+        controller.addListener(listener);
+        controller.addLinkListener(listener);
+    }
+
+    @Deactivate
+    public void deactivate() {
+        linkProviderRegistry.unregister(this);
+        linkProviderService = null;
+        controller.removeListener(listener);
+        controller.removeLinkListener(listener);
+    }
+
+    private List<PortDescription> buildPortDescriptions(List<Long> ports,
+                                                        String portType) {
+        final List<PortDescription> portDescs = new ArrayList<>();
+        for (long port : ports) {
+            portDescs.add(buildPortDescription(port, portType));
+        }
+        return portDescs;
+    }
+
+    private PortDescription buildPortDescription(long port, String portType) {
+        final PortNumber portNo = PortNumber.portNumber(port);
+        final boolean enabled = true;
+        DefaultAnnotations extendedAttributes = DefaultAnnotations.builder()
+                .set("portType", portType).build();
+        return new DefaultPortDescription(portNo, enabled, extendedAttributes);
+    }
+
+    /**
+     * Build link annotations from pcep link description.the annotations consist
+     * of lots of property of Huawei device.
+     *
+     * @param linkDesc
+     * @return
+     */
+    private DefaultAnnotations buildLinkAnnotations(PcepLink linkDesc) {
+        DefaultAnnotations extendedAttributes = DefaultAnnotations
+                .builder()
+                .set("subType", String.valueOf(linkDesc.linkSubType()))
+                .set("workState", linkDesc.linkState())
+                .set("distance", String.valueOf(linkDesc.linkDistance()))
+                .set("capType", linkDesc.linkCapacityType().toLowerCase())
+                .set("avail_" + linkDesc.linkCapacityType().toLowerCase(),
+                     String.valueOf(linkDesc.linkAvailValue()))
+                .set("max_" + linkDesc.linkCapacityType().toLowerCase(),
+                     String.valueOf(linkDesc.linkMaxValue())).build();
+
+        return extendedAttributes;
+    }
+
+    /**
+     * Build a LinkDescription from a PCEPLink.
+     *
+     * @param pceLink
+     * @return LinkDescription
+     */
+    private LinkDescription buildLinkDescription(PcepLink pceLink) {
+        LinkDescription ld;
+
+        DeviceId srcDeviceID = deviceId(uri(pceLink.linkSrcDeviceID()));
+        DeviceId dstDeviceID = deviceId(uri(pceLink.linkDstDeviceId()));
+
+        if (deviceService.getDevice(srcDeviceID) == null
+                || deviceService.getDevice(dstDeviceID) == null) {
+            log.info("the device of the link is not exited" + srcDeviceID
+                    + dstDeviceID);
+            return null;
+        }
+        // update port info
+        long srcPort = pceLink.linkSrcPort();
+        portSet.add(srcPort);
+        List<Long> srcportList = new ArrayList<Long>();
+        srcportList.addAll(portSet);
+        deviceProviderService
+                .updatePorts(srcDeviceID,
+                             buildPortDescriptions(srcportList,
+                                                   pceLink.portType()));
+
+        ConnectPoint src = new ConnectPoint(srcDeviceID,
+                                            PortNumber.portNumber(pceLink
+                                                    .linkSrcPort()));
+
+        ConnectPoint dst = new ConnectPoint(dstDeviceID,
+                                            PortNumber.portNumber(pceLink
+                                                    .linkDstPort()));
+        DefaultAnnotations extendedAttributes = buildLinkAnnotations(pceLink);
+
+        // construct the link
+        ld = new DefaultLinkDescription(src, dst, Type.OPTICAL,
+                                        extendedAttributes);
+        return ld;
+    }
+
+    private void processLinkUpdate(LinkDescription linkDescription) {
+
+        // dst changed, delete the original link,if the dst device is not in
+        // other links ,delete it.
+        if (linkService.getLink(linkDescription.src(), linkDescription.dst()) == null) {
+            // in face,one src one link
+            Set<Link> links = linkService
+                    .getIngressLinks(linkDescription.src());
+            for (Link link : links) {
+                linkProviderService.linkVanished((LinkDescription) link);
+                if (linkService.getDeviceLinks(link.dst().deviceId()).size() == 0) {
+                    deviceProviderService.deviceDisconnected(link.dst()
+                            .deviceId());
+                }
+            }
+
+        }
+        linkProviderService.linkDetected(linkDescription);
+
+    }
+
+    private class InternalLinkProvider
+            implements PcepSwitchListener, PcepLinkListener {
+
+        @Override
+        public void switchAdded(PcepDpid dpid) {
+            // TODO Auto-generated method stub
+
+            if (deviceProviderService == null) {
+                return;
+            }
+            DeviceId devicdId = deviceId(uri(dpid));
+            PcepSwitch sw = controller.getSwitch(dpid);
+            checkNotNull(sw, "device should not null.");
+            // The default device type is switch.
+            Device.Type deviceType = Device.Type.SWITCH;
+            ChassisId cId = new ChassisId(dpid.value());
+
+            // Device subType: ROADM,OTN,ROUTER.
+            DefaultAnnotations extendedAttributes = DefaultAnnotations
+                    .builder()
+                    .set("subType", String.valueOf(sw.getDeviceSubType()))
+                    .build();
+
+            DeviceDescription description = new DefaultDeviceDescription(
+                                                                         devicdId.uri(),
+                                                                         deviceType,
+                                                                         sw.manufacturerDescription(),
+                                                                         sw.hardwareDescription(),
+                                                                         sw.softwareDescription(),
+                                                                         sw.serialNumber(),
+                                                                         cId,
+                                                                         extendedAttributes);
+            NodeId localNode = clusterService.getLocalNode().id();
+            mastershipAdminService.setRole(localNode, devicdId,
+                                           MastershipRole.MASTER);
+            mastershipService.relinquishMastership(devicdId);
+            deviceProviderService.deviceConnected(devicdId, description);
+
+        }
+
+        @Override
+        public void switchRemoved(PcepDpid dpid) {
+            // TODO Auto-generated method stub
+
+            if (deviceProviderService == null || linkProviderService == null) {
+                return;
+            }
+            deviceProviderService.deviceDisconnected(deviceId(uri(dpid)));
+
+            linkProviderService.linksVanished(DeviceId.deviceId(uri(dpid)));
+        }
+
+        @Override
+        public void switchChanged(PcepDpid dpid) {
+            // TODO Auto-generated method stub
+
+        }
+
+        @Override
+        public void handlePCEPlink(PcepLink link) {
+
+            OperationType operType = link.getOperationType();
+            LinkDescription ld = buildLinkDescription(link);
+            if (ld == null) {
+                log.error("Invalid link info.");
+                return;
+            }
+            switch (operType) {
+            case ADD:
+                linkProviderService.linkDetected(ld);
+                break;
+            case UPDATE:
+                processLinkUpdate(ld);
+                break;
+
+            case DELETE:
+                linkProviderService.linkVanished(ld);
+                break;
+
+            default:
+                break;
+
+            }
+        }
+
+    }
+
+    @Override
+    public void triggerProbe(DeviceId deviceId) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
+        // NodeId localNode = clusterService.getLocalNode().id();
+        // mastershipService.setRole(localNode, deviceId, newRole);
+
+    }
+
+    @Override
+    public boolean isReachable(DeviceId deviceId) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+}
diff --git a/providers/pcep/topology/src/main/java/org/onosproject/provider/pcep/topology/impl/package-info.java b/providers/pcep/topology/src/main/java/org/onosproject/provider/pcep/topology/impl/package-info.java
new file mode 100644
index 0000000..c119266
--- /dev/null
+++ b/providers/pcep/topology/src/main/java/org/onosproject/provider/pcep/topology/impl/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * 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.
+ */
+/**
+ *Provider that uses PCEP controller as a means of infrastructure topology discovery.
+ */
+package org.onosproject.provider.pcep.topology.impl;
\ No newline at end of file
diff --git a/providers/pcep/tunnel/pom.xml b/providers/pcep/tunnel/pom.xml
new file mode 100644
index 0000000..c909d23
--- /dev/null
+++ b/providers/pcep/tunnel/pom.xml
@@ -0,0 +1,19 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.onosproject</groupId>
+		<artifactId>onos-pcep-providers</artifactId>
+		<version>1.2.0-SNAPSHOT</version>
+		<relativePath>../pom.xml</relativePath>
+	</parent>
+	<artifactId>onos-pcep-provider-tunnel</artifactId>
+	<packaging>bundle</packaging>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.onosproject</groupId>
+			<artifactId>onos-app-pcep-api</artifactId>
+		</dependency>
+	</dependencies>
+</project>
\ No newline at end of file
diff --git a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java
new file mode 100644
index 0000000..ec4d3dd
--- /dev/null
+++ b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java
@@ -0,0 +1,458 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * 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.provider.pcep.tunnel.impl;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.net.DeviceId.deviceId;
+import static org.onosproject.net.PortNumber.portNumber;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.core.DefaultGroupId;
+import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription;
+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.incubator.net.tunnel.TunnelProviderRegistry;
+import org.onosproject.incubator.net.tunnel.TunnelProviderService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.DefaultPath;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.ElementId;
+import org.onosproject.net.Link;
+import org.onosproject.net.Path;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.pcep.api.PcepController;
+import org.onosproject.pcep.api.PcepDpid;
+import org.onosproject.pcep.api.PcepHopNodeDescription;
+import org.onosproject.pcep.api.PcepOperator.OperationType;
+import org.onosproject.pcep.api.PcepTunnel;
+import org.onosproject.pcep.api.PcepTunnel.PATHTYPE;
+import org.onosproject.pcep.api.PcepTunnelListener;
+import org.slf4j.Logger;
+
+import static org.onosproject.pcep.api.PcepDpid.*;
+
+/**
+ * Provider which uses an PCEP controller to detect, update, create network
+ * tunnels.
+ */
+@Component(immediate = true)
+@Service
+public class PcepTunnelProvider extends AbstractProvider
+        implements TunnelProvider {
+
+    private static final Logger log = getLogger(PcepTunnelProvider.class);
+    private static final long MAX_BANDWIDTH = 99999744;
+    private static final long MIN_BANDWIDTH = 64;
+    static final String PROVIDER_ID = "org.onosproject.provider.tunnel.default";
+
+    private static final String TUNNLE_NOT_NULL = "Create failed,The given port may be wrong or has been occupied.";
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected TunnelProviderRegistry tunnelProviderRegistry;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected PcepController controller;
+
+    TunnelProviderService service;
+
+    HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>();
+
+    private InnerTunnerProvider listener = new InnerTunnerProvider();
+
+    /**
+     * Creates a Tunnel provider.
+     */
+    public PcepTunnelProvider() {
+        super(new ProviderId("default", PROVIDER_ID));
+    }
+
+    @Activate
+    public void activate() {
+        service = tunnelProviderRegistry.register(this);
+        controller.addTunnelListener(listener);
+        log.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        tunnelProviderRegistry.unregister(this);
+        controller.removeTunnelListener(listener);
+        log.info("Stopped");
+    }
+
+    @Override
+    public void setupTunnel(Tunnel tunnel, Path path) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void releaseTunnel(Tunnel tunnel) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void releaseTunnel(ElementId srcElement, Tunnel tunnel) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void updateTunnel(Tunnel tunnel, Path path) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public TunnelId tunnelAdded(TunnelDescription tunnel) {
+
+        long bandwidth = Long.parseLong(tunnel.annotations().value("bandWith"));
+
+        if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
+            System.out.println("Update failed, invalid bandwidth.");
+            return null;
+        }
+
+        // endpoints
+        OpticalTunnelEndPoint src = (org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint) tunnel
+                .src();
+        OpticalTunnelEndPoint dst = (OpticalTunnelEndPoint) tunnel.dst();
+        // devices
+        DeviceId srcId = (DeviceId) src.elementId().get();
+        DeviceId dstId = (DeviceId) dst.elementId().get();
+
+        // ports
+        long srcPort = src.portNumber().get().toLong();
+        long dstPort = dst.portNumber().get().toLong();
+
+        // type
+        if (tunnel.type() != Tunnel.Type.VLAN) {
+            System.out
+                    .println("Llegal tunnel type. Only support VLAN tunnel creation.");
+            return null;
+        }
+
+        PcepTunnel pcepTunnel = controller.applyTunnel(srcId, dstId, srcPort,
+                                                       dstPort, bandwidth,
+                                                       tunnel.tunnelName()
+                                                               .value());
+
+        checkNotNull(pcepTunnel, TUNNLE_NOT_NULL);
+        TunnelDescription tunnelAdded = buildOpticalTunnel(pcepTunnel, null);
+        TunnelId tunnelId = service.tunnelAdded(tunnelAdded);
+
+        tunnelMap.put(String.valueOf(pcepTunnel.id()), tunnelId);
+        return tunnelId;
+    }
+
+    @Override
+    public void tunnelRemoved(TunnelDescription tunnel) {
+        Tunnel tunnelOld = tunnelQueryById(tunnel.id());
+        checkNotNull(tunnelOld, "The tunnel id is not exsited.");
+        if (tunnelOld.type() != Tunnel.Type.VLAN) {
+            System.out
+                    .println("Llegal tunnel type. Only support VLAN tunnel deletion.");
+            return;
+        }
+        String pcepTunnelId = getPCEPTunnelKey(tunnel.id());
+        checkNotNull(pcepTunnelId, "The tunnel id is not exsited.");
+        if (controller.deleteTunnel(pcepTunnelId)) {
+            log.info("delete tunnel:" + pcepTunnelId + "ok.");
+        }
+        tunnelMap.remove(pcepTunnelId);
+        service.tunnelRemoved(tunnel);
+
+    }
+
+    @Override
+    public void tunnelUpdated(TunnelDescription tunnel) {
+
+        Tunnel tunnelOld = tunnelQueryById(tunnel.id());
+        if (tunnelOld.type() != Tunnel.Type.VLAN) {
+            System.out
+                    .println("Llegal tunnel type. Only support VLAN tunnel update.");
+            return;
+        }
+        long bandwidth = Long.parseLong(tunnel.annotations().value("bandWith"));
+        if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
+            System.out.println("Update failed, invalid bandwidth.");
+            return;
+        }
+        String pcepTunnelId = getPCEPTunnelKey(tunnel.id());
+
+        checkNotNull(pcepTunnelId, "Invalid tunnel id");
+        if (!controller.updateTunnelBandwidth(pcepTunnelId, bandwidth)) {
+
+            System.out.println("Update failed,maybe invalid bandwidth.");
+            return;
+
+        }
+        service.tunnelUpdated(tunnel);
+    }
+
+    // Short-hand for creating a connection point.
+    private ConnectPoint connectPoint(PcepDpid id, long port) {
+        return new ConnectPoint(deviceId(uri(id)), portNumber(port));
+    }
+
+    // Short-hand for creating a link.
+    private Link link(PcepDpid src, long sp, PcepDpid dst, long dp) {
+        return new DefaultLink(id(), connectPoint(src, sp), connectPoint(dst,
+                                                                         dp),
+                               Link.Type.TUNNEL);
+    }
+
+    // Creates a path that leads through the given devices.
+    private Path createPath(List<PcepHopNodeDescription> hopList,
+                            PATHTYPE pathtype) {
+        if (hopList == null || hopList.size() == 0) {
+            return null;
+        }
+        List<Link> links = new ArrayList<>();
+        for (int i = 1; i < hopList.size() - 1; i = i + 2) {
+            links.add(link(hopList.get(i).getDeviceId(), hopList.get(i)
+                    .getPortNum(), hopList.get(i + 1).getDeviceId(), hopList
+                    .get(i + 1).getPortNum()));
+        }
+
+        int hopNum = hopList.size() - 2;
+        DefaultAnnotations extendAnnotations = DefaultAnnotations.builder()
+                .set("pathNum", String.valueOf(hopNum))
+                .set("pathType", String.valueOf(pathtype)).build();
+        return new DefaultPath(id(), links, hopNum, extendAnnotations);
+    }
+
+    // convert the path description to a string.
+    public String pathToString(List<Link> links) {
+        StringBuilder builder = new StringBuilder();
+        builder.append("{");
+        for (Link link : links) {
+            builder.append("(Device:" + link.src().deviceId() + "  Port:"
+                    + link.src().port().toLong());
+            builder.append(" Device:" + link.dst().deviceId() + "  Port:"
+                    + link.dst().port().toLong());
+            builder.append(")");
+        }
+        builder.append("}");
+        return builder.toString();
+    }
+
+    // build a TunnelDescription.
+    private TunnelDescription buildOpticalTunnel(PcepTunnel pcepTunnel,
+                                                 TunnelId tunnelId) {
+        TunnelEndPoint srcPoint = null;
+        TunnelEndPoint dstPoint = null;
+        Tunnel.Type tunnelType = null;
+        TunnelName name = TunnelName.tunnelName(pcepTunnel.name());
+
+        // add path after codes of tunnel's path merged
+        Path path = createPath(pcepTunnel.getHopList(),
+                               pcepTunnel.getPathType());
+
+        OpticalTunnelEndPoint.Type endPointType = null;
+        switch (pcepTunnel.type()) {
+        case OCH:
+            tunnelType = Tunnel.Type.OCH;
+            endPointType = OpticalTunnelEndPoint.Type.LAMBDA;
+            break;
+
+        case OTN:
+            tunnelType = Tunnel.Type.ODUK;
+            endPointType = OpticalTunnelEndPoint.Type.TIMESLOT;
+            break;
+
+        case UNI:
+            tunnelType = Tunnel.Type.VLAN;
+            endPointType = null;
+            break;
+
+        default:
+            break;
+        }
+        DeviceId srcDid = deviceId(uri(pcepTunnel.srcDeviceID()));
+        DeviceId dstDid = deviceId(uri(pcepTunnel.dstDeviceId()));
+        PortNumber srcPort = PortNumber.portNumber(pcepTunnel.srcPort());
+        PortNumber dstPort = PortNumber.portNumber(pcepTunnel.dstPort());
+
+        srcPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(srcDid),
+                                                    Optional.of(srcPort), null,
+                                                    endPointType,
+                                                    OpticalLogicId.logicId(0),
+                                                    true);
+        dstPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(dstDid),
+                                                    Optional.of(dstPort), null,
+                                                    endPointType,
+                                                    OpticalLogicId.logicId(0),
+                                                    true);
+
+        // basic annotations
+        DefaultAnnotations annotations = DefaultAnnotations.builder()
+                .set("bandWith", String.valueOf(pcepTunnel.bandWidth()))
+                .set("SLA", String.valueOf(pcepTunnel.getSla()))
+                .set("index", String.valueOf(pcepTunnel.id())).build();
+
+        // if (path != null) {
+        //
+        // DefaultAnnotations extendAnnotations = DefaultAnnotations.builder()
+        // .set("pathNum", String.valueOf(hopNum))
+        // // .set("path", pathString)
+        // .set("pathType", String.valueOf(pcepTunnel.getPathType()))
+        // .build();
+        // annotations = DefaultAnnotations.merge(annotations,
+        // extendAnnotations);
+        // }
+
+        // a VLAN tunnel always carry OCH tunnel, this annotation is the index
+        // of a OCH tunnel.
+        if (pcepTunnel.underLayTunnelId() != 0) {
+            DefaultAnnotations extendAnnotations = DefaultAnnotations
+                    .builder()
+                    .set("underLayTunnelIndex",
+                         String.valueOf(pcepTunnel.underLayTunnelId())).build();
+            annotations = DefaultAnnotations.merge(annotations,
+                                                   extendAnnotations);
+
+        }
+        TunnelDescription tunnel = new DefaultTunnelDescription(
+                                                                tunnelId,
+                                                                srcPoint,
+                                                                dstPoint,
+                                                                tunnelType,
+                                                                new DefaultGroupId(
+                                                                                   0),
+                                                                id(), name,
+                                                                path,
+                                                                annotations);
+        return tunnel;
+
+    }
+
+    /**
+     * Get the tunnelID according to the tunnel key.
+     *
+     * @param tunnelKey tunnel key
+     * @return corresponding tunnel id of the a tunnel key.
+     */
+    private TunnelId getTunnelId(String tunnelKey) {
+
+        for (String key : tunnelMap.keySet()) {
+            if (key.equals(tunnelKey)) {
+                return tunnelMap.get(key);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Get the tunnel key according to the tunnelID.
+     *
+     * @param tunnelId tunnel id
+     * @return corresponding a tunnel key of the tunnel id.
+     */
+    private String getPCEPTunnelKey(TunnelId tunnelId) {
+        for (String key : tunnelMap.keySet()) {
+            if (tunnelMap.get(key).id() == tunnelId.id()) {
+                return key;
+            }
+        }
+        return null;
+
+    }
+
+    private class InnerTunnerProvider implements PcepTunnelListener {
+
+        @Override
+        public void handlePCEPTunnel(PcepTunnel pcepTunnel) {
+
+            TunnelDescription tunnel = null;
+            // instance and id identify a tunnel together
+            String tunnelKey = String.valueOf(pcepTunnel.getInstance())
+                    + String.valueOf(pcepTunnel.id());
+
+            if (tunnelKey == null || "".equals(tunnelKey)) {
+                log.error("Invalid PCEP tunnel");
+                return;
+            }
+
+            TunnelId tunnelId = getTunnelId(tunnelKey);
+
+            tunnel = buildOpticalTunnel(pcepTunnel, tunnelId);
+
+            OperationType operType = pcepTunnel.getOperationType();
+            switch (operType) {
+            case ADD:
+                tunnelId = service.tunnelAdded(tunnel);
+                tunnelMap.put(tunnelKey, tunnelId);
+                break;
+
+            case UPDATE:
+                service.tunnelUpdated(tunnel);
+                break;
+
+            case DELETE:
+                service.tunnelRemoved(tunnel);
+                tunnelMap.remove(tunnelKey);
+                break;
+
+            default:
+                log.error("Invalid tunnel operation");
+
+            }
+
+        }
+    }
+
+    @Override
+    public Tunnel tunnelQueryById(TunnelId tunnelId) {
+        return service.tunnelQueryById(tunnelId);
+    }
+
+}
diff --git a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/package-info.java b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/package-info.java
new file mode 100644
index 0000000..5074eec
--- /dev/null
+++ b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * 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.
+ */
+/**
+ *Provider that uses PCEP controller as a means of infrastructure tunnel discovery.
+ */
+package org.onosproject.provider.pcep.tunnel.impl;
\ No newline at end of file
diff --git a/providers/pom.xml b/providers/pom.xml
index d59b2b6..a2ba12c 100644
--- a/providers/pom.xml
+++ b/providers/pom.xml
@@ -38,6 +38,7 @@
         <module>netconf</module>
         <module>null</module>
         <module>tunnel</module>
+        <module>pcep</module>
     </modules>
 
     <dependencies>