BUG-139: PCE-triggered State Re-synchronization Procedure 34/27034/10
authorClaudio D. Gasparini <cgaspari@cisco.com>
Mon, 14 Sep 2015 14:10:55 +0000 (16:10 +0200)
committerClaudio D. Gasparini <cgaspari@cisco.com>
Fri, 9 Oct 2015 17:37:07 +0000 (19:37 +0200)
Trigger resync
 - RPC Trigger resyng
 - Send Upd Message with SYNC Flag for LSP set to 1
 - RPC Trigger resync Lsp
 - Send Upd Message with an LSP object containing a PLSP-ID
   of 0 and with the SYNC flag set to 1

Change-Id: I5642eb57426df739858359c0c1fe004ca339ef98
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
12 files changed:
integration-tests/src/test/java/org/opendaylight/protocol/integration/pcep/PcepRpcServicesRoutingTest.java
pcep/topology-api/src/main/yang/network-topology-pcep-programming.yang
pcep/topology-api/src/main/yang/network-topology-pcep.yang
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/ServerSessionManager.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/SyncOptimization.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyProgramming.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyRPCs.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologySessionRPCs.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTriggeredReSynchronizationProcedureTest.java [new file with mode: 0644]
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyProgrammingTest.java

index b6422af330e14e7dc2388fb1e00439125caa1c72..84d57e729dfae85614a0d913e197f28f53ce989e 100644 (file)
@@ -31,8 +31,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitAddLspInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitEnsureLspOperationalInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitRemoveLspInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerInitialSyncInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerInitialSyncInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerSyncInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerSyncInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitUpdateLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitUpdateLspInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInput;
@@ -42,8 +42,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.NetworkTopologyPcepService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerInitialSyncInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerInitialSyncInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepCreateP2pTunnelInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepCreateP2pTunnelInputBuilder;
@@ -117,7 +118,7 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
 
                 testAddLspRpce(consumerPcepService);
                 testEnsureLspRpce(consumerPcepService);
-                testTriggerInitialSyncRpce(consumerPcepService);
+                testTriggerSyncRpce(consumerPcepService);
             }
 
             private void testAddLspRpce(final NetworkTopologyPcepService consumerPcepService) {
@@ -135,20 +136,20 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
                 verify(pcepService2).addLsp(addLspInput);
             }
 
