[ONOS-4163] Provider side changes to support stateful PCE and PCECC

Change-Id: I0a57ed1d1e505a2e94921fd5f5d92426a105ad12
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java
index efb4d95..2f519ec 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java
@@ -42,6 +42,7 @@
     private ClientCapability capability;
 
     private PcepVersion pcepVersion;
+    private boolean syncCompleted;
 
     /**
      * Initialize instance with specified parameters.
@@ -109,11 +110,12 @@
 
     @Override
     public final boolean isSyncComplete() {
-        return false;
+        return syncCompleted;
     }
 
     @Override
     public final void setIsSyncComplete(boolean value) {
+        syncCompleted = value;
     }
 
     @Override
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientControllerAdapter.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientControllerAdapter.java
index 91a68fc..822d8b6 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientControllerAdapter.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientControllerAdapter.java
@@ -73,6 +73,9 @@
 
     @Override
     public PcepClient getClient(PccId pccId) {
+        if (null != connectedClients.get(pccId)) {
+            return connectedClients.get(pccId);
+        }
         PcepClientAdapter pc = new PcepClientAdapter();
         if (pccId.ipAddress().equals(IpAddress.valueOf(0xC010103))
             || pccId.ipAddress().equals(IpAddress.valueOf(0xB6024E22))) {
@@ -81,6 +84,7 @@
             pc.setCapability(new ClientCapability(true, true, true));
         }
         pc.init(PccId.pccId(pccId.ipAddress()), PcepVersion.PCEP_1);
+        connectedClients.put(pccId, pc);
         return pc;
     }
 
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java
index 027f396..ec9c1aa 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java
@@ -20,6 +20,10 @@
 import static org.hamcrest.core.Is.is;
 import static org.hamcrest.core.IsNot.not;
 import static org.onosproject.net.DefaultAnnotations.EMPTY;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -36,7 +40,9 @@
 import org.onosproject.incubator.net.tunnel.Tunnel;
 import org.onosproject.incubator.net.tunnel.TunnelId;
 import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.net.Annotations;
 import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.DefaultLink;
 import org.onosproject.net.DefaultPath;
 import org.onosproject.net.IpElementId;
@@ -44,7 +50,7 @@
 import org.onosproject.net.Path;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.provider.ProviderId;
-import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
+import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
 
 /**
  * Test for PCEP release tunnel.
@@ -77,7 +83,7 @@
     public void testCasePcepReleaseTunnel() {
         Tunnel tunnel;
         Path path;
-        List<Link> links = new ArrayList<Link>();
+        List<Link> links = new ArrayList<>();
 
         ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
 
@@ -103,14 +109,18 @@
 
         path = new DefaultPath(pid, links, 20, EMPTY);
 
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+                .build();
+
         tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
                                    new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
-                                   path, EMPTY);
+                                   path, annotations);
 
         // for releasing tunnel tunnel should exist in db
         PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
         pcepTunnelData.setPlspId(1);
-        StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
         pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
         tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
 
@@ -127,7 +137,7 @@
     public void testCasePcepReleaseTunnel2() {
         Tunnel tunnel;
         Path path;
-        List<Link> links = new ArrayList<Link>();
+        List<Link> links = new ArrayList<>();
 
         ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
 
@@ -153,14 +163,18 @@
 
         path = new DefaultPath(pid, links, 20, EMPTY);
 
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+                .build();
+
         tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
                                    new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
-                                   path, EMPTY);
+                                   path, annotations);
 
         // for releasing tunnel tunnel should exist in db
         PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
         pcepTunnelData.setPlspId(1);
-        StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
         pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
         tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
 
@@ -170,6 +184,114 @@
         assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
     }
 
+    /**
+     * Tests releasing SR based tunnel.
+     */
+    @Test
+    public void testCasePcepReleaseSrTunnel() {
+        Tunnel tunnel;
+        Path path;
+        List<Link> links = new ArrayList<>();
+
+        ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+
+        IpAddress srcIp = IpAddress.valueOf(0xB6024E20);
+        IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+        IpAddress dstIp = IpAddress.valueOf(0xB6024E21);
+        IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+        IpTunnelEndPoint ipTunnelEndPointSrc;
+        ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+        IpTunnelEndPoint ipTunnelEndPointDst;
+        ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+        ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+        ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+        Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+                .type(Link.Type.DIRECT).build();
+        links.add(link);
+
+        path = new DefaultPath(pid, links, 20, EMPTY);
+
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
+                .build();
+
+        tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+                                   new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+                                   path, annotations);
+
+        // for releasing tunnel tunnel should exist in db
+        PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
+        pcepTunnelData.setPlspId(1);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
+        pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+        tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
+
+        tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+        tunnelProvider.releaseTunnel(tunnel);
+        assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+    }
+
+    /**
+     * Tests releasing tunnel without SR and without signalling.
+     */
+    @Test
+    public void testCasePcepReleaseTunnelWithoutSigSr() {
+        Tunnel tunnel;
+        Path path;
+        List<Link> links = new ArrayList<>();
+
+        ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+
+        IpAddress srcIp = IpAddress.valueOf(0xB6024E20);
+        IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+        IpAddress dstIp = IpAddress.valueOf(0xB6024E21);
+        IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+        IpTunnelEndPoint ipTunnelEndPointSrc;
+        ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+        IpTunnelEndPoint ipTunnelEndPointDst;
+        ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+        ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+        ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+        Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+                .type(Link.Type.DIRECT).build();
+        links.add(link);
+
+        path = new DefaultPath(pid, links, 20, EMPTY);
+
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
+                .build();
+
+        tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+                                   new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+                                   path, annotations);
+
+        // for releasing tunnel tunnel should exist in db
+        PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
+        pcepTunnelData.setPlspId(1);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
+        pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+        tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
+
+        tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+        tunnelProvider.releaseTunnel(tunnel);
+        assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+    }
+
     @After
     public void tearDown() throws IOException {
         tunnelProvider.deactivate();
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java
index 5b41d41..d2c4d5e 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java
@@ -20,6 +20,10 @@
 import static org.hamcrest.core.Is.is;
 import static org.hamcrest.core.IsNot.not;
 import static org.hamcrest.Matchers.nullValue;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -36,7 +40,9 @@
 import org.onosproject.incubator.net.tunnel.Tunnel;
 import org.onosproject.incubator.net.tunnel.TunnelId;
 import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.net.Annotations;
 import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.DefaultLink;
 import org.onosproject.net.DefaultPath;
 import org.onosproject.net.IpElementId;
@@ -75,7 +81,7 @@
         Tunnel tunnel;
         Path path;
         ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
-        List<Link> links = new ArrayList<Link>();
+        List<Link> links = new ArrayList<>();
         IpAddress srcIp = IpAddress.valueOf(0xC010101);
         IpElementId srcElementId = IpElementId.ipElement(srcIp);
 
@@ -98,9 +104,13 @@
 
         path = new DefaultPath(pid, links, 10, EMPTY);
 
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+                .build();
+
         tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
                                    new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
-                                   path, EMPTY);
+                                   path, annotations);
 
         tunnelProvider.setupTunnel(tunnel, path);
         assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
