[ONOS-4170] LSP-DB sync

Change-Id: Icda3afd9cca8d1fb8c58b44da6bc26064b300388
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
index bd2edf5..89a685b 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
@@ -30,6 +30,9 @@
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.IPv4;
+
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -38,6 +41,7 @@
 import org.apache.felix.scr.annotations.Service;
 import org.onlab.packet.IpAddress;
 import org.onlab.packet.IpPrefix;
+import org.onlab.packet.TCP;
 import org.onlab.util.Bandwidth;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
@@ -139,6 +143,7 @@
     private static final String TRUE = "true";
     private static final String FALSE = "false";
     private static final String END_OF_SYNC_IP_PREFIX = "0.0.0.0/32";
+    public static final int PCEP_PORT = 4189;
 
     private IdGenerator localLspIdIdGen;
     protected DistributedSet<Short> localLspIdFreeList;
@@ -635,7 +640,7 @@
                     LinkEvent linkEvent = (LinkEvent) e;
                     if (linkEvent.type() == LinkEvent.Type.LINK_REMOVED) {
                         tunnelService.queryTunnel(MPLS).forEach(t -> {
-                                if (t.path().links().contains(((Link) e.subject()))) {
+                                if (t.path().links().contains((e.subject()))) {
                                     // Check whether this ONOS instance is master for ingress device if yes,
                                     // recompute and send update
                                     checkForMasterAndUpdateTunnel(t.path().src().deviceId(), t);
@@ -949,12 +954,30 @@
         public void process(PacketContext context) {
             // Stop processing if the packet has been handled, since we
             // can't do any more to it.
-
             if (context.isHandled()) {
                 return;
             }
 
             InboundPacket pkt = context.inPacket();
+            if (pkt == null) {
+                return;
+            }
+
+            Ethernet ethernet = pkt.parsed();
+            if (ethernet == null || ethernet.getEtherType() != Ethernet.TYPE_IPV4) {
+                return;
+            }
+
+            IPv4 ipPacket = (IPv4) ethernet.getPayload();
+            if (ipPacket == null || ipPacket.getProtocol() != IPv4.PROTOCOL_TCP) {
+                return;
+            }
+
+            TCP tcp = (TCP) ipPacket.getPayload();
+            if (tcp == null || tcp.getDestinationPort() != PCEP_PORT) {
+                return;
+            }
+
             syncLabelDb(pkt.receivedFrom().deviceId());
         }
     }
diff --git a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java
index dee7218..2da22e5 100644
--- a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java
+++ b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java
@@ -26,7 +26,6 @@
 import static org.onosproject.net.MastershipRole.MASTER;
 
 import java.net.URISyntaxException;
-import java.nio.ByteBuffer;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -44,6 +43,7 @@
 import org.onlab.junit.TestUtils.TestUtilsException;
 import org.onlab.packet.Ethernet;
 import org.onlab.packet.IPv4;
+import org.onlab.packet.TCP;
 import org.onlab.util.Bandwidth;
 import org.onosproject.common.DefaultTopologyGraph;
 import org.onosproject.core.ApplicationId;
@@ -112,6 +112,7 @@
 import org.onosproject.store.service.TestStorageService;
 
 import com.google.common.collect.ImmutableSet;
+import static org.onosproject.pce.pceservice.PceManager.PCEP_PORT;
 
 /**
  * Tests the functions of PceManager.
@@ -675,21 +676,18 @@
      * Tests packet in to trigger label DB sync.
      */
     @Test
-    public void packetProcessingTest() throws URISyntaxException {
+    public void packetProcessingTest1() throws URISyntaxException {
 
         build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
 
-        final int srcHost = 2;
-        final int dstHost = 5;
-
         LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
         LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
 
         pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
         pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
 
-        ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(srcHost));
-        ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(dstHost));
+        ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
+        ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
 
         Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
                 .providerId(new ProviderId("eth", "1")).build();
@@ -697,24 +695,66 @@
         LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
         pceManager.pceStore.addAdjLabel(link1, link1Label);
 
-        Ethernet eth;
-        IPv4 ipv4;
+        TCP tcp = new TCP();
+        tcp.setDestinationPort(PCEP_PORT);
 
-        ipv4 = new IPv4();
-        eth = new Ethernet();
+        IPv4 ipv4 = new IPv4();
+        ipv4.setProtocol(IPv4.PROTOCOL_TCP);
+        ipv4.setPayload(tcp);
+
+        Ethernet eth = new Ethernet();
         eth.setEtherType(Ethernet.TYPE_IPV4);
         eth.setPayload(ipv4);
 
-        eth.setSourceMACAddress("00:00:00:10:00:0" + srcHost).setDestinationMACAddress("00:00:00:10:00:0" + dstHost);
-
-        InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(), PortNumber.portNumber(srcHost)),
-                                                       eth, ByteBuffer.wrap(eth.serialize()));
+        InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(),
+                                                                        PortNumber.portNumber(PCEP_PORT)),
+                                                       eth, null);
 
         pktProcessor.process(new MockPcepPacketContext(inPkt, null));
         assertThat(flowsDownloaded, is(4));
     }
 
     /**
+     * Tests faulty packet in to trigger label DB sync.
+     */
+    @Test
+    public void packetProcessingTest2() throws URISyntaxException {
+
+        build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
+
+        LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
+        LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
+
+        pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
+        pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
+
+        ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
+        ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
+
+        Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
+                .providerId(new ProviderId("eth", "1")).build();
+
+        LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
+        pceManager.pceStore.addAdjLabel(link1, link1Label);
+
+        TCP tcp = new TCP(); // Not set the pcep port.
+        IPv4 ipv4 = new IPv4();
+        ipv4.setProtocol(IPv4.PROTOCOL_TCP);
+        ipv4.setPayload(tcp);
+
+        Ethernet eth = new Ethernet();
+        eth.setEtherType(Ethernet.TYPE_IPV4);
+        eth.setPayload(ipv4);
+
+        InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(),
+                                                                        PortNumber.portNumber(PCEP_PORT)),
+                                                       eth, null);
+
+        pktProcessor.process(new MockPcepPacketContext(inPkt, null));
+        assertThat(flowsDownloaded, is(0));
+    }
+
+    /**
      * Tests tunnel events added and removed.
      */
     @Test
diff --git a/protocols/pcep/api/BUCK b/protocols/pcep/api/BUCK
index 8930a95..5ced968 100644
--- a/protocols/pcep/api/BUCK
+++ b/protocols/pcep/api/BUCK
@@ -2,6 +2,7 @@
     '//lib:CORE_DEPS',
     '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
     '//apps/pcep-api:onos-apps-pcep-api',
+    '//incubator/api:onos-incubator-api',
 ]
 
 osgi_jar_with_tests (
diff --git a/protocols/pcep/api/pom.xml b/protocols/pcep/api/pom.xml
index f334654..f514985 100644
--- a/protocols/pcep/api/pom.xml
+++ b/protocols/pcep/api/pom.xml
@@ -52,5 +52,9 @@
             <groupId>org.onosproject</groupId>
             <artifactId>onlab-misc</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-incubator-api</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClient.java b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClient.java
index 297d71e..c5cf003 100644
--- a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClient.java
+++ b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClient.java
@@ -19,6 +19,7 @@
 
 import org.onosproject.pcepio.protocol.PcepFactory;
 import org.onosproject.pcepio.protocol.PcepMessage;
+import org.onosproject.pcepio.protocol.PcepStateReport;
 
 /**
  * Represents to provider facing side of a path computation client(pcc).
@@ -165,4 +166,34 @@
      * @return delegation flag
      */
     Boolean delegationInfo(LspKey lspKey);
+
+    /**
+     * Creates a temporary cache to hold report messages received during LSPDB sync.
+     *
+     * @param pccId PCC id which is the key to store report messages
+     */
+    void initializeSyncMsgList(PccId pccId);
+
+    /**
+     * Returns the list of report messages received during LSPDB sync.
+     *
+     * @param pccId PCC id which is the key for all the report messages
+     * @return list of report messages received during LSPDB sync
+     */
+    List<PcepStateReport> getSyncMsgList(PccId pccId);
+
+    /**
+     * Removes the list of report messages received during LSPDB sync.
+     *
+     * @param pccId PCC id which is the key for all the report messages
+     */
+    void removeSyncMsgList(PccId pccId);
+
+    /**
+     * Adds report message received during LSPDB sync into temporary cache.
+     *
+     * @param pccId PCC id which is the key to store report messages
+     * @param rptMsg the report message to be stored
+     */
+    void addSyncMsgToList(PccId pccId, PcepStateReport rptMsg);
 }
