Search in sources :

Example 1 with ItemSyncBox

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

the class SyncPlanPushStrategyIncrementalImplTest method testRemoveRedundantMeters.

@Test
public void testRemoveRedundantMeters() throws Exception {
    Mockito.when(meterCommitter.remove(Matchers.<InstanceIdentifier<Meter>>any(), meterCaptor.capture(), Matchers.same(NODE_IDENT))).thenReturn(RpcResultBuilder.success(new RemoveMeterOutputBuilder().build()).buildFuture());
    final ItemSyncBox<Meter> meterSyncBox = new ItemSyncBox<>();
    meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(2L));
    meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(4L));
    meterSyncBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(DSInputFactory.createMeter(1L), DSInputFactory.createMeterWithBody(1L)));
    final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.removeRedundantMeters(NODE_ID, NODE_IDENT, meterSyncBox, counters);
    Assert.assertTrue(result.isDone());
    Assert.assertTrue(result.get().isSuccessful());
    final List<Meter> metercaptorAllValues = meterCaptor.getAllValues();
    Assert.assertEquals(2, metercaptorAllValues.size());
    Assert.assertEquals(2L, metercaptorAllValues.get(0).getMeterId().getValue().longValue());
    Assert.assertEquals(4L, metercaptorAllValues.get(1).getMeterId().getValue().longValue());
    final InOrder inOrderMeter = Mockito.inOrder(flowCapableTxService, meterCommitter);
    inOrderMeter.verify(meterCommitter, Mockito.times(2)).remove(Matchers.<InstanceIdentifier<Meter>>any(), Matchers.<Meter>any(), Matchers.eq(NODE_IDENT));
    // TODO: uncomment when enabled in impl
    // inOrderMeter.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
    inOrderMeter.verifyNoMoreInteractions();
}
Also used : RemoveMeterOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutputBuilder) InOrder(org.mockito.InOrder) ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Test(org.junit.Test)

Example 2 with ItemSyncBox

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

the class SyncPlanPushStrategyIncrementalImplTest method testAddMissingFlows_withUpdate.

@Test
public void testAddMissingFlows_withUpdate() throws Exception {
    Mockito.when(flowCommitter.add(Matchers.<InstanceIdentifier<Flow>>any(), flowCaptor.capture(), Matchers.same(NODE_IDENT))).thenReturn(RpcResultBuilder.success(new AddFlowOutputBuilder().build()).buildFuture());
    Mockito.when(flowCommitter.update(Matchers.<InstanceIdentifier<Flow>>any(), flowUpdateCaptor.capture(), flowUpdateCaptor.capture(), Matchers.same(NODE_IDENT))).thenReturn(RpcResultBuilder.success(new UpdateFlowOutputBuilder().build()).buildFuture());
    final ItemSyncBox<Flow> flowBox = new ItemSyncBox<>();
    flowBox.getItemsToPush().add(DSInputFactory.createFlow("f3", 3));
    flowBox.getItemsToPush().add(DSInputFactory.createFlow("f4", 4));
    flowBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(DSInputFactory.createFlow("f1", 1), DSInputFactory.createFlowWithInstruction("f1", 1)));
    final Map<TableKey, ItemSyncBox<Flow>> flowBoxMap = new LinkedHashMap<>();
    flowBoxMap.put(new TableKey((short) 0), flowBox);
    // TODO: replace null
    final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingFlows(NODE_ID, NODE_IDENT, flowBoxMap, counters);
    Assert.assertTrue(result.isDone());
    Assert.assertTrue(result.get().isSuccessful());
    final List<Flow> flowCaptorAllValues = flowCaptor.getAllValues();
    Assert.assertEquals(2, flowCaptorAllValues.size());
    Assert.assertEquals("f3", flowCaptorAllValues.get(0).getId().getValue());
    Assert.assertEquals("f4", flowCaptorAllValues.get(1).getId().getValue());
    final List<Flow> flowUpdateCaptorAllValues = flowUpdateCaptor.getAllValues();
    Assert.assertEquals(2, flowUpdateCaptorAllValues.size());
    Assert.assertEquals("f1", flowUpdateCaptorAllValues.get(0).getId().getValue());
    Assert.assertEquals("f1", flowUpdateCaptorAllValues.get(1).getId().getValue());
    final InOrder inOrderFlow = Mockito.inOrder(flowCapableTxService, flowCommitter);
    // add f3, f4
    inOrderFlow.verify(flowCommitter, Mockito.times(2)).add(Matchers.<InstanceIdentifier<Flow>>any(), Matchers.<Flow>any(), Matchers.eq(NODE_IDENT));
    // update f1
    inOrderFlow.verify(flowCommitter).update(Matchers.<InstanceIdentifier<Flow>>any(), Matchers.<Flow>any(), Matchers.<Flow>any(), Matchers.eq(NODE_IDENT));
    // TODO: uncomment when enabled in impl
    // inOrderFlow.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
    inOrderFlow.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) AddFlowOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) LinkedHashMap(java.util.LinkedHashMap) UpdateFlowOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder) Test(org.junit.Test)