@@ -114,7 +124,7 @@
         Tunnel tunnel;
         Path path;
         ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
-        List<Link> links = new ArrayList<Link>();
+        List<Link> links = new ArrayList<>();
         IpAddress srcIp = IpAddress.valueOf(0xC010103);
         IpElementId srcElementId = IpElementId.ipElement(srcIp);
 
@@ -137,14 +147,104 @@
 
         path = new DefaultPath(pid, links, 10, EMPTY);
 
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+                .build();
+
         tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
                                    new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
-                                   path, EMPTY);
+                                   path, annotations);
 
         tunnelProvider.setupTunnel(tunnel, path);
         assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
     }
 
+    /**
+     * Sends PCInitiate msg to setup a SR based tunnel.
+     */
+    @Test
+    public void testCasePcepSetupSrTunnel() {
+        Tunnel tunnel;
+        Path path;
+        ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+        List<Link> links = new ArrayList<>();
+        IpAddress srcIp = IpAddress.valueOf(0xC010101);
+        IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+        IpAddress dstIp = IpAddress.valueOf(0xC010102);
+        IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+        IpTunnelEndPoint ipTunnelEndPointSrc;
+        ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+        IpTunnelEndPoint ipTunnelEndPointDst;
+        ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+        ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+        ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+        Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+                .type(Link.Type.DIRECT).build();
+        links.add(link);
+
+        path = new DefaultPath(pid, links, 10, EMPTY);
+
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
+                .build();
+
+        tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+                                   new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+                                   path, annotations);
+
+        tunnelProvider.setupTunnel(tunnel, path);
+        assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+    }
+
+    /**
+     * Sends PCInitiate msg to setup a tunnel without signalling and without SR.
+     */
+    @Test
+    public void testCasePcepSetupTunnelWithoutSigSr() {
+        Tunnel tunnel;
+        Path path;
+        ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+        List<Link> links = new ArrayList<>();
+        IpAddress srcIp = IpAddress.valueOf(0xC010101);
+        IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+        IpAddress dstIp = IpAddress.valueOf(0xC010102);
+        IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+        IpTunnelEndPoint ipTunnelEndPointSrc;
+        ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+        IpTunnelEndPoint ipTunnelEndPointDst;
+        ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+        ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+        ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+        Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+                .type(Link.Type.DIRECT).build();
+        links.add(link);
+
+        path = new DefaultPath(pid, links, 10, EMPTY);
+
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
+                .build();
+
+        tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+                                   new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+                                   path, annotations);
+
+        tunnelProvider.setupTunnel(tunnel, path);
+        assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+    }
+
     @After
     public void tearDown() throws IOException {
         tunnelProvider.deactivate();
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelAddedTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelAddedTest.java
new file mode 100644
index 0000000..76f2bb0
--- /dev/null
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelAddedTest.java
@@ -0,0 +1,329 @@
+/*
+ * Copyright 2016-present 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 org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
+import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.BANDWIDTH;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LOCAL_LSP_ID;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cfg.ComponentConfigAdapter;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.incubator.net.tunnel.DefaultTunnel;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+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.TunnelProviderService;
+import org.onosproject.incubator.net.tunnel.Tunnel.State;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.ElementId;
+import org.onosproject.net.Path;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
+import org.onosproject.pcepio.exceptions.PcepParseException;
+import org.onosproject.pcepio.protocol.PcepFactories;
+import org.onosproject.pcepio.protocol.PcepMessage;
+import org.onosproject.pcepio.protocol.PcepMessageReader;
+import org.onosproject.pcep.controller.ClientCapability;
+import org.onosproject.pcep.controller.PccId;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests handling of PCEP report message.
+ */
+public class PcepTunnelAddedTest {
+
+    static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
+    PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
+    private final MockTunnelProviderRegistryAdapter registry = new MockTunnelProviderRegistryAdapter();
+    private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
+    private final PcepControllerAdapter ctl = new PcepControllerAdapter();
+    private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
+    private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
+
+    private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter {
+        public long tunnelIdCounter;
+
+        @Override
+        public TunnelProviderService register(TunnelProvider provider) {
+            this.provider = provider;
+            return new TestProviderService();
+        }
+
+        private class TestProviderService implements TunnelProviderService {
+
+            @Override
+            public TunnelProvider provider() {
+                return null;
+            }
+
+            @Override
+            public TunnelId tunnelAdded(TunnelDescription tunnel) {
+                return TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
+            }
+
+            @Override
+            public TunnelId tunnelAdded(TunnelDescription tunnel, State state) {
+                return TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
+            }
+
+            @Override
+            public void tunnelRemoved(TunnelDescription tunnel) {
+            }
+
+            @Override
+            public void tunnelUpdated(TunnelDescription tunnel) {
+            }
+
+            @Override
+            public void tunnelUpdated(TunnelDescription tunnel, State state) {
+            }
+
+            @Override
+            public Tunnel tunnelQueryById(TunnelId tunnelId) {
+                return null;
+            }
+        }
+    }
+
+    private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
+        private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<>();
+        private int tunnelIdCounter = 0;
+
+        @Override
+        public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
+            TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
+            tunnelIdAsKeyStore.put(tunnelId, tunnel);
+            return tunnelId;
+        }
+
+        @Override
+        public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
+            Collection<Tunnel> result = new HashSet<>();
+            Tunnel tunnel = null;
+            for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
+                tunnel = tunnelIdAsKeyStore.get(tunnelId);
+
+                if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
+                    result.add(tunnel);
+                }
+            }
+
+            return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
+        }
+
+        @Override
+        public Collection<Tunnel> queryAllTunnels() {
+            Collection<Tunnel> result = new HashSet<>();
+
+            for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
+                result.add(tunnelIdAsKeyStore.get(tunnelId));
+            }
+
+            return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
+
+        }
+    }
+
+    @Before
+    public void preSetup() {
+        tunnelProvider.tunnelProviderRegistry = registry;
+        tunnelProvider.pcepClientController = controller;
+        tunnelProvider.controller = ctl;
+        tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
+        tunnelProvider.cfgService = new ComponentConfigAdapter();
+        tunnelProvider.tunnelService = tunnelService;
+        tunnelProvider.service = registry.register(tunnelProvider);
+        tunnelProvider.activate();
+    }
+
+    /**
+     * Tests PCRpt msg with sync flag set.
+     */
+    @Test
+    public void tunnelProviderAddedTest1() throws PcepParseException, PcepOutOfBoundMessageException {
+        byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
+                0x21, 0x10, 0x00, 0x14,  0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x01, //SRP object
+                0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
+                0x00, 0x00, 0x00, 0x02,
+                0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
+                0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
+                0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
+                0x01, 0x01, 0x01, 0x01,
+                0x00, 0x01, 0x00, 0x01,
+                0x01, 0x01, 0x01, 0x01,
+                0x05, 0x05, 0x05, 0x05,
+
+                0x07, 0x10, 0x00, 0x14, //ERO object
+                0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
+                0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
+
+                0x08, 0x10, 0x00, 0x34, //RRO object
+                0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
+                0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
+                0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
+                0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
+                0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
+                0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
+                };
+
+        ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+        buffer.writeBytes(reportMsg);
+
+        PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
+        PcepMessage message = reader.readFrom(buffer);
+        controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
+
+        assertThat(registry.tunnelIdCounter, is((long) 1));
+    }
+
+    /**
+     * Tests updating an existing tunnel on receiving asynchronous PCRpt msg,
+     * i.e. without any SRP id.
+     */
+    @Test
+    public void tunnelProviderAddedTest2() throws PcepParseException, PcepOutOfBoundMessageException {
+        byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x50,
+                                       0x21, 0x10, 0x00, 0x14, //SRP object
+                                       0x00, 0x00, 0x00, 0x00,
+                                       0x00, 0x00, 0x00, 0x00,
+                                       0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
+                                       0x00, 0x00, 0x00, 0x02,
+                                       0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, //LSP object
+                                       0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path TLV
+                                       0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
+                                       0x4e, 0x1f, 0x04, 0x00,
+                                       0x00, 0x01, 0x00, 0x01,
+                                       0x4e, 0x1f, 0x04, 0x00,
+                                       0x4e, 0x20, 0x04, 0x00,
+                                       0x07, 0x10, 0x00, 0x14, //ERO object
+                                       0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, // ERO IPv4 sub objects
+                                       0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
+                                       };
+
+        ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+        buffer.writeBytes(reportMsg);
+
+        PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
+        PcepMessage message = reader.readFrom(buffer);
+
+        // create an existing tunnel.
+        IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e1f0400));
+        IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e200400));
+
+        SparseAnnotations annotations = DefaultAnnotations.builder()
+                .set(BANDWIDTH, (new Integer(1)).toString())
+                .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
+                .set(PCC_TUNNEL_ID, String.valueOf(1))
+                .set(PLSP_ID, String.valueOf(1))
+                .set(LOCAL_LSP_ID, String.valueOf(1)).build();
+
+        Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null,
+                                          TunnelName.tunnelName("T123"), null, annotations);
+        tunnelService.setupTunnel(null, null, tunnel, null);
+
+        PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400));
+        controller.getClient(pccId).setCapability(new ClientCapability(true, true, true));
+        controller.getClient(pccId).setIsSyncComplete(true);
+
+        // Process update message.
+        controller.processClientMessage(pccId, message);
+        assertThat(tunnelService.queryAllTunnels().size(), is(1));
+    }
+
+    /**
+     * Tests adding a new tunnel on receiving asynchronous PCRpt msg,
+     * i.e. without any SRP id.
+     */
+    @Test
+    public void tunnelProviderAddedTest3() throws PcepParseException, PcepOutOfBoundMessageException {
+        byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
+                                       0x21, 0x10, 0x00, 0x14, //SRP object
+                                       0x00, 0x00, 0x00, 0x00,
+                                       0x00, 0x00, 0x00, 0x00,
+                                       0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
+                                       0x00, 0x00, 0x00, 0x02,
+                                       0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object
+                                       0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
+                                       0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
+                                       0x01, 0x01, 0x01, 0x01,
+                                       0x00, 0x01, 0x00, 0x01,
+                                       0x01, 0x01, 0x01, 0x01,
+                                       0x05, 0x05, 0x05, 0x05,
+
+                                       0x07, 0x10, 0x00, 0x14, //ERO object
+                                       0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
+                                       0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
+
+                                       0x08, 0x10, 0x00, 0x34, //RRO object
+                                       0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
+                                       0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
+                                       0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
+                                       0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
+                                       0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
+                                       0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
+                                       };
+
+        ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+        buffer.writeBytes(reportMsg);
+
+        PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
+        PcepMessage message = reader.readFrom(buffer);
+
+        PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
+        controller.getClient(pccId).setIsSyncComplete(true);
+        controller.getClient(pccId).setCapability(new ClientCapability(true, true, true));
+        controller.processClientMessage(pccId, message);
+
+        assertThat(registry.tunnelIdCounter, is((long) 1));
+    }
+
+    @After
+    public void tearDown() throws IOException {
+        tunnelProvider.deactivate();
+        tunnelProvider.controller = null;
+        tunnelProvider.pcepClientController = null;
+        tunnelProvider.tunnelProviderRegistry = null;
+
+        tunnelProvider.pcepTunnelApiMapper = null;
+        tunnelProvider.cfgService = null;
+        tunnelProvider.tunnelService = null;
+        tunnelProvider.service = null;
+    }
+}
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java
index d357d46..2922537 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java
@@ -15,7 +15,12 @@
  */
 package org.onosproject.provider.pcep.tunnel.impl;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.core.IsNot.not;
 import static org.onosproject.net.DefaultAnnotations.EMPTY;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -30,7 +35,9 @@
 import org.onosproject.incubator.net.tunnel.Tunnel;
 import org.onosproject.incubator.net.tunnel.TunnelId;
 import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.net.Annotations;
 import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.DefaultLink;
 import org.onosproject.net.DefaultPath;
 import org.onosproject.net.IpElementId;