diff --git a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClientController.java b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClientController.java
index fff6759..0f14778 100644
--- a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClientController.java
+++ b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClientController.java
@@ -85,6 +85,20 @@
     void removeNodeListener(PcepNodeListener listener);
 
     /**
+     * Register a listener for packet events.
+     *
+     * @param listener the listener to notify
+     */
+    void addPacketListener(PcepPacketListener listener);
+
+    /**
+     * Unregister a packet listener.
+     *
+     * @param listener the listener to unregister
+     */
+    void removePacketListener(PcepPacketListener listener);
+
+    /**
      * Send a message to a particular pcc client.
      *
      * @param pccId the id of the client to send message.
diff --git a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepEventListener.java b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepEventListener.java
index 7ba8ca7..c7c347a 100644
--- a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepEventListener.java
+++ b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepEventListener.java
@@ -15,6 +15,7 @@
  */
 package org.onosproject.pcep.controller;
 
+import org.onosproject.incubator.net.tunnel.Tunnel;
 import org.onosproject.pcepio.protocol.PcepMessage;
 /**
  * Notifies providers about PCEP message events.
@@ -28,4 +29,21 @@
      * @param msg the message
      */
     void handleMessage(PccId pccId, PcepMessage msg);
+
+    /**
+     * Handles end of LSPDB sync actions.
+     *
+     * @param tunnel the tunnel on which action needs to be taken
+     * @param endOfSyncAction the action that needs to be taken for the tunnel
+     */
+    void handleEndOfSyncAction(Tunnel tunnel, PcepLspSyncAction endOfSyncAction);
+
+    /**
+     * Handles sending PCEP message to client on end of LSPDB sync.
+     *
+     * @param pccId id of the pcc
+     * @param msg the message to be sent
+     * @param endOfSyncAction the action that needs to be taken in the message
+     */
+    void handleEndOfSyncAction(PccId pccId, PcepMessage msg, PcepLspSyncAction endOfSyncAction);
 }
diff --git a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepLspSyncAction.java b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepLspSyncAction.java
new file mode 100644
index 0000000..92ce8e6
--- /dev/null
+++ b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepLspSyncAction.java
@@ -0,0 +1,53 @@
+/*
+ * 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.pcep.controller;
+
+/**
+ * Representation of actions to be taken for LSPs on end of LSP-DB sync.
+ */
+public enum PcepLspSyncAction {
+
+    /**
+     * Specifies that delete message for PCE intiiated tunnel should be sent.
+     */
+    SEND_DELETE(0),
+
+    /**
+     * Specifies that update message should be sent.
+     */
+    SEND_UPDATE(1),
+
+    /**
+     * Specifies that the tunnel should be removed from PCE.
+     */
+    REMOVE(2),
+
+    /**
+     * Specifies that the status of the tunnel should be set as unstable.
+     */
+    UNSTABLE(3);
+
+    int value;
+
+    /**
+     * Assigns val with the value for actions to be taken for LSPs on end of LSP-DB sync.
+     *
+     * @param val sync status
+     */
+    PcepLspSyncAction(int val) {
+        value = val;
+    }
+}
diff --git a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepPacketListener.java b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepPacketListener.java
new file mode 100644
index 0000000..c2017ae
--- /dev/null
+++ b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepPacketListener.java
@@ -0,0 +1,22 @@
+/*
+ * 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.pcep.controller;
+
+public interface PcepPacketListener {
+
+    void sendPacketIn(PccId pccId);
+
+}
diff --git a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepAgent.java b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepAgent.java
index de95962..55d5614 100755
--- a/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepAgent.java
+++ b/protocols/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepAgent.java
@@ -73,4 +73,12 @@
      * @param pccId PCEP client ID
      */
     void deleteNode(PccId pccId);
+
+    /**
+     * Analyzes report messages received during LSP DB sync again tunnel store and takes necessary actions.
+     *
+     * @param pccId the id of pcc client
+     * @return success or failure
+     */
+    boolean analyzeSyncMsgList(PccId pccId);
 }
diff --git a/protocols/pcep/ctl/BUCK b/protocols/pcep/ctl/BUCK
index dd7e29c..ae62881 100644
--- a/protocols/pcep/ctl/BUCK
+++ b/protocols/pcep/ctl/BUCK
@@ -2,6 +2,7 @@
     '//lib:CORE_DEPS',
     '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
     '//protocols/pcep/api:onos-protocols-pcep-api',