Example 3 with ItemSyncBox

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

the class SyncPlanPushStrategyIncrementalImplTest method testAddMissingGroups.

@Test
public void testAddMissingGroups() throws Exception {
    Mockito.when(groupCommitter.add(Matchers.<InstanceIdentifier<Group>>any(), groupCaptor.capture(), Matchers.same(NODE_IDENT))).thenReturn(RpcResultBuilder.success(new AddGroupOutputBuilder().build()).buildFuture());
    ItemSyncBox<Group> groupBox1 = new ItemSyncBox<>();
    groupBox1.getItemsToPush().add(DSInputFactory.createGroup(2L));
    ItemSyncBox<Group> groupBox2 = new ItemSyncBox<>();
    groupBox2.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(3L, 2L));
    groupBox2.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(4L, 2L));
    ItemSyncBox<Group> groupBox3 = new ItemSyncBox<>();
    groupBox3.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(5L, 3L, 4L));
    final List<ItemSyncBox<Group>> groupBoxLot = Lists.newArrayList(groupBox1, groupBox2, groupBox3);
    final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingGroups(NODE_ID, NODE_IDENT, groupBoxLot, counters);
    Assert.assertTrue(result.isDone());
    Assert.assertTrue(result.get().isSuccessful());
    final List<Group> groupCaptorAllValues = groupCaptor.getAllValues();
    Assert.assertEquals(4, groupCaptorAllValues.size());
    Assert.assertEquals(2L, groupCaptorAllValues.get(0).getGroupId().getValue().longValue());
    Assert.assertEquals(3L, groupCaptorAllValues.get(1).getGroupId().getValue().longValue());
    Assert.assertEquals(4L, groupCaptorAllValues.get(2).getGroupId().getValue().longValue());
    Assert.assertEquals(5L, groupCaptorAllValues.get(3).getGroupId().getValue().longValue());
    final InOrder inOrderGroups = Mockito.inOrder(flowCapableTxService, groupCommitter);
    // add 2
    inOrderGroups.verify(groupCommitter).add(Matchers.<InstanceIdentifier<Group>>any(), Matchers.<Group>any(), Matchers.eq(NODE_IDENT));
    inOrderGroups.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
    // add 3, 4
    inOrderGroups.verify(groupCommitter, Mockito.times(2)).add(Matchers.<InstanceIdentifier<Group>>any(), Matchers.<Group>any(), Matchers.eq(NODE_IDENT));
    inOrderGroups.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
    // add 5
    inOrderGroups.verify(groupCommitter).add(Matchers.<InstanceIdentifier<Group>>any(), Matchers.<Group>any(), Matchers.eq(NODE_IDENT));
    inOrderGroups.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
    inOrderGroups.verifyNoMoreInteractions();
}
Also used : Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) InOrder(org.mockito.InOrder) ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddGroupOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder) Test(org.junit.Test)

Example 4 with ItemSyncBox

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

the class SyncPlanPushStrategyIncrementalImplTest method testAddMissingFlows.

@Test
public void testAddMissingFlows() throws Exception {
    Mockito.when(flowCommitter.add(Matchers.<InstanceIdentifier<Flow>>any(), flowCaptor.capture(), Matchers.same(NODE_IDENT))).thenReturn(RpcResultBuilder.success(new AddFlowOutputBuilder().build()).buildFuture());
    final ItemSyncBox<Flow> flowBox = new ItemSyncBox<>();
    flowBox.getItemsToPush().add(DSInputFactory.createFlow("f3", 3));
    flowBox.getItemsToPush().add(DSInputFactory.createFlow("f4", 4));
    final Map<TableKey, ItemSyncBox<Flow>> flowBoxMap = new LinkedHashMap<>();
    flowBoxMap.put(new TableKey((short) 0), flowBox);
    final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingFlows(NODE_ID, NODE_IDENT, flowBoxMap, counters);
    Assert.assertTrue(result.isDone());
    Assert.assertTrue(result.get().isSuccessful());
    final List<Flow> flowCaptorAllValues = flowCaptor.getAllValues();
    Assert.assertEquals(2, flowCaptorAllValues.size());
    Assert.assertEquals("f3", flowCaptorAllValues.get(0).getId().getValue());
    Assert.assertEquals("f4", flowCaptorAllValues.get(1).getId().getValue());
    final InOrder inOrderFlow = Mockito.inOrder(flowCapableTxService, flowCommitter);
    inOrderFlow.verify(flowCommitter, Mockito.times(2)).add(Matchers.<InstanceIdentifier<Flow>>any(), Matchers.<Flow>any(), Matchers.eq(NODE_IDENT));
    // TODO: uncomment when enabled in impl
    // inOrderFlow.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
    inOrderFlow.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) AddFlowOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with ItemSyncBox

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