@@ -62,7 +69,7 @@
         Tunnel tunnel;
         Path path;
         ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
-        List<Link> links = new ArrayList<Link>();
+        List<Link> links = new ArrayList<>();
         IpAddress srcIp = IpAddress.valueOf(0xC010101);
         IpElementId srcElementId = IpElementId.ipElement(srcIp);
 
@@ -85,11 +92,17 @@
 
         path = new DefaultPath(pid, links, 10, EMPTY);
 
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+                .build();
+
         tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
                                    new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
-                                   path, EMPTY);
+                                   path, annotations);
 
         tunnelProvider.setupTunnel(tunnel, path);
+
+        assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
     }
 
     @After
@@ -99,4 +112,4 @@
         tunnelProvider.pcepClientController = null;
         tunnelProvider.tunnelProviderRegistry = null;
     }
-}
+}
\ No newline at end of file
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
index 23a2213..2c9961f 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
@@ -20,6 +20,7 @@
 import static org.hamcrest.core.Is.is;
 import static org.hamcrest.core.IsNot.not;
 import static org.onosproject.net.DefaultAnnotations.EMPTY;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -36,7 +37,9 @@
 import org.onosproject.incubator.net.tunnel.Tunnel;
 import org.onosproject.incubator.net.tunnel.TunnelId;
 import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.net.Annotations;
 import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.DefaultLink;
 import org.onosproject.net.DefaultPath;
 import org.onosproject.net.IpElementId;