+    '//incubator/api:onos-incubator-api',
 ]
 
 osgi_jar_with_tests (
diff --git a/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientControllerImpl.java b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientControllerImpl.java
index 19e2ce4..20c2856 100644
--- a/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientControllerImpl.java
+++ b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientControllerImpl.java
@@ -15,10 +15,16 @@
  */
 package org.onosproject.pcep.controller.impl;
 
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -28,25 +34,47 @@
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.Service;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelService;
+import org.onosproject.incubator.net.tunnel.Tunnel.State;
 import org.onosproject.net.device.DeviceService;
+import org.onosproject.pcep.controller.LspKey;
 import org.onosproject.pcep.controller.PccId;
 import org.onosproject.pcep.controller.PcepClient;
 import org.onosproject.pcep.controller.PcepClientController;
 import org.onosproject.pcep.controller.PcepClientListener;
 import org.onosproject.pcep.controller.PcepEventListener;
 import org.onosproject.pcep.controller.PcepNodeListener;
+import org.onosproject.pcep.controller.PcepPacketListener;
+import org.onosproject.pcep.controller.PcepSyncStatus;
 import org.onosproject.pcep.controller.driver.PcepAgent;
+import org.onosproject.pcepio.exceptions.PcepParseException;
+import org.onosproject.pcepio.protocol.PcInitiatedLspRequest;
 import org.onosproject.pcepio.protocol.PcepError;
 import org.onosproject.pcepio.protocol.PcepErrorInfo;
 import org.onosproject.pcepio.protocol.PcepErrorMsg;
 import org.onosproject.pcepio.protocol.PcepErrorObject;
 import org.onosproject.pcepio.protocol.PcepFactory;
+import org.onosproject.pcepio.protocol.PcepInitiateMsg;
+import org.onosproject.pcepio.protocol.PcepLspObject;
 import org.onosproject.pcepio.protocol.PcepMessage;
+import org.onosproject.pcepio.protocol.PcepReportMsg;
+import org.onosproject.pcepio.protocol.PcepStateReport;
+import org.onosproject.pcepio.types.PcepValueType;
+import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
+import org.onosproject.pcepio.types.SymbolicPathNameTlv;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Sets;
+import static com.google.common.base.Preconditions.checkNotNull;
 
+import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC;
+import static org.onosproject.pcep.controller.PcepLspSyncAction.REMOVE;
+import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_UPDATE;
+import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_DELETE;
+import static org.onosproject.pcep.controller.PcepLspSyncAction.UNSTABLE;
 import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_TYPE_19;
 import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5;
 
@@ -70,9 +98,22 @@
 
     protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
     protected Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet();
+    protected Set<PcepPacketListener> pcepPacketListener = Sets.newHashSet();
 
     private final Controller ctrl = new Controller();
 
+    public static final String BANDWIDTH = "bandwidth";
+    public static final String LSP_SIG_TYPE = "lspSigType";
+    public static final String PCC_TUNNEL_ID = "PccTunnelId";
+    public static final String PLSP_ID = "PLspId";
+    public static final String LOCAL_LSP_ID = "localLspId";
+    public static final String PCE_INIT = "pceInit";
+    public static final String COST_TYPE = "costType";
+    public static final String DELEGATE = "delegation";
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected TunnelService tunnelService;
+
     @Activate
     public void activate() {
         ctrl.start(agent);
@@ -120,6 +161,16 @@
     }
 
     @Override
+    public void addPacketListener(PcepPacketListener listener) {
+        pcepPacketListener.add(listener);
+    }
+
+    @Override
+    public void removePacketListener(PcepPacketListener listener) {
+        pcepPacketListener.remove(listener);
+    }
+
+    @Override
     public void writeMessage(PccId pccId, PcepMessage msg) {
         this.getClient(pccId).sendMessage(msg);
     }
@@ -180,8 +231,48 @@
         case REPORT:
             //Only update the listener if respective capability is supported else send PCEP-ERR msg
             if (pc.capability().statefulPceCapability()) {
-                for (PcepEventListener l : pcepEventListener) {
-                    l.handleMessage(pccId, msg);
+
+                ListIterator<PcepStateReport> listIterator = ((PcepReportMsg) msg).getStateReportList().listIterator();
+                while (listIterator.hasNext()) {
+                    PcepStateReport stateRpt = listIterator.next();
+                    if (stateRpt.getLspObject().getSFlag()) {
+                        if (pc.lspDbSyncStatus() != PcepSyncStatus.IN_SYNC) {
+                            // Initialize LSP DB sync and temporary cache.
+                            pc.setLspDbSyncStatus(PcepSyncStatus.IN_SYNC);
+                            pc.initializeSyncMsgList(pccId);
+                        }
+                        // Store stateRpt in temporary cache.
+                        pc.addSyncMsgToList(pccId, stateRpt);
+
+                        // Don't send to provider as of now.
+                        continue;
+                    } else {
+                        if (pc.lspDbSyncStatus() == PcepSyncStatus.IN_SYNC) {
+                            // Set end of LSPDB sync.
+                            pc.setLspDbSyncStatus(PcepSyncStatus.SYNCED);
+
+                            // Call packet provider to initiate label DB sync (only if PCECC capable).
+                            if (pc.capability().pceccCapability()) {
+                                pc.setLabelDbSyncStatus(IN_SYNC);
+                                for (PcepPacketListener l : pcepPacketListener) {
+                                    l.sendPacketIn(pccId);
+                                }
+                            } else {
+                                // If label db sync is not to be done, handle end of LSPDB sync actions.
+                                agent.analyzeSyncMsgList(pccId);
+                            }
+                            continue;
+                        }
+                    }
+
+                    // It's a usual report message while sync is not undergoing. So process it immediately.
+                    LinkedList<PcepStateReport> llPcRptList = new LinkedList<>();
+                    llPcRptList.add(stateRpt);
+                    PcepMessage pcReportMsg = pc.factory().buildReportMsg().setStateReportList((llPcRptList))
+                            .build();
+                    for (PcepEventListener l : pcepEventListener) {
+                        l.handleMessage(pccId, pcReportMsg);
+                    }
                 }
             } else {
                 // Send PCEP-ERROR message.
@@ -304,5 +395,162 @@
                 l.deleteNode(pccId);
             }
         }
+
+        @SuppressWarnings({ "unchecked", "rawtypes" })
+        @Override
+        public boolean analyzeSyncMsgList(PccId pccId) {
+            PcepClient pc = getClient(pccId);
+            /*
+             * PLSP_ID is null while tunnel is created at PCE and PCInit msg carries it as 0. It is allocated by PCC and
+             * in that case it becomes the first PCRpt msg from PCC for this LSP, and hence symbolic path name must be
+             * carried in the PCRpt msg. Draft says: The SYMBOLIC-PATH-NAME TLV "MUST" be included in the LSP object in
+             * the LSP State Report (PCRpt) message when during a given PCEP session an LSP is "first" reported to a
+             * PCE. So two separate lists with separate keys are maintained.
+             */
+            Map<LspKey, Tunnel> preSyncLspDbByKey = new HashMap<>();
+            Map<String, Tunnel> preSyncLspDbByName = new HashMap<>();
+
+            // Query tunnel service and fetch all the tunnels with this PCC as ingress.
+            // Organize into two maps, with LSP key if known otherwise with symbolic path name, for quick search.
+            Collection<Tunnel> queriedTunnels = tunnelService.queryTunnel(Tunnel.Type.MPLS);
+            for (Tunnel tunnel : queriedTunnels) {
+                if (((IpTunnelEndPoint) tunnel.src()).ip().equals(pccId.ipAddress())) {
+                    String pLspId = tunnel.annotations().value(PLSP_ID);
+                    if (pLspId != null) {
+                        String localLspId = tunnel.annotations().value(LOCAL_LSP_ID);
+                        checkNotNull(localLspId);
+                        LspKey lspKey = new LspKey(Integer.valueOf(pLspId), Short.valueOf(localLspId));
+                        preSyncLspDbByKey.put(lspKey, tunnel);
+                    } else {
+                        preSyncLspDbByName.put(tunnel.tunnelName().value(), tunnel);
+                    }
+                }
+            }
+
+            List<PcepStateReport> syncStateRptList = pc.getSyncMsgList(pccId);
+            Iterator<PcepStateReport> stateRptListIterator = syncStateRptList.iterator();
+
+            // For every report, fetch PLSP id, local LSP id and symbolic path name from the message.
+            while (syncStateRptList.iterator().hasNext()) {
+                PcepStateReport stateRpt = stateRptListIterator.next();
+                Tunnel tunnel = null;
+
+                PcepLspObject lspObj = stateRpt.getLspObject();
+                ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
+                StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv = null;
+                SymbolicPathNameTlv pathNameTlv = null;
+
+                while (listTlvIterator.hasNext()) {
+                    PcepValueType tlv = listTlvIterator.next();
+                    switch (tlv.getType()) {
+                    case StatefulIPv4LspIdentifiersTlv.TYPE:
+                        ipv4LspIdenTlv = (StatefulIPv4LspIdentifiersTlv) tlv;
+                        break;
+
+                    case SymbolicPathNameTlv.TYPE:
+                        pathNameTlv = (SymbolicPathNameTlv) tlv;
+                        break;
+
+                    default:
+                        break;
+                    }
+                }
+
+                LspKey lspKeyOfRpt = new LspKey(lspObj.getPlspId(), ipv4LspIdenTlv.getLspId());
+                tunnel = preSyncLspDbByKey.get(lspKeyOfRpt);
+                // PCE tunnel is matched with PCRpt LSP. Now delete it from the preSyncLspDb list as the residual
+                // non-matching list will be processed at the end.
+                if (tunnel != null) {
+                    preSyncLspDbByKey.remove(lspKeyOfRpt);
+                } else if (pathNameTlv != null) {
+                    tunnel = preSyncLspDbByName.get(Arrays.toString(pathNameTlv.getValue()));
+                    if (tunnel != null) {
+                        preSyncLspDbByName.remove(tunnel.tunnelName());
+                    }
+                }
+
+                if (tunnel == null) {
+                    // If remove flag is set, and tunnel is not known to PCE, ignore it.
+                    if (lspObj.getCFlag() && !lspObj.getRFlag()) {
+                        // For initiated LSP, need to send PCInit delete msg.
+                        try {
+                            PcInitiatedLspRequest releaseLspRequest = pc.factory().buildPcInitiatedLspRequest()
+                                    .setLspObject(lspObj).build();
+                            LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList
+                                    = new LinkedList<PcInitiatedLspRequest>();
+                            llPcInitiatedLspRequestList.add(releaseLspRequest);
+
+                            PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg()
+                                    .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList).build();
+
+                            for (PcepEventListener l : pcepEventListener) {
+                                l.handleEndOfSyncAction(pccId, pcInitiateMsg, SEND_DELETE);
+                            }
+
+                        } catch (PcepParseException e) {
+                            log.error("Exception occured while sending initiate delete message {}", e.getMessage());
+                        }
+                    }
+                    continue;
+                }
+
+                if (!lspObj.getCFlag()) {
+                    // For learned LSP process both add/update PCRpt.
+                    LinkedList<PcepStateReport> llPcRptList = new LinkedList<>();
+                    llPcRptList.add(stateRpt);
+                    PcepMessage pcReportMsg = pc.factory().buildReportMsg().setStateReportList((llPcRptList))
+                            .build();
+
+                    for (PcepEventListener l : pcepEventListener) {
+                        l.handleMessage(pccId, pcReportMsg);
+                    }
+                    continue;
+                }
+
+                // Implied that tunnel != null and lspObj.getCFlag() is set
+                // State different for PCC sent LSP and PCE known LSP, send PCUpd msg.
+                State tunnelState = PcepLspStatus
+                        .getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]);
+                if (tunnelState != tunnel.state()) {
+                    for (PcepEventListener l : pcepEventListener) {
+                        l.handleEndOfSyncAction(tunnel, SEND_UPDATE);
+                    }
+                }
+            }
+
+            // Check which tunnels are extra at PCE that were not reported by PCC.
+            Map<Object, Tunnel> preSyncLspDb = (Map) preSyncLspDbByKey;
+            handleResidualTunnels(preSyncLspDb);
+            preSyncLspDbByKey = null;
+
+            preSyncLspDb = (Map) preSyncLspDbByName;
+            handleResidualTunnels(preSyncLspDb);
+            preSyncLspDbByName = null;
+            preSyncLspDb = null;
+
+            pc.removeSyncMsgList(pccId);
+            return true;
+        }
+
+        /*
+         * Go through the tunnels which are known by PCE but were not reported by PCC during LSP DB sync and take
+         * appropriate actions.
+         */
+        private void handleResidualTunnels(Map<Object, Tunnel> preSyncLspDb) {
+            for (Tunnel pceExtraTunnel : preSyncLspDb.values()) {
+                if (pceExtraTunnel.annotations().value(PCE_INIT) == null
+                        || "false".equalsIgnoreCase(pceExtraTunnel.annotations().value(PCE_INIT))) {
+                    // PCC initiated tunnels should be removed from tunnel store.
+                    for (PcepEventListener l : pcepEventListener) {
+                        l.handleEndOfSyncAction(pceExtraTunnel, REMOVE);
+                    }
+                } else {
+                    // PCE initiated tunnels should be initiated again.
+                    for (PcepEventListener l : pcepEventListener) {
+                        l.handleEndOfSyncAction(pceExtraTunnel, UNSTABLE);
+                    }
+                }
+            }
+        }
     }
 }