the class SyncPlanPushStrategyFlatBatchImpl method assembleAddOrUpdateMeters.

@VisibleForTesting
static int assembleAddOrUpdateMeters(final List<Batch> batchBag, int batchOrder, final ItemSyncBox<Meter> meterItemSyncBox) {
    // process meter add+update
    int order = batchOrder;
    if (meterItemSyncBox != null) {
        if (!meterItemSyncBox.getItemsToPush().isEmpty()) {
            final List<FlatBatchAddMeter> flatBatchAddMeterBag = new ArrayList<>(meterItemSyncBox.getItemsToUpdate().size());
            int itemOrder = 0;
            for (Meter meter : meterItemSyncBox.getItemsToPush()) {
                flatBatchAddMeterBag.add(new FlatBatchAddMeterBuilder(meter).setBatchOrder(itemOrder++).build());
            }
            final Batch batch = new BatchBuilder().setBatchChoice(new FlatBatchAddMeterCaseBuilder().setFlatBatchAddMeter(flatBatchAddMeterBag).build()).setBatchOrder(order).build();
            order += itemOrder;
            batchBag.add(batch);
        }
        if (!meterItemSyncBox.getItemsToUpdate().isEmpty()) {
            final List<FlatBatchUpdateMeter> flatBatchUpdateMeterBag = new ArrayList<>(meterItemSyncBox.getItemsToUpdate().size());
            int itemOrder = 0;
            for (ItemSyncBox.ItemUpdateTuple<Meter> meterUpdate : meterItemSyncBox.getItemsToUpdate()) {
                flatBatchUpdateMeterBag.add(new FlatBatchUpdateMeterBuilder().setBatchOrder(itemOrder++).setOriginalBatchedMeter(new OriginalBatchedMeterBuilder(meterUpdate.getOriginal()).build()).setUpdatedBatchedMeter(new UpdatedBatchedMeterBuilder(meterUpdate.getUpdated()).build()).build());
            }
            final Batch batch = new BatchBuilder().setBatchChoice(new FlatBatchUpdateMeterCaseBuilder().setFlatBatchUpdateMeter(flatBatchUpdateMeterBag).build()).setBatchOrder(order).build();
            order += itemOrder;
            batchBag.add(batch);
        }
    }
    return order;
}
Also used : ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) UpdatedBatchedMeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.batch.meter.input.update.grouping.UpdatedBatchedMeterBuilder) Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) FlatBatchUpdateMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.meter._case.FlatBatchUpdateMeter) FlatBatchRemoveMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.meter._case.FlatBatchRemoveMeter) FlatBatchAddMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.meter._case.FlatBatchAddMeter) OriginalBatchedMeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.batch.meter.input.update.grouping.OriginalBatchedMeterBuilder) ArrayList(java.util.ArrayList) BatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.BatchBuilder) FlatBatchUpdateMeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.meter._case.FlatBatchUpdateMeterBuilder) FlatBatchUpdateMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.meter._case.FlatBatchUpdateMeter) Batch(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch) FlatBatchAddMeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.meter._case.FlatBatchAddMeterBuilder) FlatBatchAddMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.meter._case.FlatBatchAddMeter) FlatBatchAddMeterCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddMeterCaseBuilder) FlatBatchUpdateMeterCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchUpdateMeterCaseBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ItemSyncBox (org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox)20 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)16 ArrayList (java.util.ArrayList)10 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)10 Test (org.junit.Test)9 InOrder (org.mockito.InOrder)9 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)9 Meter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter)8 Group (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 Map (java.util.Map)6 CrudCounts (org.opendaylight.openflowplugin.applications.frsync.util.CrudCounts)6 LinkedHashMap (java.util.LinkedHashMap)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Batch (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch)4 BatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.BatchBuilder)4 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)4 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)4 SyncCrudCounters (org.opendaylight.openflowplugin.applications.frsync.util.SyncCrudCounters)3 Iterables (com.google.common.collect.Iterables)2