Search in sources :

Example 6 with SyncupEntry

use of org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry in project openflowplugin by opendaylight.

the class SyncReactorFutureZipDecoratorTest method testSyncupWithOptimizedConfigDeltaCompression.

@Test
public void testSyncupWithOptimizedConfigDeltaCompression() throws Exception {
    final FlowCapableNode dataBefore = Mockito.mock(FlowCapableNode.class);
    final FlowCapableNode dataAfter = Mockito.mock(FlowCapableNode.class);
    final FlowCapableNode dataAfter2 = Mockito.mock(FlowCapableNode.class);
    final CountDownLatch latchForFirst = new CountDownLatch(1);
    final CountDownLatch latchForNext = new CountDownLatch(1);
    final SyncupEntry first = new SyncupEntry(dataBefore, configDS, null, operationalDS);
    final SyncupEntry second = new SyncupEntry(dataAfter, configDS, dataBefore, configDS);
    final SyncupEntry third = new SyncupEntry(null, configDS, dataAfter, configDS);
    final SyncupEntry fourth = new SyncupEntry(dataAfter2, configDS, null, configDS);
    final SyncupEntry zipped = new SyncupEntry(dataAfter2, configDS, dataBefore, configDS);
    final List<ListenableFuture<Boolean>> allResults = new ArrayList<>();
    Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(), Mockito.eq(first))).thenAnswer(invocationOnMock -> {
        LOG.info("unlocking next configs");
        latchForNext.countDown();
        latchForFirst.await();
        LOG.info("unlocking first delegate");
        return Futures.immediateFuture(Boolean.TRUE);
    });
    allResults.add(reactor.syncup(fcNodePath, first));
    latchForNext.await();
    mockSyncupWithEntry(second);
    allResults.add(reactor.syncup(fcNodePath, second));
    mockSyncupWithEntry(third);
    allResults.add(reactor.syncup(fcNodePath, third));
    mockSyncupWithEntry(fourth);
    allResults.add(reactor.syncup(fcNodePath, fourth));
    latchForFirst.countDown();
    Futures.allAsList(allResults).get(1, TimeUnit.SECONDS);
    LOG.info("all configs done");
    syncThreadPool.shutdown();
    boolean terminated = syncThreadPool.awaitTermination(1, TimeUnit.SECONDS);
    if (!terminated) {
        LOG.info("thread pool not terminated.");
        syncThreadPool.shutdownNow();
    }
    final InOrder inOrder = Mockito.inOrder(delegate);
    inOrder.verify(delegate).syncup(fcNodePath, first);
    inOrder.verify(delegate).syncup(fcNodePath, zipped);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CountDownLatch(java.util.concurrent.CountDownLatch) SyncupEntry(org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry) Test(org.junit.Test)

Example 7 with SyncupEntry

use of org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry in project openflowplugin by opendaylight.

the class SyncReactorFutureZipDecoratorTest method testSyncupConfigEmptyQueue.

@Test
public void testSyncupConfigEmptyQueue() throws Exception {
    final FlowCapableNode dataBefore = Mockito.mock(FlowCapableNode.class);
    final FlowCapableNode dataAfter = Mockito.mock(FlowCapableNode.class);
    final CountDownLatch latchForNext = new CountDownLatch(1);
    final SyncupEntry first = new SyncupEntry(dataBefore, configDS, null, configDS);
    final SyncupEntry second = new SyncupEntry(dataAfter, configDS, dataBefore, configDS);
    Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(), Mockito.eq(first))).thenAnswer(invocationOnMock -> {
        LOG.info("unlocking next config");
        latchForNext.countDown();
        return Futures.immediateFuture(Boolean.TRUE);
    });
    reactor.syncup(fcNodePath, first);
    latchForNext.await();
    mockSyncupWithEntry(second);
    reactor.syncup(fcNodePath, second);
    boolean terminated = syncThreadPool.awaitTermination(1, TimeUnit.SECONDS);
    if (!terminated) {
        LOG.info("thread pool not terminated.");
        syncThreadPool.shutdownNow();
    }
    final InOrder inOrder = Mockito.inOrder(delegate);
    inOrder.verify(delegate).syncup(fcNodePath, first);
    inOrder.verify(delegate).syncup(fcNodePath, second);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) CountDownLatch(java.util.concurrent.CountDownLatch) SyncupEntry(org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry) Test(org.junit.Test)