diff --git a/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientImpl.java b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientImpl.java
index ac51371..a62a611 100644
--- a/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientImpl.java
+++ b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientImpl.java
@@ -19,6 +19,8 @@
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.RejectedExecutionException;
@@ -36,6 +38,7 @@
 import org.onosproject.pcepio.protocol.PcepFactories;
 import org.onosproject.pcepio.protocol.PcepFactory;
 import org.onosproject.pcepio.protocol.PcepMessage;
+import org.onosproject.pcepio.protocol.PcepStateReport;
 import org.onosproject.pcepio.protocol.PcepVersion;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -70,6 +73,7 @@
     private byte sessionId;
     private PcepPacketStatsImpl pktStats;
     private Map<LspKey, Boolean> lspDelegationInfo;
+    private Map<PccId, List<PcepStateReport>> sycRptCache = new HashMap<>();
 
     @Override
     public void init(PccId pccId, PcepVersion pcepVersion, PcepPacketStats pktStats) {
@@ -192,7 +196,14 @@
 
     @Override
     public void setLabelDbSyncStatus(PcepSyncStatus syncStatus) {
+
+        PcepSyncStatus syncOldStatus = labelDbSyncStatus();
         this.labelDbSyncStatus = syncStatus;
+
+        if ((syncOldStatus == PcepSyncStatus.IN_SYNC) && (syncStatus == PcepSyncStatus.SYNCED)) {
+            // Perform end of LSP DB sync actions.
+            this.agent.analyzeSyncMsgList(pccId);
+        }
     }
 
     @Override
@@ -254,6 +265,29 @@
     }
 
     @Override
+    public void initializeSyncMsgList(PccId pccId) {
+        List<PcepStateReport> rptMsgList = new LinkedList<>();
+        sycRptCache.put(pccId, rptMsgList);
+    }
+
+    @Override
+    public List<PcepStateReport> getSyncMsgList(PccId pccId) {
+        return sycRptCache.get(pccId);
+    }
+
+    @Override
+    public void removeSyncMsgList(PccId pccId) {
+        sycRptCache.remove(pccId);
+    }
+
+    @Override
+    public void addSyncMsgToList(PccId pccId, PcepStateReport rptMsg) {
+        List<PcepStateReport> rptMsgList = sycRptCache.get(pccId);
+        rptMsgList.add(rptMsg);
+        sycRptCache.put(pccId, rptMsgList);
+    }
+
+    @Override
     public boolean isOptical() {
         return false;
     }
diff --git a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepLspStatus.java b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepLspStatus.java
similarity index 94%
rename from providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepLspStatus.java
rename to protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepLspStatus.java
index ef628ed..79ed9fe 100644
--- a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepLspStatus.java
+++ b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepLspStatus.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.provider.pcep.tunnel.impl;
+package org.onosproject.pcep.controller.impl;
 
 import org.onosproject.incubator.net.tunnel.Tunnel.State;
 
@@ -51,6 +51,7 @@
      * Returns the applicable PCEP LSP status corresponding to ONOS tunnel state.
      *
      * @param tunnelState ONOS tunnel state