@@ -44,8 +47,11 @@
 import org.onosproject.net.Path;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.provider.ProviderId;
-import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
+import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
 
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
 /**
  * Test for PCEP update tunnel.
  */
@@ -78,7 +84,7 @@
         Tunnel tunnel;
         Path path;
         ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
-        List<Link> links = new ArrayList<Link>();
+        List<Link> links = new ArrayList<>();
         IpAddress srcIp = IpAddress.valueOf(0xD010101);
         IpElementId srcElementId = IpElementId.ipElement(srcIp);
 
@@ -101,14 +107,18 @@
 
         path = new DefaultPath(pid, links, 20, EMPTY);
 
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+                .build();
+
         tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
                                    new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
-                                   path, EMPTY);
+                                   path, annotations);
 
         // for updating tunnel tunnel should exist in db
         PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
         pcepTunnelData.setPlspId(1);
-        StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
         pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
         tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
 
@@ -126,7 +136,7 @@
         Tunnel tunnel;
         Path path;
         ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
-        List<Link> links = new ArrayList<Link>();
+        List<Link> links = new ArrayList<>();
         IpAddress srcIp = IpAddress.valueOf(0xC010103);
         IpElementId srcElementId = IpElementId.ipElement(srcIp);
 
@@ -149,14 +159,18 @@
 
         path = new DefaultPath(pid, links, 20, EMPTY);
 
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+                .build();
+
         tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
                                    new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