-            private void testTriggerInitialSyncRpce(final NetworkTopologyPcepService consumerPcepService) {
-                TriggerInitialSyncInput triggerInput = getInputForRpc(topology, TriggerInitialSyncInputBuilder.class,
-                    TriggerInitialSyncInput.class);
-                consumerPcepService.triggerInitialSync(triggerInput);
+            private void testTriggerSyncRpce(final NetworkTopologyPcepService consumerPcepService) {
+                TriggerSyncInput triggerInput = getInputForRpc(topology, TriggerSyncInputBuilder.class,
+                    TriggerSyncInput.class);
+                consumerPcepService.triggerSync(triggerInput);
 
-                verify(pcepService1).triggerInitialSync(triggerInput);
+                verify(pcepService1).triggerSync(triggerInput);
                 verifyZeroInteractions(pcepService2);
 
-                triggerInput = getInputForRpc(topology2, TriggerInitialSyncInputBuilder.class, TriggerInitialSyncInput.class);
+                triggerInput = getInputForRpc(topology2, TriggerSyncInputBuilder.class, TriggerSyncInput.class);
 
-                consumerPcepService.triggerInitialSync(triggerInput);
+                consumerPcepService.triggerSync(triggerInput);
 
                 verifyZeroInteractions(pcepService1);
-                verify(pcepService2).triggerInitialSync(triggerInput);
+                verify(pcepService2).triggerSync(triggerInput);
             }
 
             private void testEnsureLspRpce(final NetworkTopologyPcepService consumerPcepService) {
@@ -176,9 +177,11 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
 
         @SuppressWarnings("rawtypes")
         final ListenableFuture future = Futures.immediateFuture(RpcResultBuilder.<AddLspOutput>success().build());
+        final ListenableFuture futureSyncTrigger = Futures.immediateFuture(RpcResultBuilder.<TriggerSyncOutput>success().build());
+
         when(pcepService.addLsp(Mockito.<AddLspInput>any())).thenReturn(future);
         when(pcepService.removeLsp(Mockito.<RemoveLspInput>any())).thenReturn(future);
-        when(pcepService.triggerInitialSync(Mockito.<TriggerInitialSyncInput>any())).thenReturn(future);
+        when(pcepService.triggerSync(Mockito.<TriggerSyncInput>any())).thenReturn(futureSyncTrigger);
         when(pcepService.ensureLspOperational(Mockito.<EnsureLspOperationalInput>any())).thenReturn(future);
         when(pcepService.updateLsp(Mockito.<UpdateLspInput>any())).thenReturn(future);
 
@@ -251,7 +254,7 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
 
                 testSubmitAddLspRpc(consumerPcepService);
                 testSubmitUpdateLspRpc(consumerPcepService);
-                testTriggerInitialSyncRpc(consumerPcepService);
+                testTriggerSyncRpc(consumerPcepService);
             }
 
             private void testSubmitAddLspRpc(final NetworkTopologyPcepProgrammingService consumerPcepService) {
@@ -285,22 +288,22 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
                 verify(pcepService2).submitUpdateLsp(submitLspInput);
             }
 
-            private void testTriggerInitialSyncRpc(final NetworkTopologyPcepProgrammingService consumerPcepService) {
-                SubmitTriggerInitialSyncInput submitTriggerInput = getInputForRpc(topology,
-                    SubmitTriggerInitialSyncInputBuilder.class,
-                    SubmitTriggerInitialSyncInput.class);
-                consumerPcepService.submitTriggerInitialSync(submitTriggerInput);
+            private void testTriggerSyncRpc(final NetworkTopologyPcepProgrammingService consumerPcepService) {
+                SubmitTriggerSyncInput submitTriggerSyncInput = getInputForRpc(topology,
+                    SubmitTriggerSyncInputBuilder.class,
+                    SubmitTriggerSyncInput.class);
+                consumerPcepService.submitTriggerSync(submitTriggerSyncInput);
 
-                verify(pcepService1).submitTriggerInitialSync(submitTriggerInput);
+                verify(pcepService1).submitTriggerSync(submitTriggerSyncInput);
                 verifyZeroInteractions(pcepService2);
 
-                submitTriggerInput = getInputForRpc(topology2, SubmitTriggerInitialSyncInputBuilder.class,
-                    SubmitTriggerInitialSyncInput.class);
+                submitTriggerSyncInput = getInputForRpc(topology2, SubmitTriggerSyncInputBuilder.class,
+                    SubmitTriggerSyncInput.class);
 
-                consumerPcepService.submitTriggerInitialSync(submitTriggerInput);
+                consumerPcepService.submitTriggerSync(submitTriggerSyncInput);
 
                 verifyZeroInteractions(pcepService1);
-                verify(pcepService2).submitTriggerInitialSync(submitTriggerInput);
+                verify(pcepService2).submitTriggerSync(submitTriggerSyncInput);
             }
         };
         broker.registerConsumer(consumer, getBundleContext());
@@ -310,9 +313,10 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
     private void initMock(final NetworkTopologyPcepProgrammingService pcepService) {
         @SuppressWarnings("rawtypes")
         final ListenableFuture future = Futures.immediateFuture(RpcResultBuilder.<AddLspOutput>success().build());
+        final ListenableFuture futureTriggerSync = Futures.immediateFuture(RpcResultBuilder.<TriggerSyncOutput>success().build());
         when(pcepService.submitAddLsp(Mockito.<SubmitAddLspInput>any())).thenReturn(future);
         when(pcepService.submitRemoveLsp(Mockito.<SubmitRemoveLspInput>any())).thenReturn(future);
-        when(pcepService.submitTriggerInitialSync(Mockito.<SubmitTriggerInitialSyncInput>any())).thenReturn(future);
+        when(pcepService.submitTriggerSync(Mockito.<SubmitTriggerSyncInput>any())).thenReturn(futureTriggerSync);
         when(pcepService.submitEnsureLspOperational(Mockito.<SubmitEnsureLspOperationalInput>any())).thenReturn(future);
         when(pcepService.submitUpdateLsp(Mockito.<SubmitUpdateLspInput>any())).thenReturn(future);
     }
@@ -377,7 +381,7 @@ public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
 
             private void testCreateP2pTunnel(final TopologyTunnelPcepProgrammingService consumerPcepService) {
                 PcepCreateP2pTunnelInput addLspInput = getInputForRpc(topology, PcepCreateP2pTunnelInputBuilder.class,
-                        PcepCreateP2pTunnelInput.class);
+                    PcepCreateP2pTunnelInput.class);
                 consumerPcepService.pcepCreateP2pTunnel(addLspInput);
 
                 verify(pcepService1).pcepCreateP2pTunnel(addLspInput);
index b351c8390ac359e3378d561ddafbf2828f7d8e72..7257094be2ee05de6feacdc50a8b7a9591d448bc 100644 (file)
@@ -77,10 +77,10 @@ module network-topology-pcep-programming {
         }
     }
 