+     * @return LSP status as per protocol
      */
     public static PcepLspStatus getLspStatusFromTunnelStatus(State tunnelState) {
 
@@ -76,6 +77,7 @@
      * Returns the applicable ONOS tunnel state corresponding to PCEP LSP status.
      *
      * @param lspState PCEP LSP status
+     * @return tunnel state
      */
     public static State getTunnelStatusFromLspStatus(PcepLspStatus lspState) {
 
diff --git a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMetricObjectVer1.java b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMetricObjectVer1.java
index 1ac1340..6e82ffd 100644
--- a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMetricObjectVer1.java
+++ b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMetricObjectVer1.java
@@ -57,6 +57,10 @@
     public static final int BFLAG_RESET = 0;
     public static final byte CFLAG_CHECK = 0x02;
 
+    public static final byte IGP_METRIC = 0x01;
+    public static final byte TE_METRIC = 0x02;
+    public static final byte HOP_COUNT_METRIC = 0x03;
+
     static final PcepObjectHeader DEFAULT_METRIC_OBJECT_HEADER = new PcepObjectHeader(METRIC_OBJ_CLASS,
             METRIC_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED,
             METRIC_OBJ_MINIMUM_LENGTH);
diff --git a/providers/pcep/packet/pom.xml b/providers/pcep/packet/pom.xml
new file mode 100644
index 0000000..4bc94bd
--- /dev/null
+++ b/providers/pcep/packet/pom.xml
@@ -0,0 +1,34 @@
+<!--
+  ~ 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.
+  -->
+<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.7.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <artifactId>onos-pcep-provider-packet</artifactId>
+    <packaging>bundle</packaging>
+    <description>PCEP packet provider</description>
+    <dependencies>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-pcep-controller-api</artifactId>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/PcepPacketProvider.java b/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/PcepPacketProvider.java
new file mode 100644
index 0000000..48f2408
--- /dev/null
+++ b/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/PcepPacketProvider.java
@@ -0,0 +1,140 @@
+package org.onosproject.provider.pcep.packet.impl;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+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.onlab.packet.Ethernet;
+import org.onlab.packet.IPv4;
+import org.onlab.packet.TCP;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.packet.DefaultInboundPacket;
+import org.onosproject.net.packet.DefaultPacketContext;
+import org.onosproject.net.packet.InboundPacket;
+import org.onosproject.net.packet.OutboundPacket;
+import org.onosproject.net.packet.PacketProvider;
+import org.onosproject.net.packet.PacketProviderRegistry;
+import org.onosproject.net.packet.PacketProviderService;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.pcep.controller.PccId;
+import org.onosproject.pcep.controller.PcepClientController;
+import org.onosproject.pcep.controller.PcepPacketListener;
+import org.slf4j.Logger;
+
+/**
+ * Provider which uses an PCEP controller to process packets.
+ */
+@Component(immediate = true)
+@Service
+public class PcepPacketProvider extends AbstractProvider implements PacketProvider {
+
+    private static final Logger log = getLogger(PcepPacketProvider.class);
+    static final String PROVIDER_ID = "org.onosproject.provider.packet.pcep";
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected PacketProviderRegistry packetProviderRegistry;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected PcepClientController pcepClientController;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceService deviceService;
+
+    PacketProviderService packetProviderService;
+
+    private InnerPacketProvider listener = new InnerPacketProvider();
+    public static final String LSRID = "lsrId";
+    public static final int PCEP_PORT = 4189;
+
+    /**
+     * Creates a Packet provider.
+     */
+    public PcepPacketProvider() {
+        super(new ProviderId("pcep", PROVIDER_ID));
+    }
+
+    @Activate
+    public void activate() {
+        packetProviderService = packetProviderRegistry.register(this);
+        pcepClientController.addPacketListener(listener);
+        log.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        packetProviderRegistry.unregister(this);
+        pcepClientController.removePacketListener(listener);
+        log.info("Stopped");
+    }
+
+    private class InnerPacketProvider implements PcepPacketListener {
+        @Override
+        public void sendPacketIn(PccId pccId) {
+            TCP tcp = new TCP();
+            // Set the well known PCEP port. To be used to decide to process/discard the packet while processing.
+            tcp.setDestinationPort(PCEP_PORT);
+
+            IPv4 ipv4 = new IPv4();
+            ipv4.setProtocol(IPv4.PROTOCOL_TCP);
+            ipv4.setPayload(tcp);
+
+            Ethernet eth = new Ethernet();
+            eth.setEtherType(Ethernet.TYPE_IPV4);
+            eth.setPayload(ipv4);
+
+            // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
+            String lsrId = String.valueOf(pccId.ipAddress());
+            DeviceId pccDeviceId = null;
+
+            // Find PCC deviceID from lsrId stored as annotations
+            Iterable<Device> devices = deviceService.getAvailableDevices();
+            for (Device dev : devices) {
+                if ("L3".equals(dev.annotations().value(AnnotationKeys.TYPE))
+                        && lsrId.equals(dev.annotations().value(LSRID))) {
+                    pccDeviceId = dev.id();
+                    break;
+                }
+            }
+
+            if (pccDeviceId == null) {
+                return;
+            }
+
+            InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(pccDeviceId,
+                                                                            PortNumber.portNumber(PCEP_PORT)),
+                                                           eth, null);
+
+            packetProviderService.processPacket(new PcepPacketContext(inPkt, null));
+        }
+    }
+
+    // Minimal PacketContext to make core and applications happy.
+    private final class PcepPacketContext extends DefaultPacketContext {
+        private PcepPacketContext(InboundPacket inPkt, OutboundPacket outPkt) {
+            super(System.currentTimeMillis(), inPkt, outPkt, false);
+        }
+
+        @Override
+        public void send() {
+            // We don't send anything out.
+            return;
+        }
+    }
+
+    @Override
+    public void emit(OutboundPacket packet) {
+        // Nothing to emit
+        return;
+
+    }
+}
diff --git a/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/package-info.java b/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/package-info.java
new file mode 100644
index 0000000..8e1ab9a
--- /dev/null
+++ b/providers/pcep/packet/src/main/java/org/onosproject/provider/pcep/packet/impl/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+/**
+ *Provider that uses PCEP controller as a means to send packets.
+ */
+package org.onosproject.provider.pcep.packet.impl;
\ No newline at end of file
diff --git a/providers/pcep/pom.xml b/providers/pcep/pom.xml
index 238d6f7..5597ca4 100644
--- a/providers/pcep/pom.xml
+++ b/providers/pcep/pom.xml
@@ -28,5 +28,6 @@
         <module>topology</module>
         <module>tunnel</module>
         <module>app</module>
+        <module>packet</module>
   </modules>
 </project>
\ No newline at end of file
diff --git a/providers/pcep/topology/src/test/java/org/onosproject/provider/pcep/topology/impl/PcepClientAdapter.java b/providers/pcep/topology/src/test/java/org/onosproject/provider/pcep/topology/impl/PcepClientAdapter.java
index 8f9c3c4..853bfd5 100644
--- a/providers/pcep/topology/src/test/java/org/onosproject/provider/pcep/topology/impl/PcepClientAdapter.java
+++ b/providers/pcep/topology/src/test/java/org/onosproject/provider/pcep/topology/impl/PcepClientAdapter.java
@@ -31,6 +31,7 @@
 import org.onosproject.pcepio.protocol.PcepFactories;
 import org.onosproject.pcepio.protocol.PcepFactory;
 import org.onosproject.pcepio.protocol.PcepMessage;
+import org.onosproject.pcepio.protocol.PcepStateReport;
 import org.onosproject.pcepio.protocol.PcepVersion;
 
 /**
@@ -161,4 +162,28 @@
     public Boolean delegationInfo(LspKey lspKey) {
         return lspDelegationInfo.get(lspKey);
     }
+
+    @Override
+    public void initializeSyncMsgList(PccId pccId) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public List<PcepStateReport> getSyncMsgList(PccId pccId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void removeSyncMsgList(PccId pccId) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void addSyncMsgToList(PccId pccId, PcepStateReport rptMsg) {
+        // TODO Auto-generated method stub
+
+    }
 }
diff --git a/providers/pcep/topology/src/test/java/org/onosproject/provider/pcep/topology/impl/PcepClientControllerAdapter.java b/providers/pcep/topology/src/test/java/org/onosproject/provider/pcep/topology/impl/PcepClientControllerAdapter.java
index 5153ab2..74660b1 100644
--- a/providers/pcep/topology/src/test/java/org/onosproject/provider/pcep/topology/impl/PcepClientControllerAdapter.java
+++ b/providers/pcep/topology/src/test/java/org/onosproject/provider/pcep/topology/impl/PcepClientControllerAdapter.java
@@ -32,6 +32,7 @@
 import org.onosproject.pcep.controller.PcepClientListener;
 import org.onosproject.pcep.controller.PcepEventListener;
 import org.onosproject.pcep.controller.PcepNodeListener;
+import org.onosproject.pcep.controller.PcepPacketListener;
 import org.onosproject.pcep.controller.driver.PcepAgent;
 import org.onosproject.pcepio.protocol.PcepError;
 import org.onosproject.pcepio.protocol.PcepErrorInfo;
@@ -280,5 +281,23 @@
                 l.deleteNode(pccId);
             }
         }
+
+        @Override
+        public boolean analyzeSyncMsgList(PccId pccId) {
+            // TODO Auto-generated method stub
+            return false;
+        }
+    }
+
+    @Override
+    public void addPacketListener(PcepPacketListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void removePacketListener(PcepPacketListener listener) {
+        // TODO Auto-generated method stub
+
     }
 }
diff --git a/providers/pcep/tunnel/BUCK b/providers/pcep/tunnel/BUCK
index ce09ba2..465f5fd 100644
--- a/providers/pcep/tunnel/BUCK
+++ b/providers/pcep/tunnel/BUCK
@@ -6,6 +6,7 @@
     '//incubator/api:onos-incubator-api',
     '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
     '//protocols/pcep/api:onos-protocols-pcep-api',
+    '//protocols/pcep/ctl:onos-protocols-pcep-ctl',
 ]
 
 TEST_DEPS = [
diff --git a/providers/pcep/tunnel/pom.xml b/providers/pcep/tunnel/pom.xml
index cb7b18c..2eaaa68 100644
--- a/providers/pcep/tunnel/pom.xml
+++ b/providers/pcep/tunnel/pom.xml
@@ -50,5 +50,10 @@
             <version>${project.version} </version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-pcep-controller-impl</artifactId>
+            <version>${project.version} </version>
+        </dependency>
     </dependencies>
 </project>
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
index fbfeda7..c77187a 100644
--- 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
@@ -79,7 +79,8 @@
 import org.onosproject.pcep.controller.PcepClientController;
 import org.onosproject.pcep.controller.PcepClientListener;
 import org.onosproject.pcep.controller.PcepEventListener;
-import org.onosproject.pcep.controller.PcepSyncStatus;
+import org.onosproject.pcep.controller.PcepLspSyncAction;
+import org.onosproject.pcep.controller.impl.PcepLspStatus;
 import org.onosproject.pcepio.exceptions.PcepParseException;
 import org.onosproject.pcepio.protocol.PcInitiatedLspRequest;
 import org.onosproject.pcepio.protocol.PcepAttribute;
@@ -89,6 +90,7 @@
 import org.onosproject.pcepio.protocol.PcepInitiateMsg;
 import org.onosproject.pcepio.protocol.PcepLspObject;
 import org.onosproject.pcepio.protocol.PcepMessage;
+import org.onosproject.pcepio.protocol.PcepMetricObject;
 import org.onosproject.pcepio.protocol.PcepMsgPath;
 import org.onosproject.pcepio.protocol.PcepReportMsg;
 import org.onosproject.pcepio.protocol.PcepSrpObject;
@@ -113,7 +115,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
-import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
@@ -134,15 +135,18 @@
 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.PcepAnnotationKeys.PCE_INIT;
 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.DELEGATE;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.COST_TYPE;
 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.CREATE;
 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.DELETE;
 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.LSP_STATE_RPT;
 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.UPDATE;
-import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC;
-import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED;
 import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
+import static org.onosproject.pcep.controller.PcepLspSyncAction.REMOVE;
+import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_UPDATE;
+import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_DELETE;
+import static org.onosproject.pcepio.protocol.ver1.PcepMetricObjectVer1.IGP_METRIC;
+import static org.onosproject.pcepio.protocol.ver1.PcepMetricObjectVer1.TE_METRIC;
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
@@ -206,10 +210,6 @@
     protected PcepTunnelApiMapper pcepTunnelApiMapper = new PcepTunnelApiMapper();
     private static final int DEFAULT_BANDWIDTH_VALUE = 10;
 
-    private Map<IpAddress, Map<TunnelId, Tunnel>> preSyncLspDbMap = new HashMap<>();
-    private Map<IpAddress, List<Tunnel>> syncCompleteDeleteList = new HashMap<>();
-    private Map<IpAddress, List<Tunnel>> syncCompleteUpdateList = new HashMap<>();
-
     /**
      * Creates a Tunnel provider.
      */
@@ -760,7 +760,6 @@
                                                                 path,
                                                                 annotations);
         return tunnel;
