Search in sources :

Example 6 with SalFlowService

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

the class FlowListenerTest method deleteFlowTest.

@Test
public void deleteFlowTest() throws Exception {
    addFlowCapableNode(NODE_KEY);
    FlowKey flowKey = new FlowKey(new FlowId("test_Flow"));
    InstanceIdentifier<Table> tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(Table.class, tableKey);
    InstanceIdentifier<Flow> flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey);
    Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
    Flow flow = new FlowBuilder().setKey(flowKey).setTableId((short) 2).build();
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
    writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
    assertCommit(writeTx.submit());
    SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
    List<AddFlowInput> addFlowCalls = salFlowService.getAddFlowCalls();
    assertEquals(1, addFlowCalls.size());
    assertEquals("DOM-0", addFlowCalls.get(0).getTransactionUri().getValue());
    writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.delete(LogicalDatastoreType.CONFIGURATION, flowII);
    assertCommit(writeTx.submit());
    salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
    List<RemoveFlowInput> removeFlowCalls = salFlowService.getRemoveFlowCalls();
    assertEquals(1, removeFlowCalls.size());
    assertEquals("DOM-1", removeFlowCalls.get(0).getTransactionUri().getValue());
    assertEquals(flowII, removeFlowCalls.get(0).getFlowRef().getValue());
    assertEquals(Boolean.TRUE, removeFlowCalls.get(0).isStrict());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) StaleFlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlowKey) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) 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) AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) TableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) StaleFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow) SalFlowServiceMock(test.mock.util.SalFlowServiceMock) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) StaleFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlowBuilder) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) RemoveFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput) FRMTest(test.mock.util.FRMTest) Test(org.junit.Test)

Example 7 with SalFlowService

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

the class FlowListenerTest method updateFlowScopeTest.

@Test
public void updateFlowScopeTest() throws Exception {
    addFlowCapableNode(NODE_KEY);
    FlowKey flowKey = new FlowKey(new FlowId("test_Flow"));
    InstanceIdentifier<Table> tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(Table.class, tableKey);
    InstanceIdentifier<Flow> flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey);
    Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
    IpMatch ipMatch = new IpMatchBuilder().setIpDscp(new Dscp((short) 4)).build();
    Match match = new MatchBuilder().setIpMatch(ipMatch).build();
    Flow flow = new FlowBuilder().setMatch(match).setKey(flowKey).setTableId((short) 2).build();
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
    writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
    assertCommit(writeTx.submit());
    SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
    List<AddFlowInput> addFlowCalls = salFlowService.getAddFlowCalls();
    assertEquals(1, addFlowCalls.size());
    assertEquals("DOM-0", addFlowCalls.get(0).getTransactionUri().getValue());
    flowKey = new FlowKey(new FlowId("test_Flow"));
    flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey);
    ipMatch = new IpMatchBuilder().setIpDscp(new Dscp((short) 5)).build();
    match = new MatchBuilder().setIpMatch(ipMatch).build();
    flow = new FlowBuilder().setMatch(match).setKey(flowKey).setTableId((short) 2).build();
    writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
    assertCommit(writeTx.submit());
    salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
    List<UpdateFlowInput> updateFlowCalls = salFlowService.getUpdateFlowCalls();
    assertEquals(1, updateFlowCalls.size());
    assertEquals("DOM-1", updateFlowCalls.get(0).getTransactionUri().getValue());
    assertEquals(flowII, updateFlowCalls.get(0).getFlowRef().getValue());
    assertEquals(ipMatch, updateFlowCalls.get(0).getUpdatedFlow().getMatch().getIpMatch());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) IpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) StaleFlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlowKey) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) 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) AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) TableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) IpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) StaleFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) IpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch) SalFlowServiceMock(test.mock.util.SalFlowServiceMock) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) StaleFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlowBuilder) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) Dscp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp) IpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) UpdateFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput) FRMTest(test.mock.util.FRMTest) Test(org.junit.Test)

Example 8 with SalFlowService

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

the class SalFlowsBatchServiceImplTest method testUpdateFlowsBatch_success.

