Search in sources :

Example 1 with AddFlowOutputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder 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 2 with AddFlowOutputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder 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 3 with AddFlowOutputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder in project openflowplugin by opendaylight.

the class SalBulkFlowServiceImplTest method testAddRemoveFlowsRpc.

@Test
public void testAddRemoveFlowsRpc() throws Exception {
    Mockito.when(mockSalFlowService.addFlow(Matchers.<AddFlowInput>any())).thenReturn(RpcResultBuilder.success(new AddFlowOutputBuilder().build()).buildFuture());
    Mockito.when(mockSalFlowService.removeFlow(Matchers.<RemoveFlowInput>any())).thenReturn(RpcResultBuilder.success(new RemoveFlowOutputBuilder().build()).buildFuture());
    final BulkFlowItemBuilder bulkFlowItemBuilder = new BulkFlowItemBuilder();
    final InstanceIdentifier<Node> nodeId = BulkOMaticUtils.getFlowCapableNodeId("1");
    bulkFlowItemBuilder.setNode(new NodeRef(nodeId));
    final BulkFlowItem bulkFlowItem = bulkFlowItemBuilder.build();
    final List<BulkFlowItem> bulkFlowItems = new ArrayList<>();
    bulkFlowItems.add(bulkFlowItem);
    final AddFlowsRpcInputBuilder addFlowsRpcInputBuilder = new AddFlowsRpcInputBuilder();
    addFlowsRpcInputBuilder.setBulkFlowItem(bulkFlowItems);
    final AddFlowsRpcInput addFlowsRpcInput = addFlowsRpcInputBuilder.build();
    salBulkFlowService.addFlowsRpc(addFlowsRpcInput);
    verify(mockSalFlowService).addFlow(Matchers.<AddFlowInput>any());
    final RemoveFlowsRpcInputBuilder removeFlowsRpcInputBuilder = new RemoveFlowsRpcInputBuilder();
    removeFlowsRpcInputBuilder.setBulkFlowItem(bulkFlowItems);
    final RemoveFlowsRpcInput removeFlowsRpcInput = removeFlowsRpcInputBuilder.build();
    salBulkFlowService.removeFlowsRpc(removeFlowsRpcInput);
    verify(mockSalFlowService).removeFlow(Matchers.<RemoveFlowInput>any());
}
Also used : BulkFlowItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.bulk.flow.list.grouping.BulkFlowItemBuilder) BulkFlowItem(org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.bulk.flow.list.grouping.BulkFlowItem) RemoveFlowOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) ArrayList(java.util.ArrayList) AddFlowOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder) RemoveFlowsRpcInput(org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.RemoveFlowsRpcInput) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) AddFlowsRpcInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.AddFlowsRpcInputBuilder) AddFlowsRpcInput(org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.AddFlowsRpcInput) RemoveFlowsRpcInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.RemoveFlowsRpcInputBuilder) Test(org.junit.Test)

Example 4 with AddFlowOutputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder in project openflowplugin by opendaylight.

the class FlowForwarderTest method addTest.

@Test
public void addTest() throws Exception {
    Mockito.when(salFlowService.addFlow(addFlowInputCpt.capture())).thenReturn(RpcResultBuilder.success(new AddFlowOutputBuilder().setTransactionId(new TransactionId(BigInteger.ONE)).build()).buildFuture());
    final Future<RpcResult<AddFlowOutput>> addResult = flowForwarder.add(flowPath, flow, flowCapableNodePath);
    Mockito.verify(salFlowService).addFlow(Matchers.<AddFlowInput>any());
    final AddFlowInput flowInput = addFlowInputCpt.getValue();
    Assert.assertEquals(2, flowInput.getTableId().shortValue());
    Assert.assertEquals(emptyMatch, flowInput.getMatch());
    Assert.assertEquals(null, flowInput.getInstructions());
    Assert.assertEquals(nodePath, flowInput.getNode().getValue());
    Assert.assertEquals(flowPath, flowInput.getFlowRef().getValue());
    Assert.assertEquals(null, flowInput.isStrict());
    final RpcResult<AddFlowOutput> addFlowOutputRpcResult = addResult.get(2, TimeUnit.SECONDS);
    Assert.assertTrue(addFlowOutputRpcResult.isSuccessful());
    final AddFlowOutput resultValue = addFlowOutputRpcResult.getResult();
    Assert.assertEquals(1, resultValue.getTransactionId().getValue().intValue());
}
Also used : AddFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) AddFlowOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder) TransactionId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId) Test(org.junit.Test)

Example 5 with AddFlowOutputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder in project openflowplugin by opendaylight.

the class SalFlowsBatchServiceImplTest method testAddFlowsBatch_success.

@Test
public void testAddFlowsBatch_success() throws Exception {
    Mockito.when(salFlowService.addFlow(Matchers.<AddFlowInput>any())).thenReturn(RpcResultBuilder.success(new AddFlowOutputBuilder().build()).buildFuture());
    final AddFlowsBatchInput input = new AddFlowsBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchAddFlows(Lists.newArrayList(createEmptyBatchAddFlow("ut-dummy-flow1", 42), createEmptyBatchAddFlow("ut-dummy-flow2", 43))).build();
    final Future<RpcResult<AddFlowsBatchOutput>> resultFuture = salFlowsBatchService.addFlowsBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertTrue(resultFuture.get().isSuccessful());
    final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService);
    inOrder.verify(salFlowService, Mockito.times(2)).addFlow(addFlowInputCpt.capture());
    final List<AddFlowInput> allValues = addFlowInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42, allValues.get(0).getPriority().longValue());
    Assert.assertEquals(43, allValues.get(1).getPriority().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : AddFlowsBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInputBuilder) InOrder(org.mockito.InOrder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) AddFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput) AddFlowOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 AddFlowOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder)5 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 InOrder (org.mockito.InOrder)3 LinkedHashMap (java.util.LinkedHashMap)2 ItemSyncBox (org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox)2 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)2 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)2 AddFlowInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput)2 ArrayList (java.util.ArrayList)1 AddFlowsRpcInput (org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.AddFlowsRpcInput)1 AddFlowsRpcInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.AddFlowsRpcInputBuilder)1 RemoveFlowsRpcInput (org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.RemoveFlowsRpcInput)1 RemoveFlowsRpcInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.RemoveFlowsRpcInputBuilder)1 BulkFlowItem (org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.bulk.flow.list.grouping.BulkFlowItem)1 BulkFlowItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.bulk.flow.list.grouping.BulkFlowItemBuilder)1 AddFlowOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput)1 RemoveFlowOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder)1 UpdateFlowOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder)1 TransactionId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId)1