-
     }
 
     /**
@@ -1177,41 +1176,8 @@
                         log.debug("SRP ID in handle message " + srpId);
 
                         if (!(pcepTunnelApiMapper.checkFromTunnelRequestQueue(srpId))) {
-
-                            // Check the sync status
-                            if (lspObj.getSFlag()) {
-                                if (pcepClientController.getClient(pccId).lspDbSyncStatus() != IN_SYNC) {
-                                    pcepClientController.getClient(pccId).setLspDbSyncStatus(IN_SYNC);
-
-                                    // On starting LSP-DB sync, store LSP DB locally for this PCC.
-                                    Map<TunnelId, Tunnel> preSyncLspDb = new HashMap<>();
-                                    Collection<Tunnel> queriedTunnels = tunnelService.queryTunnel(MPLS);
-
-                                    for (Tunnel tunnel : queriedTunnels) {
-                                        if (((IpTunnelEndPoint) tunnel.src()).ip().equals(pccId.ipAddress())) {
-                                            preSyncLspDb.put(tunnel.tunnelId(), tunnel);
-                                        }
-                                    }
-
-                                    preSyncLspDbMap.put(pccId.ipAddress(), preSyncLspDb);
-                                    syncCompleteDeleteList.put(pccId.ipAddress(), new LinkedList<>());
-                                    syncCompleteUpdateList.put(pccId.ipAddress(), new LinkedList<>());
-                                }
-                                handleRptWithoutSrpId(stateRpt, pccId, IN_SYNC);
-                                continue;
-
-                            } else if (pcepClientController.getClient(pccId).lspDbSyncStatus() == IN_SYNC) {
-                                // If sync flag is not set in the msg, and the
-                                // previous state was "in sync" means this is
-                                // end of sync message. PCRpt for end of sync
-                                // does not carry any LSP report.
-                                pcepClientController.getClient(pccId).setLspDbSyncStatus(SYNCED);
-                                handleEndOfSyncAction(pccId);
-                                continue;
-                            }
-
-                            // For PCRpt without matching SRP id not during LSPDB sync.
-                            handleRptWithoutSrpId(stateRpt, pccId, SYNCED);
+                            // For PCRpt without matching SRP id.
+                            handleRptWithoutSrpId(stateRpt, pccId);
                             continue;
                         }
 
@@ -1306,8 +1272,19 @@
         }
 
         private SparseAnnotations getAnnotations(PcepLspObject lspObj, StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv,
-                float bandwidth, LspType lspType) {
-            SparseAnnotations annotations = DefaultAnnotations.builder()
+                float bandwidth, LspType lspType, String costType) {
+
+            Builder builder = DefaultAnnotations.builder();
+
+            /*
+             * [RFC 5440] The absence of the METRIC object MUST be interpreted by the PCE as a path computation request
+             * for which no constraints need be applied to any of the metrics.
+             */
+            if (costType != null) {
+                builder.set(COST_TYPE, costType);
+            }
+
+            SparseAnnotations annotations = builder
                     .set(BANDWIDTH, (new Float(bandwidth)).toString()).set(LSP_SIG_TYPE, lspType.name())
                     .set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId()))
                     .set(PLSP_ID, String.valueOf(lspObj.getPlspId()))
@@ -1340,8 +1317,9 @@
             return lspType;
         }
 
-        private void handleRptWithoutSrpId(PcepStateReport stateRpt, PccId pccId, PcepSyncStatus syncStatus) {
+        private void handleRptWithoutSrpId(PcepStateReport stateRpt, PccId pccId) {
             ProviderId providerId = new ProviderId("pcep", PROVIDER_ID);
+            String costType = null;
             PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath();
             checkNotNull(msgPath);
             PcepEroObject eroObj = msgPath.getEroObject();
@@ -1349,7 +1327,30 @@
                 log.error("ERO object is null in report message.");
                 return;
             }
-            Path path = buildPathFromEroObj(eroObj, providerId);
+
+            PcepAttribute attributes = msgPath.getPcepAttribute();
+            int cost = 0;
+            if (attributes != null && attributes.getMetricObjectList() != null) {
+                ListIterator<PcepMetricObject> iterator = attributes.getMetricObjectList().listIterator();
+                PcepMetricObject metricObj = iterator.next();
+
+                while (metricObj != null) {
+                    if (metricObj.getBType() == IGP_METRIC) {
+                        costType = "COST";
+                    } else if (metricObj.getBType() == TE_METRIC) {
+                        costType = "TE_COST";
+                    }
+
+                    if (costType != null) {
+                        cost = metricObj.getMetricVal();
+                        log.debug("Path cost {}", cost);
+                        break;
+                    }
+                    metricObj = iterator.next();
+                }
+            }
+
+            Path path = buildPathFromEroObj(eroObj, providerId, cost);
 
             float bandwidth = 0;
             if (msgPath.getBandwidthObject() != null) {
@@ -1443,48 +1444,23 @@
                     return;
                 }
 
-                if (lspObj.getCFlag()) {
-                    /*
-                     * While in sync, if PCRpt is received for PCE init LSP and PCE doesn't have entry, mark to send
-                     * delete message on end of sync.
-                     */
-                    annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType);
-
-                    // Generate tunnel id for the temporary tunnel.
-                    String onosTunnelId = "PCC" + String.valueOf(ipv4LspIdenTlv.getTunnelId());
-                    Tunnel tunnelToBeDeleted = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS,
-                                                                 new DefaultGroupId(0), TunnelId.valueOf(onosTunnelId),
-                                                                 TunnelName.tunnelName(String
-                                                                         .valueOf(pathNameTlv.getValue())),
-                                                                 path, annotations);
-                    /*
-                     * Need to send PCInitiate delete msg for a tunnel which does not exist at PCE. For that some dummy
-                     * data-structures need to be populated.
-                     */
-                    PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnelToBeDeleted, path, RequestType.DELETE);
-                    pcepTunnelData.setPlspId(lspObj.getPlspId());
-                    pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv);
-                    pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
-                    pcepTunnelApiMapper.handleCreateTunnelRequestQueue(0, pcepTunnelData);
-
-                    /*
-                     * Add to the list of tunnels for which PCInit delete will be sent at the end of sync.
-                     */
-                    List<Tunnel> tunnelToBeDeletedList = syncCompleteDeleteList.get(pccId.ipAddress());
-                    tunnelToBeDeletedList.add(tunnelToBeDeleted);
-                    syncCompleteDeleteList.put(pccId.ipAddress(), tunnelToBeDeletedList);
-                    return;
-                }
                 DeviceId deviceId = getDevice(pccId);
                 if (deviceId == null) {
                     log.error("Ingress deviceId not found");
                     return;
                 }
-                annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType);
+                annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType, costType);
 
                 td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
                         0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path,
                         annotations);
+
+                // Do not support PCC initiated LSP after LSP DB sync is completed.
+                if (!lspObj.getSFlag() && !lspObj.getCFlag()) {
+                    log.error("Received PCC initiated LSP while not in sync.");
+                    return;
+                }
+
                 /*
                  * If ONOS instance is master for PCC then set delegated flag as annotation and add the tunnel to store.
                  * Because all LSPs need not be delegated, hence mastership for the PCC is confirmed whereas not the
@@ -1523,35 +1499,24 @@
 
             //delegated owner will update can be a master or non-master
             if (lspObj.getDFlag()) {
-                annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType);
+                annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType, costType);
                 td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
                         0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path,
                         annotations);
                 tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId);
             }
-
-            if ((syncStatus == IN_SYNC) && (lspObj.getCFlag()) && (tunnelState != tunnel.state())) {
-                // Mark to send PCUpd msg with state known at PCE.
-                List<Tunnel> tunnelToBeUpdateList = syncCompleteUpdateList.get(pccId.ipAddress());
-                tunnelToBeUpdateList.add(tunnel);
-                syncCompleteUpdateList.put(pccId.ipAddress(), tunnelToBeUpdateList);
-                return;
-            }
-            removeOrUpdatetunnel(tunnel, pccId, lspObj, providerId, syncStatus, tunnelState);
+            removeOrUpdatetunnel(tunnel, pccId, lspObj, providerId, tunnelState);
             return;
         }
 
         private void removeOrUpdatetunnel(Tunnel tunnel, PccId pccId, PcepLspObject lspObj, ProviderId providerId,
-                PcepSyncStatus syncStatus, State tunnelState) {
+                State tunnelState) {
             DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), tunnel.dst(),
                     tunnel.type(), tunnel.groupId(), providerId, tunnel.tunnelName(), tunnel.path(),
                     (SparseAnnotations) tunnel.annotations());
             if (lspObj.getRFlag()) {
                 tunnelRemoved(td);
             } else {
-                if (syncStatus == IN_SYNC) {
-                    markLspDbEntryAsLatest(pccId, tunnel.tunnelId());
-                }
                 tunnelUpdated(td, tunnelState);
             }
         }
@@ -1576,9 +1541,10 @@
          *
          * @param eroObj ERO object
          * @param providerId provider id
+         * @param cost cost of path
          * @return path object
          */
-        private Path buildPathFromEroObj(PcepEroObject eroObj, ProviderId providerId) {
+        private Path buildPathFromEroObj(PcepEroObject eroObj, ProviderId providerId, int cost) {
             checkNotNull(eroObj);
             List<Link> links = new ArrayList<Link>();
             LinkedList<PcepValueType> llSubObj = eroObj.getSubObjects();
@@ -1618,7 +1584,8 @@
                     // the other sub objects are not required
                 }
             }