@Test
public void testUpdateFlowsBatch_success() throws Exception {
    Mockito.when(salFlowService.updateFlow(Matchers.<UpdateFlowInput>any())).thenReturn(RpcResultBuilder.success(new UpdateFlowOutputBuilder().build()).buildFuture());
    final UpdateFlowsBatchInput input = new UpdateFlowsBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchUpdateFlows(Lists.newArrayList(createEmptyBatchUpdateFlow(FLOW_ID_VALUE_1, 42), createEmptyBatchUpdateFlow(FLOW_ID_VALUE_2, 44))).build();
    final Future<RpcResult<UpdateFlowsBatchOutput>> resultFuture = salFlowsBatchService.updateFlowsBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertTrue(resultFuture.get().isSuccessful());
    final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService);
    inOrder.verify(salFlowService, Mockito.times(2)).updateFlow(updateFlowInputCpt.capture());
    final List<UpdateFlowInput> allValues = updateFlowInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42, allValues.get(0).getOriginalFlow().getPriority().longValue());
    Assert.assertEquals(43, allValues.get(0).getUpdatedFlow().getPriority().longValue());
    Assert.assertEquals(44, allValues.get(1).getOriginalFlow().getPriority().longValue());
    Assert.assertEquals(45, allValues.get(1).getUpdatedFlow().getPriority().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : UpdateFlowOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder) UpdateFlowsBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInputBuilder) InOrder(org.mockito.InOrder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UpdateFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInput) UpdateFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput) Test(org.junit.Test)

Example 9 with SalFlowService

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

the class SalFlowsBatchServiceImplTest method testAddFlowsBatch_failed.

@Test
public void testAddFlowsBatch_failed() throws Exception {
    Mockito.when(salFlowService.addFlow(Matchers.<AddFlowInput>any())).thenReturn(RpcResultBuilder.<AddFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ut-groupAddError").buildFuture());
    final AddFlowsBatchInput input = new AddFlowsBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchAddFlows(Lists.newArrayList(createEmptyBatchAddFlow(FLOW_ID_VALUE_1, 42), createEmptyBatchAddFlow(FLOW_ID_VALUE_2, 43))).build();
    final Future<RpcResult<AddFlowsBatchOutput>> resultFuture = salFlowsBatchService.addFlowsBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertFalse(resultFuture.get().isSuccessful());
    Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedFlowsOutput().size());
    Assert.assertEquals(FLOW_ID_VALUE_1, resultFuture.get().getResult().getBatchFailedFlowsOutput().get(0).getFlowId().getValue());
    Assert.assertEquals(FLOW_ID_VALUE_2, resultFuture.get().getResult().getBatchFailedFlowsOutput().get(1).getFlowId().getValue());
    Assert.assertEquals(2, resultFuture.get().getErrors().size());
    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) Test(org.junit.Test)

Example 10 with SalFlowService

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

the class SalFlowsBatchServiceImplTest method testRemoveFlowsBatch_failed.

@Test
public void testRemoveFlowsBatch_failed() throws Exception {
    Mockito.when(salFlowService.removeFlow(Matchers.<RemoveFlowInput>any())).thenReturn(RpcResultBuilder.<RemoveFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, "flow-remove-fail-1").buildFuture());
    final BatchRemoveFlows batchFlow1 = createEmptyBatchRemoveFlow(FLOW_ID_VALUE_1, 42);
    final BatchRemoveFlows batchFlow2 = createEmptyBatchRemoveFlow(FLOW_ID_VALUE_2, 43);
    final RemoveFlowsBatchInput input = new RemoveFlowsBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchRemoveFlows(Lists.newArrayList(batchFlow1, batchFlow2)).build();
    final Future<RpcResult<RemoveFlowsBatchOutput>> resultFuture = salFlowsBatchService.removeFlowsBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    final RpcResult<RemoveFlowsBatchOutput> rpcResult = resultFuture.get();
    Assert.assertFalse(rpcResult.isSuccessful());
    final RemoveFlowsBatchOutput result = rpcResult.getResult();
    Assert.assertEquals(2, result.getBatchFailedFlowsOutput().size());
    Assert.assertEquals(FLOW_ID_VALUE_1, result.getBatchFailedFlowsOutput().get(0).getFlowId().getValue());
    Assert.assertEquals(FLOW_ID_VALUE_2, result.getBatchFailedFlowsOutput().get(1).getFlowId().getValue());
    final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService);
    inOrder.verify(salFlowService, Mockito.times(2)).removeFlow(removeFlowInputCpt.capture());
    final List<RemoveFlowInput> allValues = removeFlowInputCpt.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 : RemoveFlowsBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInputBuilder) InOrder(org.mockito.InOrder) RemoveFlowsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput) RemoveFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) BatchRemoveFlows(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.remove.flows.batch.input.BatchRemoveFlows) RemoveFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInput) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)10 AddFlowInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput)9 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)7 InOrder (org.mockito.InOrder)6 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)6 UpdateFlowInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput)6 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)5 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)5 RemoveFlowInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput)5 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)5 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)5 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)4 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)4 TableBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder)4 StaleFlow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow)4 StaleFlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlowBuilder)4 StaleFlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlowKey)4 FRMTest (test.mock.util.FRMTest)4