-    rpc submit-trigger-initial-sync {
+    rpc submit-trigger-sync {
         input {
             uses ntp:topology-instruction-input;
-            uses pcep:trigger-initial-sync-args;
+            uses pcep:trigger-sync-args;
         }
         output {
             uses ntp:topology-instruction-output;
index 2ac5bdc08907ec0ad12cd27cce80c29bcdf2da7d..db6a9a25c4fab7e410795aa80ec8e1bf7cceebf6 100644 (file)
@@ -54,6 +54,10 @@ module network-topology-pcep {
                 description
                      "Triggered initial state resynchronization is being performed.";
             }
+            enum pcep-triggered-resync {
+                description
+                    "Pcep triggered state resynchronization is being performed.";
+            }
             enum synchronized {
                 description
                     "State synchronization has been achieved.";
@@ -275,17 +279,18 @@ module network-topology-pcep {
         }
     }
 
-    grouping trigger-initial-sync-args {
-        leaf node {
-            type nt:node-ref;
-            mandatory true;
+    grouping trigger-sync-args {
+        uses lsp-id {
+          refine name {
+            mandatory false;
+          }
         }
     }
 
-    rpc trigger-initial-sync {
+    rpc trigger-sync {
         input {
             uses ont:network-topology-reference;
-            uses trigger-initial-sync-args;
+            uses trigger-sync-args;
         }
         output {
             uses operation-result;
index 1de5e1b2da853bf4377bd3e95032f5cbed65ee9b..797ca49c2459511c4e4aa4a316a2fd7a3d5130db 100644 (file)
@@ -111,7 +111,7 @@ public abstract class AbstractTopologySessionListener<S, L> implements PCEPSessi
     private final Map<String, ReportedLsp> lspData = new HashMap<>();
 
     @GuardedBy("this")
-    private final Map<L, String> lsps = new HashMap<>();
+    protected final Map<L, String> lsps = new HashMap<>();
 
     private final ServerSessionManager serverSessionManager;
     private InstanceIdentifier<PathComputationClient> pccIdentifier;
@@ -193,6 +193,27 @@ public abstract class AbstractTopologySessionListener<S, L> implements PCEPSessi
         });
     }
 
+    protected void updatePccState(final PccSyncState pccSyncState) {
+        final MessageContext ctx = new MessageContext(this.nodeState.beginTransaction());
+        updatePccNode(ctx, new PathComputationClientBuilder().setStateSync(pccSyncState).build());
+        if (pccSyncState != PccSyncState.Synchronized) {
+            this.synced = false;
+        }
+        // All set, commit the modifications
+        Futures.addCallback(ctx.trans.submit(), new FutureCallback<Void>() {
+            @Override
+            public void onSuccess(final Void result) {
+                LOG.trace("Internal state for session {} updated successfully", session);
+            }
+
+            @Override
+            public void onFailure(final Throwable t) {
+                LOG.error("Failed to update internal state for session {}", session, t);
+                session.close(TerminationReason.UNKNOWN);
+            }
+        });
+    }
+
     @GuardedBy("this")
     private void tearDown(final PCEPSession session) {
         this.serverSessionManager.releaseNodeState(this.nodeState, session, isLspDbPersisted());
@@ -518,6 +539,13 @@ public abstract class AbstractTopologySessionListener<S, L> implements PCEPSessi
         return false;
     }
 
+    protected final boolean isTriggeredReSyncEnabled() {
+        if (syncOptimization != null) {
+            return syncOptimization.isTriggeredReSyncEnabled();
+        }
+        return false;
+    }
+
     protected final boolean isSynchronized() {
         if (syncOptimization != null) {
             return syncOptimization.doesLspDbMatch();
index f59029c93b50ebfc156cf41fe300ff9765ce961b..516f1b1e80d2bda82534cf345d10d4d7016945b8 100644 (file)
@@ -35,7 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TopologyTypes1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TopologyTypes1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerInitialSyncArgs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.topology.pcep.type.TopologyPcepBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
@@ -149,9 +149,9 @@ final class ServerSessionManager implements PCEPSessionListenerFactory, AutoClos
     }
 
     @Override
-    public synchronized ListenableFuture<OperationResult> triggerInitialSync(final TriggerInitialSyncArgs input) {
+    public synchronized ListenableFuture<OperationResult> triggerSync(final TriggerSyncArgs input) {
         final TopologySessionListener l = checkSessionPresence(input.getNode());
-        return (l != null) ? l.triggerInitialSync(input) : OperationResults.UNSENT.future();
+        return (l != null) ? l.triggerSync(input) : OperationResults.UNSENT.future();
     }
 
     @Override
index 446f6b27f716bf36d5d4875c66d7e6a14f9b6b39..cd3f7c956c66b645bdc8d651035f3f75af298baa 100644 (file)
@@ -74,7 +74,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspArgs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerInitialSyncArgs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClientBuilder;
@@ -134,20 +134,40 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener<
     }
 
     /**
-     * when PCE-triggered Initial State Synchronization Procedure is set during the session establishment, PCC will
-     * wait arrival of PCUpd message with PLSP-ID = 0 and SYNC = 1 in order to trigger the LSP-DB synchronization
-     * process.
      * @param input
      * @return
      */
     @Override
-    public synchronized ListenableFuture<OperationResult> triggerInitialSync(final TriggerInitialSyncArgs input) {
-        if(isTriggeredInitialSynchro() && !isSynchronized()) {
+    public synchronized ListenableFuture<OperationResult> triggerSync(final TriggerSyncArgs input) {
+        if (isTriggeredInitialSynchro() && !isSynchronized()) {
+            LOG.trace("Trigger Initial Synchronization {}", input);
             final PcupdMessageBuilder pcupdMessageBuilder = new PcupdMessageBuilder(MESSAGE_HEADER);
             final SrpIdNumber srpIdNumber = createUpdateMessageSync(pcupdMessageBuilder);
             final Message msg = new PcupdBuilder().setPcupdMessage(pcupdMessageBuilder.build()).build();
             // Send the message
             return sendMessage(msg, srpIdNumber, null);
+        } else if (isSynchronized() && isTriggeredReSyncEnabled()) {
+            Preconditions.checkArgument(input != null && input.getNode() != null, MISSING_XML_TAG);
+            if (input.getName() == null) {
+                LOG.trace("Trigger Resynchronization {}", input);
+                markAllLspAsStale();
+                updatePccState(PccSyncState.PcepTriggeredResync);
+                final PcupdMessageBuilder pcupdMessageBuilder = new PcupdMessageBuilder(MESSAGE_HEADER);
+                final SrpIdNumber srpIdNumber = createUpdateMessageSync(pcupdMessageBuilder);
+                final Message msg = new PcupdBuilder().setPcupdMessage(pcupdMessageBuilder.build()).build();
+                // Send the message
+                return sendMessage(msg, srpIdNumber, null);
+            } else {
+                LOG.trace("Trigger Lsp Resynchronization {}", input);
+
+                // Make sure the LSP exists
+                final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
+                final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
+                if (f == null) {
+                    return OperationResults.createUnsent(PCEPErrors.LSP_INTERNAL_ERROR).future();
+                }
+                return Futures.transform(f, new ResyncLspFunction(input));
+            }
         }
         return OperationResults.UNSENT.future();
     }
@@ -158,7 +178,7 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener<
         final Lsp lsp = new LspBuilder().setPlspId(new PlspId(0L)).setSync(Boolean.TRUE).build();
         // SRP Mandatory in Upd
         final SrpBuilder srpBuilder = new SrpBuilder();
-        // not sue wheter use 0 instead of nextRequest() or dont  insert srp == SRP-ID-number = 0
+        // not sue whether use 0 instead of nextRequest() or do not insert srp == SRP-ID-number = 0
         srpBuilder.setOperationId(nextRequest());
         final Srp srp = srpBuilder.build();
         //ERO Mandatory in Upd
@@ -172,6 +192,66 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener<
         return srp.getOperationId();
     }
 
+    private void markAllLspAsStale() {
+        for (final PlspId plspId : lsps.keySet()) {
+            staleLsps.add(plspId);
+        }
+    }
+
+    private class ResyncLspFunction implements AsyncFunction<Optional<ReportedLsp>, OperationResult>  {
+
+        private final TriggerSyncArgs input;
+
+        public ResyncLspFunction(final TriggerSyncArgs input) {
+            this.input = input;
+        }
+
+        @Override
+        public ListenableFuture<OperationResult> apply(final Optional<ReportedLsp> rep) {
+            final Lsp reportedLsp = validateReportedLsp(rep, this.input);
+            if (reportedLsp == null || !rep.isPresent()) {
+                return OperationResults.createUnsent(PCEPErrors.UNKNOWN_PLSP_ID).future();
+            }
+            // mark lsp as stale
+            final ReportedLsp staleLsp = rep.get();
+            if (!staleLsp.getPath().isEmpty()) {
+                final Path1 path1 = staleLsp.getPath().get(0).getAugmentation(Path1.class);
+                if (path1 != null) {
+                    staleLsps.add(path1.getLsp().getPlspId());
+                }
+            }
+            updatePccState(PccSyncState.PcepTriggeredResync);
+            // create PCUpd with mandatory objects and LSP object set to 1
+            final SrpBuilder srpBuilder = new SrpBuilder();
+            srpBuilder.setOperationId(nextRequest());
+            srpBuilder.setProcessingRule(Boolean.TRUE);
+
+            final Optional<PathSetupType> maybePST = getPST(rep);
+            if (maybePST.isPresent()) {
+                srpBuilder.setTlvs(
+                    new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder()
+                        .setPathSetupType(maybePST.get()).build());
+            }
+
+            final Srp srp = srpBuilder.build();
+            final Lsp lsp = new LspBuilder().setPlspId(reportedLsp.getPlspId()).setSync(Boolean.TRUE).build();
+
+            final Message msg = createPcepUpd(srp,lsp);
+            return sendMessage(msg, srp.getOperationId(), null);
+        }
+
+        private Message createPcepUpd(final Srp srp, final Lsp lsp) {
+            final UpdatesBuilder rb = new UpdatesBuilder();
+            rb.setSrp(srp);
+            rb.setLsp(lsp);
+            final PathBuilder pb = new PathBuilder();
+            rb.setPath(pb.build());
+            final PcupdMessageBuilder ub = new PcupdMessageBuilder(MESSAGE_HEADER);
+            ub.setUpdates(Collections.singletonList(rb.build()));
+            return new PcupdBuilder().setPcupdMessage(ub.build()).build();
+        }
+    }
+
     private boolean handleErrorMessage(final PcerrMessage message) {
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessage errMsg = message.getPcerrMessage();
         if (errMsg.getErrorType() instanceof StatefulCase) {
@@ -229,6 +309,8 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener<
     private boolean manageNextReport(final Reports report, final MessageContext ctx) {
         final Lsp lsp = report.getLsp();
         final PlspId plspid = lsp.getPlspId();
+        final Srp srp = report.getSrp();
+
         if (!lsp.isSync() && (plspid == null || plspid.getValue() == 0)) {
             purgeStaleLsps(ctx);
             stateSynchronizationAchieved(ctx);
@@ -236,7 +318,6 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener<
         }
         final ReportedLspBuilder rlb = new ReportedLspBuilder();
         boolean solicited = false;
-        final Srp srp = report.getSrp();
         solicited = isSolicited(srp, lsp, ctx, rlb);
 
         // if remove flag is set in SRP object, remove the tunnel immediately
@@ -260,7 +341,7 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener<
                     new PathComputationClient1Builder().setLspDbVersion(lspDbVersion).build()).build());
         }
         updateLsp(ctx, plspid, name, rlb, solicited, lsp.isRemove());
-        unmarkStaleLsp(plspid, lsp.isSync());
+        unmarkStaleLsp(plspid);
 
         LOG.debug("LSP {} updated", lsp);
         return true;
@@ -565,7 +646,7 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener<
     }
 
     @Override
-    protected Lsp validateReportedLsp(final Optional<ReportedLsp> rep, final LspId input) {
+    protected Lsp validateReportedLsp(final Optional<ReportedLsp> rep,  final LspId input) {
         if (!rep.isPresent()) {
             LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
             return null;
@@ -643,12 +724,9 @@ class Stateful07TopologySessionListener extends AbstractTopologySessionListener<
      * exists in the LSP database, the PCE MUST update the LSP database and
      * clear the stale marker from the LSP
      * @param plspId
-     * @param sync
      */
-    private synchronized void unmarkStaleLsp(final PlspId plspId, final boolean sync) {
-        if (!sync) {
-            staleLsps.remove(plspId);
-        }
+    private synchronized void unmarkStaleLsp(final PlspId plspId) {
+        staleLsps.remove(plspId);
     }
 
     /**
index 9e0333c88a018dc1aa1f766df1f19ae9d43c756d..4fc02eea1a57cdbad38dcbb750e33c7e6944fe6a 100644 (file)
@@ -23,7 +23,7 @@ final class SyncOptimization {
     private final boolean isDeltaSyncEnabled;
     private final boolean isDbVersionPresent;
     private final boolean isTriggeredInitialSynEnable;
-    private final boolean isTriggeredReSynEnable;
+    private final boolean isTriggeredReSyncEnable;
 
     public SyncOptimization(final PCEPSession session) {
         Preconditions.checkNotNull(session);
@@ -36,7 +36,7 @@ final class SyncOptimization {
         this.isDeltaSyncEnabled = isDeltaSync(local) && isDeltaSync(remote);
         this.isDbVersionPresent = localLspDbVersion != null || remoteLspDbVersion != null;
         this.isTriggeredInitialSynEnable = isTriggeredInitialSync(local) && isTriggeredInitialSync(remote);
-        this.isTriggeredReSynEnable = isTriggeredReSync(local) && isTriggeredReSync(remote);
+        this.isTriggeredReSyncEnable = isTriggeredReSync(local) && isTriggeredReSync(remote);
     }
 
     public boolean doesLspDbMatch() {
@@ -50,13 +50,13 @@ final class SyncOptimization {
     public boolean isDeltaSyncEnabled() {
         return isDeltaSyncEnabled;
     }
-    /**
-     * Returns
-     * @return isTriggeredInitialSynEnable
-     */
+
     public boolean isTriggeredInitSyncEnabled() {
         return isTriggeredInitialSynEnable;
     }
+    public boolean isTriggeredReSyncEnabled() {
+        return isTriggeredReSyncEnable;
+    }
 
     public boolean isDbVersionPresent() {
         return isDbVersionPresent;
index c6c6239e96c17ac811379876210c2a673f970b62..19d9556c458ce380220050e5b301f784f18792e1 100644 (file)
@@ -23,9 +23,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitRemoveLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitRemoveLspOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitRemoveLspOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerInitialSyncInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerInitialSyncOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerInitialSyncOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerSyncInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerSyncOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerSyncOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitUpdateLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitUpdateLspOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitUpdateLspOutputBuilder;
@@ -122,18 +122,18 @@ final class TopologyProgramming implements NetworkTopologyPcepProgrammingService
 
 
     @Override
-    public ListenableFuture<RpcResult<SubmitTriggerInitialSyncOutput>> submitTriggerInitialSync(final SubmitTriggerInitialSyncInput input) {
+    public ListenableFuture<RpcResult<SubmitTriggerSyncOutput>> submitTriggerSync(final SubmitTriggerSyncInput input) {
         Preconditions.checkArgument(input.getNode() != null);
 
-        final SubmitTriggerInitialSyncOutputBuilder b = new SubmitTriggerInitialSyncOutputBuilder();
+        final SubmitTriggerSyncOutputBuilder b = new SubmitTriggerSyncOutputBuilder();
         b.setResult(AbstractInstructionExecutor.schedule(scheduler, new AbstractInstructionExecutor(input) {
             @Override
             protected ListenableFuture<OperationResult> invokeOperation() {
-                return TopologyProgramming.this.manager.triggerInitialSync(input);
+                return TopologyProgramming.this.manager.triggerSync(input);
             }
         }));
 
-        final RpcResult<SubmitTriggerInitialSyncOutput> res = SuccessfulRpcResult.create(b.build());
+        final RpcResult<SubmitTriggerSyncOutput> res = SuccessfulRpcResult.create(b.build());
         return Futures.immediateFuture(res);
     }
 }
index 38429fc73464a6b9416c0df8e74c0577e769c891..1bbbe365e891881b7f6b7cf3194dfc7475d439ab 100644 (file)
@@ -23,9 +23,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerInitialSyncInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerInitialSyncOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerInitialSyncOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutputBuilder;
@@ -59,11 +59,11 @@ final class TopologyRPCs implements NetworkTopologyPcepService {
     }
 
     @Override
-    public Future<RpcResult<TriggerInitialSyncOutput>> triggerInitialSync(final TriggerInitialSyncInput input) {
-        return Futures.transform(manager.triggerInitialSync(input), new Function<OperationResult, RpcResult<TriggerInitialSyncOutput>>() {
+    public Future<RpcResult<TriggerSyncOutput>> triggerSync(final TriggerSyncInput input) {
+        return Futures.transform(manager.triggerSync(input), new Function<OperationResult, RpcResult<TriggerSyncOutput>>() {
             @Override
-            public RpcResult<TriggerInitialSyncOutput> apply(final OperationResult input) {
-                return SuccessfulRpcResult.create(new TriggerInitialSyncOutputBuilder(input).build());
+            public RpcResult<TriggerSyncOutput> apply(final OperationResult input) {
+                return SuccessfulRpcResult.create(new TriggerSyncOutputBuilder(input).build());
             }
         });
     }
index 4ad8eb03ca0f30a76423c1a49a4a9f1ed9429ad0..f206634cafd390f17668036e69aad2bfdeba1ce0 100644 (file)
@@ -13,7 +13,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspArgs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerInitialSyncArgs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspArgs;
 
 interface TopologySessionRPCs {
@@ -25,5 +25,5 @@ interface TopologySessionRPCs {
 
     ListenableFuture<OperationResult> ensureLspOperational(EnsureLspOperationalInput input);
 
-    ListenableFuture<OperationResult> triggerInitialSync(TriggerInitialSyncArgs input);
+    ListenableFuture<OperationResult> triggerSync(TriggerSyncArgs input);
 }
\ No newline at end of file
diff --git a/pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTriggeredReSynchronizationProcedureTest.java b/pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTriggeredReSynchronizationProcedureTest.java
new file mode 100644 (file)
index 0000000..a048d75
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.pcep.topology.provider;
+
+import static org.opendaylight.protocol.pcep.pcc.mock.MsgBuilderUtil.createLsp;
+import static org.opendaylight.protocol.pcep.pcc.mock.MsgBuilderUtil.createPath;
+
+import com.google.common.base.Optional;
+import java.math.BigInteger;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.pcep.PCEPSession;
+import org.opendaylight.protocol.pcep.pcc.mock.MsgBuilderUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs3Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.lsp.db.version.tlv.LspDbVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.lsp.db.version.tlv.LspDbVersionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.OperationalStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Pcrpt;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PlspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
+
+public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
+    private Stateful07TopologySessionListener listener;
+
+    private PCEPSession session;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        this.listener = (Stateful07TopologySessionListener) getSessionListener();
+    }
+
+    @Test
+    public void testTriggeredResynchronization() throws InterruptedException, ExecutionException {
+        //session up - sync skipped (LSP-DBs match)
+        final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1l)).build();
+        this.session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
+        this.listener.onSessionUp(session);
+
+        //report LSP + LSP-DB version number
+        final Pcrpt pcRpt = getPcrt();
+        this.listener.onMessage(session, pcRpt);
+
+        final PathComputationClient pcc = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
+        Assert.assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+        Assert.assertFalse(pcc.getReportedLsp().isEmpty());
+
+        //PCEP Trigger Full Resync
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(NODE_ID).build());
+
+        final PathComputationClient pcc1 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
+        Assert.assertEquals(PccSyncState.PcepTriggeredResync, pcc1.getStateSync());
+
+        //end of sync
+        final Pcrpt syncMsg = getSyncMsg();
+        this.listener.onMessage(session, syncMsg);
+        final PathComputationClient pcc2 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
+        //check node - synchronized
+        Assert.assertEquals(PccSyncState.Synchronized, pcc2.getStateSync());
+
+        this.listener.onMessage(session, pcRpt);
+        final PathComputationClient pcc3 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
+        Assert.assertEquals(1, pcc3.getReportedLsp().size());
+
+        //Trigger Full Resync
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(NODE_ID).build());
+        this.listener.onMessage(session, pcRpt);
+        //end of sync
+        this.listener.onMessage(session, syncMsg);
+        final PathComputationClient pcc4 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
+        //check node - synchronized
+        Assert.assertEquals(PccSyncState.Synchronized, pcc4.getStateSync());
+        //check reported LSP is not empty, Stale LSP state were purged
+        Assert.assertEquals(1, pcc4.getReportedLsp().size());
+    }
+
+    @Test
+    public void testTriggeredResynchronizationLsp() throws InterruptedException, ExecutionException {
+        //session up - sync skipped (LSP-DBs match)
+        final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1l)).build();
+        this.session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
+        this.listener.onSessionUp(session);
+
+        //report LSP + LSP-DB version number
+        final Pcrpt pcRpt = getPcrt();
+        this.listener.onMessage(session, pcRpt);
+
+        final PathComputationClient pcc = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
+        Assert.assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+        final List<ReportedLsp> reportedLspPcc = pcc.getReportedLsp();
+        Assert.assertFalse(reportedLspPcc.isEmpty());
+
+        //Trigger Full Resync
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(NODE_ID).setName("test").build());
+
+        final PathComputationClient pcc1 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
+        Assert.assertEquals(PccSyncState.PcepTriggeredResync, pcc1.getStateSync());
+        Assert.assertFalse(pcc1.getReportedLsp().isEmpty());
+
+        this.listener.onMessage(session, pcRpt);
+
+        Assert.assertFalse(reportedLspPcc.isEmpty());
+
+        //sync rpt + LSP-DB
+        final Pcrpt syncMsg = getSyncMsg();
+        this.listener.onMessage(session, syncMsg);
+        final PathComputationClient pcc2 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
+        //check node - synchronized
+        Assert.assertEquals(PccSyncState.Synchronized, pcc2.getStateSync());
+        //check reported LSP
+        Assert.assertEquals(1, pcc2.getReportedLsp().size());
+
+        //Trigger Full Resync
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(NODE_ID).setName("test").build());
+        this.listener.onMessage(session, syncMsg);
+
+        final PathComputationClient pcc3 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
+        //check node - synchronized
+        Assert.assertEquals(PccSyncState.Synchronized, pcc3.getStateSync());
+        //check reported LSP
+        Assert.assertEquals(0, pcc3.getReportedLsp().size());
+
+    }
+
+    private Open getOpen(final LspDbVersion dbVersion) {
+        return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder()
+            .addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build())
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder()
+                    .setIncludeDbVersion(Boolean.TRUE).setTriggeredResync(Boolean.TRUE).build())
+            .build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(dbVersion).build()).build()).build();
+    }
+
+    private Pcrpt getSyncMsg() {
+        return MsgBuilderUtil.createPcRtpMessage(createLsp(0, false, Optional.of(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().addAugmentation(
+                    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
+                    new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder()
+                        .setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(3l)).build()).build()).build()), true, false), Optional.<Srp>absent(),
+            createPath(Collections.<Subobject>emptyList()));
+    }
+
+    private Pcrpt getPcrt() {
+        return MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setPlspId(new PlspId(1l)).setTlvs(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.
+                    TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(1l)).build()).setSymbolicPathName(
+                    new SymbolicPathNameBuilder().setPathName(new SymbolicPathName("test".getBytes())).build())
+                    .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
+                        new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder()
+                            .setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1l)).build()).build()).build())
+                .setPlspId(new PlspId(1L)).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.<Srp>absent(),
+            createPath(Collections.<Subobject>emptyList()));
+    }
+}
index 2e94da5a897b71ab288a5d9397171aefa3df68a4..c3d5168b4cc1625405df2a6ff68cbed0be777a89 100644 (file)
@@ -33,7 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programm
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitAddLspInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitEnsureLspOperationalInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitRemoveLspInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerInitialSyncInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitTriggerSyncInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitUpdateLspInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInput;
@@ -43,9 +43,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerInitialSyncArgs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerInitialSyncInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerInitialSyncOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncArgs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspArgs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutput;
@@ -67,7 +67,7 @@ public class TopologyProgrammingTest extends AbstractPCEPSessionTest<MockedTopol
     private AddLspArgs addLspArgs;
     private UpdateLspArgs updateLspArgs;
     private RemoveLspArgs removeLspArgs;