-            return new DefaultPath(providerId, links, 0, EMPTY);
+
+            return new DefaultPath(providerId, links, cost, EMPTY);
         }
 
         @Override
@@ -1637,44 +1604,14 @@
             TunnelStatistics tunnelStatistics = buildTunnelStatistics(pcepTunnelStatistics);
             tunnelStatisticsMap.put(id, tunnelStatistics);
         }
-    }
 
-    @Override
-    public Tunnel tunnelQueryById(TunnelId tunnelId) {
-        return service.tunnelQueryById(tunnelId);
-    }
+        @Override
+        public void handleEndOfSyncAction(Tunnel tunnel, PcepLspSyncAction endOfSyncAction) {
 
-    /**
-     * Removes the entry from temporary copy of LSPDB, signifying its status as upto date.
-     *
-     * @param pccId the key for temporary LSPDB
-     * @param tunnelId the tunnel id for which information is updated.
-     */
-    private void markLspDbEntryAsLatest(PccId pccId, TunnelId tunnelId) {
-        checkNotNull(pccId);
-        checkNotNull(tunnelId);
-
-        Map<TunnelId, Tunnel> preSyncLspDb = preSyncLspDbMap.get(pccId.ipAddress());
-        checkNotNull(preSyncLspDb);
-
-        preSyncLspDb.remove(tunnelId);
-        preSyncLspDbMap.put(pccId.ipAddress(), preSyncLspDb);
-    }
-
-    /**
-     * Sends PCInit, PCInit(R) or PCUpd messages for initiated LSPs at the end
-     * of LSP DB sync based on actions decided while sync was in progress. Also
-     * triggers label DB sync.
-     *
-     * @param pccId the key for temporary DBs storing required end of sync
-     *            actions.
-     */
-    private void handleEndOfSyncAction(PccId pccId) {
-
-        Map<TunnelId, Tunnel> preSyncLspDb = preSyncLspDbMap.get(pccId.ipAddress());
-        checkNotNull(preSyncLspDb);
-
-        for (Tunnel tunnel : preSyncLspDb.values()) {
+            if (endOfSyncAction == SEND_UPDATE) {
+                updateTunnel(tunnel, tunnel.path());
+                return;
+            }
 
             TunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(),
                                                                 tunnel.src(), tunnel.dst(),
@@ -1685,43 +1622,56 @@
                                                                 tunnel.path(),
                                                                 (SparseAnnotations) tunnel.annotations());
 
-            if ((tunnel.annotations().value(PCE_INIT) == null)
-                    || (tunnel.annotations().value(PCE_INIT).equals("false"))) {
 
-                tunnelRemoved(td);
-            } else {
+            if (endOfSyncAction == PcepLspSyncAction.UNSTABLE) {
+
                 // Send PCInit msg again after global reoptimization.
                 tunnelUpdated(td, UNSTABLE);
 
                 // To remove the old tunnel from store whose PLSPID is not
                 // recognized by ingress PCC.
                 tunnelRemoved(td);
+
+            } else if (endOfSyncAction == REMOVE) {
+                tunnelRemoved(td);
             }
         }
 
-        List<Tunnel> tunnelsToBeDeletedList = syncCompleteDeleteList.get(pccId.ipAddress());
-        checkNotNull(tunnelsToBeDeletedList);
-        for (Tunnel tunnel: tunnelsToBeDeletedList) {
-            releaseTunnel(tunnel);
-        }
+        @Override
+        public void handleEndOfSyncAction(PccId pccId, PcepMessage msg, PcepLspSyncAction endOfSyncAction) {
+            try {
+                if ((msg instanceof PcepInitiateMsg) && (endOfSyncAction == SEND_DELETE)) {
+                    PcepClient pc = pcepClientController.getClient(pccId);
+                    LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = ((PcepInitiateMsg) msg)
+                            .getPcInitiatedLspRequestList();
+                    PcInitiatedLspRequest pcInitMsg = llPcInitiatedLspRequestList.iterator().next();
 
-        List<Tunnel> tunnelsToBeUpdatedList = syncCompleteUpdateList.get(pccId.ipAddress());
-        checkNotNull(tunnelsToBeUpdatedList);
-        for (Tunnel tunnel: tunnelsToBeUpdatedList) {
-            updateTunnel(tunnel, tunnel.path());
-        }
+                    if (pcInitMsg != null) {
+                        PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(SrpIdGenerators.create())
+                                .setRFlag(true).build();
 
-        /* On end of sync, empty all temporary data structures. */
-        preSyncLspDbMap.remove(pccId.ipAddress());
-        syncCompleteDeleteList.remove(pccId.ipAddress());
-        syncCompleteUpdateList.remove(pccId.ipAddress());
+                        PcInitiatedLspRequest releaseLspRequest = pc.factory().buildPcInitiatedLspRequest()
+                                .setLspObject(pcInitMsg.getLspObject()).setSrpObject(srpobj).build();
 
-        // TODO: If SR capable, send a notification to
-        // PCE APP to start label DB sync.
-        if (true) {
-            pcepClientController.getClient(pccId).setLabelDbSyncStatus(IN_SYNC);
+                        llPcInitiatedLspRequestList.remove(pcInitMsg);
+                        llPcInitiatedLspRequestList.add(releaseLspRequest);
+
+                        PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg()
+                                .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList).build();
+
+                        pc.sendMessage(Collections.singletonList(pcInitiateMsg));
+                    }
+                }
+            } catch (PcepParseException e) {
+                log.error("Exception occured while sending initiate delete message {}", e.getMessage());
+            }
         }
     }
+    @Override
+    public Tunnel tunnelQueryById(TunnelId tunnelId) {
+        return service.tunnelQueryById(tunnelId);
+    }
+
 
     private DeviceId getDevice(PccId pccId) {
         // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
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 4f6178a..aafdfaa 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
@@ -18,6 +18,7 @@
 import static org.junit.Assert.assertNotNull;
 
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.RejectedExecutionException;
@@ -31,6 +32,7 @@
 import org.onosproject.pcepio.protocol.PcepFactories;
 import org.onosproject.pcepio.protocol.PcepFactory;
 import org.onosproject.pcepio.protocol.PcepMessage;
+import org.onosproject.pcepio.protocol.PcepStateReport;
 import org.onosproject.pcepio.protocol.PcepVersion;
 
 /**
@@ -49,6 +51,7 @@
     private PcepSyncStatus lspDbSyncStatus;
     private PcepSyncStatus labelDbSyncStatus;
     private Map<LspKey, Boolean> lspDelegationInfo = new HashMap<>();
+    private Map<PccId, List<PcepStateReport>> sycRptCache = new HashMap<>();
 
     /**
      * Initialize instance with specified parameters.
@@ -161,4 +164,27 @@
     public Boolean delegationInfo(LspKey lspKey) {
         return lspDelegationInfo.get(lspKey);
     }
+
+    @Override
+    public void initializeSyncMsgList(PccId pccId) {
+        List<PcepStateReport> rptMsgList = new LinkedList<>();
+        sycRptCache.put(pccId, rptMsgList);
+    }
+
+    @Override
+    public List<PcepStateReport> getSyncMsgList(PccId pccId) {
+        return sycRptCache.get(pccId);
+    }
+
+    @Override
+    public void removeSyncMsgList(PccId pccId) {
+        sycRptCache.remove(pccId);
+    }
+
+    @Override
+    public void addSyncMsgToList(PccId pccId, PcepStateReport rptMsg) {
+        List<PcepStateReport> rptMsgList = sycRptCache.get(pccId);
+        rptMsgList.add(rptMsg);
+        sycRptCache.put(pccId, rptMsgList);
+    }
 }
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 769268b..dd82aac 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
@@ -30,6 +30,7 @@
 import org.onosproject.pcep.controller.PcepClientListener;
 import org.onosproject.pcep.controller.PcepEventListener;
 import org.onosproject.pcep.controller.PcepNodeListener;
+import org.onosproject.pcep.controller.PcepPacketListener;
 import org.onosproject.pcep.controller.driver.PcepAgent;
 import org.onosproject.pcepio.protocol.PcepError;
 import org.onosproject.pcepio.protocol.PcepErrorInfo;
@@ -57,6 +58,7 @@
 
     protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
     public Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet();
+    protected Set<PcepPacketListener> pcepPacketListener = Sets.newHashSet();
 
     @Activate
     public void activate() {
@@ -116,6 +118,16 @@
     }
 
     @Override
+    public void addPacketListener(PcepPacketListener listener) {
+        pcepPacketListener.add(listener);
+    }
+
+    @Override
+    public void removePacketListener(PcepPacketListener listener) {
+        pcepPacketListener.remove(listener);
+    }
+
+    @Override
     public void writeMessage(PccId pccId, PcepMessage msg) {
         this.getClient(pccId).sendMessage(msg);
     }
@@ -273,5 +285,11 @@
                 l.deleteNode(pccId);
             }
         }
+
+        @Override
+        public boolean analyzeSyncMsgList(PccId pccId) {
+            // TODO Auto-generated method stub
+            return false;
+        }
     }
 }
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
index fe2c8b2..ce00b5e 100644
--- 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
@@ -27,7 +27,6 @@
 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.DELEGATE;
 import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
 import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED;
-import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC;
 import static org.onosproject.net.Device.Type.ROUTER;
 import static org.onosproject.net.MastershipRole.MASTER;
 
@@ -404,7 +403,7 @@
                                        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
+                                       0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x1B, // 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,
@@ -552,19 +551,18 @@
     }
 
     /**
-     * Tests LSPDB sync where PCC reports less LSPs than known by PCE and PCE deletes at the end of DB sync.
+     * Tests adding PCC Init LSP after LSP DB sync is over.
      */
     @Test
-    public void testCaseLspDbSync1() throws PcepParseException, PcepOutOfBoundMessageException {
-        /* Step 1 create 2 LSPs */
-        byte[] reportMsg1 = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
+    public void tunnelProviderAddedTest5() 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, 0x00,
+                                       0x00, 0x00, 0x00, 0x02,
                                        0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object
-                                       0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
+                                       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,
@@ -584,11 +582,11 @@
                                        0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
                                        };
 
-        ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer();
-        buffer1.writeBytes(reportMsg1);
+        ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+        buffer.writeBytes(reportMsg);
 
-        PcepMessageReader<PcepMessage> reader1 = PcepFactories.getGenericReader();
-        PcepMessage message1 = reader1.readFrom(buffer1);
+        PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
+        PcepMessage message = reader.readFrom(buffer);
 
         DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
         newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
@@ -601,263 +599,16 @@
         deviceService.addDevice(device);
 
         PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
+        controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
         controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
 
         PcepClientAdapter pc = new PcepClientAdapter();
         pc.init(pccId, PcepVersion.PCEP_1);
-        controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(2, (short) 2), true);
+        controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
         masterShipService.setMaster(true);
-        controller.processClientMessage(pccId, message1);
+        controller.processClientMessage(pccId, message);
 
-        /* create 2nd LSP */
-        byte[] reportMsg2 = 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, 0x00,
-                                       0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x20, 0x19, // LSP object
-                                       0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
-                                       0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
-                                       0x01, 0x01, 0x01, 0x01,
-                                       0x00, 0x02, 0x00, 0x02,
-                                       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 buffer2 = ChannelBuffers.dynamicBuffer();
-        buffer2.writeBytes(reportMsg2);
-
-        PcepMessageReader<PcepMessage> reader2 = PcepFactories.getGenericReader();
-        PcepMessage message2 = reader2.readFrom(buffer2);
-
-        controller.processClientMessage(pccId, message2);
-
-        /* Assert number of LSPs in DB to be 2. */
-        assertThat(registry.tunnelIdCounter, is((long) 2));
-
-        /* Step 2 send sync begin message and LSP 1. */
-        byte[] reportMsg3 = 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, 0x00,
-                                        0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x1B, // LSP object
-                                        0x00, 0x11, 0x00, 0x04, 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 buffer3 = ChannelBuffers.dynamicBuffer();
-         buffer3.writeBytes(reportMsg3);
-         PcepMessageReader<PcepMessage> reader3 = PcepFactories.getGenericReader();
-         PcepMessage message3 = reader3.readFrom(buffer3);
-         controller.processClientMessage(pccId, message3);
-
-         assertThat(controller.getClient(pccId).lspDbSyncStatus(), is(IN_SYNC));
-
-        /* Step 3 send end of sync marker */
-         byte[] reportMsg4 = new byte[] {0x20, 0x0a, 0x00, (byte) 0x24,
-                                         0x20, 0x10, 0x00, 0x1C, // LSP object
-                                         0x00, 0x00, 0x10, 0x19,
-                                         0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
-                                         0x00, 0x00, 0x00, 0x00,
-                                         0x00, 0x00, 0x00, 0x00,
-                                         0x00, 0x00, 0x00, 0x00,
-                                         0x00, 0x00, 0x00, 0x00,
-                                         0x07, 0x10, 0x00, 0x04, //ERO object
-                                         };
-
-          ChannelBuffer buffer4 = ChannelBuffers.dynamicBuffer();
-          buffer4.writeBytes(reportMsg4);
-          PcepMessageReader<PcepMessage> reader4 = PcepFactories.getGenericReader();
-          PcepMessage message4 = reader4.readFrom(buffer4);
-          controller.processClientMessage(pccId, message4);
-
-        assertThat(controller.getClient(pccId).lspDbSyncStatus(), is(SYNCED));
-    }
-
-    /**
-     * Tests PCC PCRpt PCE initiated LSP which PCE doesn't know and hence should send PCInit delete msg.
-     */
-    @Test
-    public void testCaseLspDbSync2() throws PcepParseException, PcepOutOfBoundMessageException {
-        /* Step 1 create 2 LSPs */
-        byte[] reportMsg1 = 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, 0x00,
-                                       0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object
-                                       0x00, 0x11, 0x00, 0x04, 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 buffer1 = ChannelBuffers.dynamicBuffer();
-        buffer1.writeBytes(reportMsg1);
-
-        PcepMessageReader<PcepMessage> reader1 = PcepFactories.getGenericReader();
-        PcepMessage message1 = reader1.readFrom(buffer1);
-
-        DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
-        newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
-        newBuilder.set(AnnotationKeys.TYPE, "L3");
-        Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
-                UNKOWN, UNKOWN, UNKOWN,
-                UNKOWN, new ChassisId(),
-                newBuilder.build());
-
-        deviceService.addDevice(device);
-
-        PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
-        controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
-
-        PcepClientAdapter pc = new PcepClientAdapter();
-        pc.init(pccId, PcepVersion.PCEP_1);
-        masterShipService.setMaster(true);
-        controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(2, (short) 2), true);
-
-        controller.processClientMessage(pccId, message1);
-
-        /* create 2nd LSP */
-        byte[] reportMsg2 = 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, 0x00,
-                                       0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x20, 0x19, // LSP object
-                                       0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
-                                       0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
-                                       0x01, 0x01, 0x01, 0x01,
-                                       0x00, 0x02, 0x00, 0x02,
-                                       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 buffer2 = ChannelBuffers.dynamicBuffer();
-        buffer2.writeBytes(reportMsg2);
-
-        PcepMessageReader<PcepMessage> reader2 = PcepFactories.getGenericReader();
-        PcepMessage message2 = reader2.readFrom(buffer2);
-
-        controller.processClientMessage(pccId, message2);
-
-        /* Assert number of LSPs in DB to be 2. */
-        assertThat(registry.tunnelIdCounter, is((long) 2));
-
-        /* Step 2 send sync begin message and LSP 1. */
-        byte[] reportMsg3 = 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, 0x00,
-                                        0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, (byte) 0x9B, // LSP object
-                                        0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
-                                        0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
-                                        0x01, 0x01, 0x01, 0x01,
-                                        0x00, 0x01, 0x00, 0x03,
-                                        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 buffer3 = ChannelBuffers.dynamicBuffer();
-        buffer3.writeBytes(reportMsg3);
-        PcepMessageReader<PcepMessage> reader3 = PcepFactories.getGenericReader();
-        PcepMessage message3 = reader3.readFrom(buffer3);
-        controller.processClientMessage(pccId, message3);
-
-        assertThat(controller.getClient(pccId).lspDbSyncStatus(), is(IN_SYNC));
-
-        /* Step 3 send end of sync marker */
-        byte[] reportMsg4 = new byte[] {0x20, 0x0a, 0x00, (byte) 0x24,
-                                       0x20, 0x10, 0x00, 0x1C, // LSP object
-                                       0x00, 0x00, 0x10, 0x19,
-                                       0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
-                                       0x00, 0x00, 0x00, 0x00,
-                                       0x00, 0x00, 0x00, 0x00,
-                                       0x00, 0x00, 0x00, 0x00,
-                                       0x00, 0x00, 0x00, 0x00,
-                                       0x07, 0x10, 0x00, 0x04, //ERO object
-                                       };
-
-        ChannelBuffer buffer4 = ChannelBuffers.dynamicBuffer();
-        buffer4.writeBytes(reportMsg4);
-        PcepMessageReader<PcepMessage> reader4 = PcepFactories.getGenericReader();
-        PcepMessage message4 = reader4.readFrom(buffer4);
-        controller.processClientMessage(pccId, message4);
-
-        assertThat(controller.getClient(pccId).lspDbSyncStatus(), is(SYNCED));
+        assertThat(registry.tunnelIdCounter, is((long) 0));
     }
 
     @After