Search in sources :

Example 11 with SalFlowService

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

the class OpenflowpluginTestServiceProvider method register.

public ObjectRegistration<OpenflowpluginTestServiceProvider> register(final ProviderContext ctx) {
    RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation = ctx.<SalFlowService>addRoutedRpcImplementation(SalFlowService.class, this);
    setFlowRegistration(addRoutedRpcImplementation);
    InstanceIdentifierBuilder<Nodes> builderII = InstanceIdentifier.<Nodes>builder(Nodes.class);
    NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
    NodeKey nodeKey = new NodeKey(nodeId);
    InstanceIdentifierBuilder<Node> nodeIdentifier = builderII.<Node, NodeKey>child(Node.class, nodeKey);
    InstanceIdentifier<Node> instance = nodeIdentifier.build();
    flowRegistration.registerPath(NodeContext.class, instance);
    RoutedRpcRegistration<SalFlowService> flowRegistration2 = getFlowRegistration();
    return new AbstractObjectRegistration<OpenflowpluginTestServiceProvider>(this) {

        @Override
        protected void removeRegistration() {
            flowRegistration2.close();
        }
    };
}
Also used : AbstractObjectRegistration(org.opendaylight.yangtools.concepts.AbstractObjectRegistration) SalFlowService(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)

Example 12 with SalFlowService

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

the class FlowListenerTest method updateFlowTest.

@Test
public void updateFlowTest() 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());
    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);
    flow = new FlowBuilder().setKey(flowKey).setTableId((short) 2).setOutGroup((long) 5).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(Boolean.TRUE, updateFlowCalls.get(0).getOriginalFlow().isStrict());
    assertEquals(Boolean.TRUE, updateFlowCalls.get(0).getUpdatedFlow().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) UpdateFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput) FRMTest(test.mock.util.FRMTest) Test(org.junit.Test)

Example 13 with SalFlowService

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

the class FlowListenerTest method addTwoFlowsTest.

@Test
public void addTwoFlowsTest() 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());
    flowKey = new FlowKey(new FlowId("test_Flow2"));
    flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey);
    flow = new FlowBuilder().setKey(flowKey).setTableId((short) 2).build();
    writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
    assertCommit(writeTx.submit());
    salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
    addFlowCalls = salFlowService.getAddFlowCalls();
    assertEquals(2, addFlowCalls.size());
    assertEquals("DOM-1", addFlowCalls.get(1).getTransactionUri().getValue());
    assertEquals(2, addFlowCalls.get(1).getTableId().intValue());
    assertEquals(flowII, addFlowCalls.get(1).getFlowRef().getValue());
}
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) FRMTest(test.mock.util.FRMTest) Test(org.junit.Test)

Example 14 with SalFlowService

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

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

the class FlowForwarderTest method updateTest.

@Test
public void updateTest() throws Exception {
    Mockito.when(salFlowService.updateFlow(updateFlowInputCpt.capture())).thenReturn(RpcResultBuilder.success(new UpdateFlowOutputBuilder().setTransactionId(new TransactionId(BigInteger.ONE)).build()).buildFuture());
    final Instructions originalInstructions = new InstructionsBuilder().setInstruction(Collections.singletonList(new InstructionBuilder().setInstruction(new ApplyActionsCaseBuilder().setApplyActions(new ApplyActionsBuilder().setAction(Collections.singletonList(new ActionBuilder().setAction(new DropActionCaseBuilder().build()).build())).build()).build()).build())).build();
    final Flow flowUpdated = new FlowBuilder(flow).setInstructions(originalInstructions).setMatch(new MatchBuilder().build()).build();
    final Future<RpcResult<UpdateFlowOutput>> updateResult = flowForwarder.update(flowPath, flow, flowUpdated, flowCapableNodePath);
    Mockito.verify(salFlowService).updateFlow(Matchers.<UpdateFlowInput>any());
    final UpdateFlowInput updateFlowInput = updateFlowInputCpt.getValue();
    final OriginalFlow flowOrigInput = updateFlowInput.getOriginalFlow();
    final UpdatedFlow flowInput = updateFlowInput.getUpdatedFlow();
    Assert.assertEquals(nodePath, updateFlowInput.getNode().getValue());
    Assert.assertEquals(flowPath, updateFlowInput.getFlowRef().getValue());
    Assert.assertEquals(2, flowInput.getTableId().shortValue());
    Assert.assertEquals(emptyMatch, flowInput.getMatch());
    Assert.assertEquals(originalInstructions, flowInput.getInstructions());
    Assert.assertEquals(true, flowInput.isStrict());
    Assert.assertEquals(2, flowOrigInput.getTableId().shortValue());
    Assert.assertEquals(emptyMatch, flowOrigInput.getMatch());
    Assert.assertEquals(null, flowOrigInput.getInstructions());
    Assert.assertEquals(true, flowOrigInput.isStrict());
    final RpcResult<UpdateFlowOutput> updateFlowOutputRpcResult = updateResult.get(2, TimeUnit.SECONDS);
    Assert.assertTrue(updateFlowOutputRpcResult.isSuccessful());
    final UpdateFlowOutput resultValue = updateFlowOutputRpcResult.getResult();
    Assert.assertEquals(1, resultValue.getTransactionId().getValue().intValue());
}
Also used : InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder) UpdatedFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Instructions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions) OriginalFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow) TransactionId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId) InstructionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) UpdatedFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow) OriginalFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow) UpdateFlowOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) ApplyActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder) UpdateFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput) ApplyActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) DropActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder) UpdateFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput) 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