-    private TriggerInitialSyncArgs triggerInitialSyncArgs;
+    private TriggerSyncArgs triggerSyncArgs;
     private EnsureLspOperationalInput ensureLspInput;
 
     @Mock
@@ -77,7 +77,7 @@ public class TopologyProgrammingTest extends AbstractPCEPSessionTest<MockedTopol
     @Mock
     private ListenableFuture<RpcResult<RemoveLspOutput>> futureRemoveLspOutput;
     @Mock
-    private ListenableFuture<RpcResult<TriggerInitialSyncOutput>> futureTriggerInitialSyncOutput;
+    private ListenableFuture<RpcResult<TriggerSyncOutput>> futureTriggerSyncOutput;
     @Mock
     private ListenableFuture<RpcResult<EnsureLspOperationalOutput>> futureEnsureLspOutput;
 
@@ -130,7 +130,7 @@ public class TopologyProgrammingTest extends AbstractPCEPSessionTest<MockedTopol
                 callback.run();
                 return null;
             }
-        }).when(this.futureTriggerInitialSyncOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
+        }).when(this.futureTriggerSyncOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
         Mockito.doAnswer(new Answer<Void>() {
             @Override
             public Void answer(final InvocationOnMock invocation) throws Throwable {
@@ -160,13 +160,13 @@ public class TopologyProgrammingTest extends AbstractPCEPSessionTest<MockedTopol
                 return TopologyProgrammingTest.this.futureRemoveLspOutput;
             }
         }).when(listener).removeLsp(Mockito.any(RemoveLspInput.class));
-        Mockito.doAnswer(new Answer<Future<RpcResult<TriggerInitialSyncOutput>>>() {
+        Mockito.doAnswer(new Answer<Future<RpcResult<TriggerSyncOutput>>>() {
             @Override
-            public Future<RpcResult<TriggerInitialSyncOutput>> answer(final InvocationOnMock invocation) throws Throwable {
-                TopologyProgrammingTest.this.triggerInitialSyncArgs = (TriggerInitialSyncArgs) invocation.getArguments()[0];
-                return TopologyProgrammingTest.this.futureTriggerInitialSyncOutput;
+            public Future<RpcResult<TriggerSyncOutput>> answer(final InvocationOnMock invocation) throws Throwable {
+                TopologyProgrammingTest.this.triggerSyncArgs = (TriggerSyncArgs) invocation.getArguments()[0];
+                return TopologyProgrammingTest.this.futureTriggerSyncOutput;
             }
-        }).when(listener).triggerInitialSync(Mockito.any(TriggerInitialSyncInput.class));
+        }).when(listener).triggerSync(Mockito.any(TriggerSyncInput.class));
         Mockito.doAnswer(new Answer<Future<RpcResult<EnsureLspOperationalOutput>>>() {
             @Override
             public Future<RpcResult<EnsureLspOperationalOutput>> answer(final InvocationOnMock invocation) throws Throwable {
@@ -230,12 +230,14 @@ public class TopologyProgrammingTest extends AbstractPCEPSessionTest<MockedTopol
     }
 
     @Test
-    public void testSubmitTriggerInitialSync() {
-        final SubmitTriggerInitialSyncInputBuilder inputBuilder = new SubmitTriggerInitialSyncInputBuilder();
+    public void testSubmitTriggerSync() {
+        final SubmitTriggerSyncInputBuilder inputBuilder = new SubmitTriggerSyncInputBuilder();
+        inputBuilder.setName(NAME);
         inputBuilder.setNode(NODE_ID);
-        this.topologyProgramming.submitTriggerInitialSync(inputBuilder.build());
-        Assert.assertNotNull(this.triggerInitialSyncArgs);
-        Assert.assertEquals(NODE_ID, this.triggerInitialSyncArgs.getNode());
+        this.topologyProgramming.submitTriggerSync(inputBuilder.build());
+        Assert.assertNotNull(this.triggerSyncArgs);
+        Assert.assertEquals(NAME, this.triggerSyncArgs.getName());
+        Assert.assertEquals(NODE_ID, this.triggerSyncArgs.getNode());
     }
 
     protected static final class MockedTopologySessionListenerFactory implements TopologySessionListenerFactory {