Example 8 with SyncupEntry

use of org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry in project openflowplugin by opendaylight.

the class SimplifiedConfigListener method onNodeAdded.

/**
 * If node was added to config DS and it is already present in operational DS (connected) diff between current
 * new configuration and actual configuration (seen in operational) should be calculated and sent to device.
 */
private ListenableFuture<Boolean> onNodeAdded(final InstanceIdentifier<FlowCapableNode> nodePath, final FlowCapableNode dataAfter, final FlowCapableNode operationalNode) {
    LOG.debug("Reconciliation {}: {}", dsType(), PathUtil.digNodeId(nodePath).getValue());
    final SyncupEntry syncupEntry = new SyncupEntry(dataAfter, dsType(), operationalNode, LogicalDatastoreType.OPERATIONAL);
    return reactor.syncup(nodePath, syncupEntry);
}
Also used : SyncupEntry(org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry)

Example 9 with SyncupEntry

use of org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry in project openflowplugin by opendaylight.

the class SimplifiedOperationalListener method reconciliation.

/**
 * If node is present in config DS diff between wanted configuration (in config DS) and actual device
 * configuration (coming from operational) should be calculated and sent to device.
 * @param modification from DS
 * @return optional syncup future
 */
private Optional<ListenableFuture<Boolean>> reconciliation(final DataTreeModification<Node> modification) {
    final NodeId nodeId = ModificationUtil.nodeId(modification);
    final Optional<FlowCapableNode> nodeConfiguration = configDao.loadByNodeId(nodeId);
    if (nodeConfiguration.isPresent()) {
        LOG.debug("Reconciliation {}: {}", dsType(), nodeId.getValue());
        final InstanceIdentifier<FlowCapableNode> nodePath = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(ModificationUtil.nodeId(modification))).augmentation(FlowCapableNode.class);
        final FlowCapableNode fcOperationalNode = ModificationUtil.flowCapableNodeAfter(modification);
        final SyncupEntry syncupEntry = new SyncupEntry(nodeConfiguration.get(), LogicalDatastoreType.CONFIGURATION, fcOperationalNode, dsType());
        return Optional.of(reactor.syncup(nodePath, syncupEntry));
    } else {
        LOG.debug("Config not present for reconciliation: {}", nodeId.getValue());
        reconciliationRegistry.unregisterIfRegistered(nodeId);
        return skipModification(modification);
    }
}
Also used : FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) SyncupEntry(org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)

Example 10 with SyncupEntry

use of org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry in project openflowplugin by opendaylight.

the class SyncReactorFutureZipDecorator method updateOptimizedConfigDelta.

private void updateOptimizedConfigDelta(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath, final SyncupEntry actual, final SyncupEntry previous) {
    final SyncupEntry updatedEntry = new SyncupEntry(actual.getAfter(), actual.getDsTypeAfter(), previous.getBefore(), previous.getDsTypeBefore());
    compressionQueue.put(flowcapableNodePath, updatedEntry);
}
Also used : SyncupEntry(org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry)

Aggregations

SyncupEntry (org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry)14 Test (org.junit.Test)9 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)7 CountDownLatch (java.util.concurrent.CountDownLatch)3 InOrder (org.mockito.InOrder)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ArrayList (java.util.ArrayList)1 SynchronizationDiffInput (org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SynchronizationDiffInput)1 FlowCapableNodeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder)1 TableBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder)1 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)1 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)1 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1