-                                   path, EMPTY);
+                                   path, annotations);
 
         // for updating tunnel tunnel should exist in db
         PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
         pcepTunnelData.setPlspId(1);
-        StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
         pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
         tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
 
@@ -166,6 +180,110 @@
         assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
     }
 
+    /**
+     * Sends update message to PCC for SR based tunnel.
+     */
+    @Test
+    public void testCasePcepUpdateSrTunnel() {
+        Tunnel tunnel;
+        Path path;
+        ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+        List<Link> links = new ArrayList<>();
+        IpAddress srcIp = IpAddress.valueOf(0xD010101);
+        IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+        IpAddress dstIp = IpAddress.valueOf(0xD010102);
+        IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+        IpTunnelEndPoint ipTunnelEndPointSrc;
+        ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+        IpTunnelEndPoint ipTunnelEndPointDst;
+        ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+        ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+        ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+        Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+                .type(Link.Type.DIRECT).build();
+        links.add(link);
+
+        path = new DefaultPath(pid, links, 20, EMPTY);
+
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
+                .build();
+
+        tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+                                   new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+                                   path, annotations);
+
+        // for updating tunnel tunnel should exist in db
+        PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
+        pcepTunnelData.setPlspId(1);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
+        pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+        tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
+
+        tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+        tunnelProvider.updateTunnel(tunnel, path);
+        assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+    }
+
+    /**
+     * Sends update message to PCC for tunnel without signalling and without SR.
+     */
+    @Test
+    public void testCasePcepUpdateTunnelWithoutSigSr() {
+        Tunnel tunnel;
+        Path path;
+        ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+        List<Link> links = new ArrayList<>();
+        IpAddress srcIp = IpAddress.valueOf(0xD010101);
+        IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+        IpAddress dstIp = IpAddress.valueOf(0xD010102);
+        IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+        IpTunnelEndPoint ipTunnelEndPointSrc;
+        ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+        IpTunnelEndPoint ipTunnelEndPointDst;
+        ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+        ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+        ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+        Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+                .type(Link.Type.DIRECT).build();
+        links.add(link);
+
+        path = new DefaultPath(pid, links, 20, EMPTY);
+
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
+                .build();
+
+        tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+                                   new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+                                   path, annotations);
+
+        // for updating tunnel tunnel should exist in db
+        PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
+        pcepTunnelData.setPlspId(1);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
+        pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+        tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
+
+        tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+        tunnelProvider.updateTunnel(tunnel, path);
+        assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+    }
+
     @After
     public void tearDown() throws IOException {
         tunnelProvider.deactivate();
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/TunnelServiceAdapter.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/TunnelServiceAdapter.java
index 10be5f5..8e31508 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/TunnelServiceAdapter.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/TunnelServiceAdapter.java
@@ -94,17 +94,17 @@
 
     @Override
     public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId consumerId) {
-        return null;
+        return Collections.emptySet();
     }
 
     @Override
     public Collection<Tunnel> queryTunnel(Tunnel.Type type) {
-        return null;
+        return Collections.emptySet();
     }
 
     @Override
     public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
-        return null;
+        return Collections.emptySet();
     }
 
     @Override