Search in sources :

Example 6 with AddFlowInputBuilder

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

the class FlowForwarder method add.

@Override
public Future<RpcResult<AddFlowOutput>> add(final InstanceIdentifier<Flow> identifier, final Flow addDataObj, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
    Future<RpcResult<AddFlowOutput>> future;
    final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class);
    if (tableIdValidationPrecondition(tableKey, addDataObj)) {
        final AddFlowInputBuilder builder = new AddFlowInputBuilder(addDataObj);
        builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
        builder.setFlowRef(new FlowRef(identifier));
        builder.setFlowTable(new FlowTableRef(nodeIdent.child(Table.class, tableKey)));
        builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
        future = provider.getSalFlowService().addFlow(builder.build());
    } else {
        future = Futures.<RpcResult<AddFlowOutput>>immediateFuture(null);
    }
    return future;
}
Also used : AddFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) FlowTableRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef) FlowRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)

Example 7 with AddFlowInputBuilder

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

the class SalBulkFlowServiceImpl method addFlowsRpc.

@Override
public Future<RpcResult<Void>> addFlowsRpc(AddFlowsRpcInput input) {
    List<ListenableFuture<RpcResult<AddFlowOutput>>> bulkResults = new ArrayList<>();
    for (BulkFlowBaseContentGrouping bulkFlow : input.getBulkFlowItem()) {
        AddFlowInputBuilder flowInputBuilder = new AddFlowInputBuilder((org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) bulkFlow);
        final NodeRef nodeRef = bulkFlow.getNode();
        flowInputBuilder.setNode(nodeRef);
        flowInputBuilder.setTableId(bulkFlow.getTableId());
        Future<RpcResult<AddFlowOutput>> rpcAddFlowResult = flowService.addFlow(flowInputBuilder.build());
        bulkResults.add(JdkFutureAdapters.listenInPoolThread(rpcAddFlowResult));
    }
    return handleResultFuture(Futures.allAsList(bulkResults));
}
Also used : AddFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput) BulkFlowBaseContentGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.BulkFlowBaseContentGrouping) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder)

Example 8 with AddFlowInputBuilder

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

the class SalFlowServiceImpl method updateFlow.

@Override
public Future<RpcResult<UpdateFlowOutput>> updateFlow(final UpdateFlowInput input) {
    final UpdatedFlow updated = input.getUpdatedFlow();
    final OriginalFlow original = input.getOriginalFlow();
    final List<FlowModInputBuilder> allFlowMods = new ArrayList<>();
    final List<FlowModInputBuilder> ofFlowModInputs;
    ListenableFuture<RpcResult<UpdateFlowOutput>> future;
    if (flowUpdateMessage.canUseSingleLayerSerialization()) {
        if (!FlowCreatorUtil.canModifyFlow(original, updated, flowUpdateMessage.getVersion())) {
            final SettableFuture<RpcResult<UpdateFlowOutput>> objectSettableFuture = SettableFuture.create();
            final ListenableFuture<List<RpcResult<UpdateFlowOutput>>> listListenableFuture = Futures.successfulAsList(flowUpdateMessage.handleServiceCall(input.getOriginalFlow()), flowUpdateMessage.handleServiceCall(input.getUpdatedFlow()));
            Futures.addCallback(listListenableFuture, new FutureCallback<List<RpcResult<UpdateFlowOutput>>>() {

                @Override
                public void onSuccess(@Nonnull final List<RpcResult<UpdateFlowOutput>> results) {
                    final ArrayList<RpcError> errors = new ArrayList();
                    for (RpcResult<UpdateFlowOutput> flowModResult : results) {
                        if (flowModResult == null) {
                            errors.add(RpcResultBuilder.newError(RpcError.ErrorType.PROTOCOL, OFConstants.APPLICATION_TAG, "unexpected flowMod result (null) occurred"));
                        } else if (!flowModResult.isSuccessful()) {
                            errors.addAll(flowModResult.getErrors());
                        }
                    }
                    final RpcResultBuilder<UpdateFlowOutput> rpcResultBuilder;
                    if (errors.isEmpty()) {
                        rpcResultBuilder = RpcResultBuilder.success();
                    } else {
                        rpcResultBuilder = RpcResultBuilder.<UpdateFlowOutput>failed().withRpcErrors(errors);
                    }
                    objectSettableFuture.set(rpcResultBuilder.build());
                }

                @Override
                public void onFailure(final Throwable throwable) {
                    RpcResultBuilder<UpdateFlowOutput> rpcResultBuilder = RpcResultBuilder.failed();
                    objectSettableFuture.set(rpcResultBuilder.build());
                }
            }, MoreExecutors.directExecutor());
            future = objectSettableFuture;
        } else {
            future = flowUpdateMessage.handleServiceCall(input.getUpdatedFlow());
        }
    } else {
        if (!FlowCreatorUtil.canModifyFlow(original, updated, flowUpdate.getVersion())) {
            // We would need to remove original and add updated.
            // remove flow
            final RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(original);
            final List<FlowModInputBuilder> ofFlowRemoveInput = flowUpdate.toFlowModInputs(removeflow.build());
            // remove flow should be the first
            allFlowMods.addAll(ofFlowRemoveInput);
            final AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(updated);
            ofFlowModInputs = flowUpdate.toFlowModInputs(addFlowInputBuilder.build());
        } else {
            ofFlowModInputs = flowUpdate.toFlowModInputs(updated);
        }
        allFlowMods.addAll(ofFlowModInputs);
        future = flowUpdate.processFlowModInputBuilders(allFlowMods);
    }
    Futures.addCallback(future, new UpdateFlowCallback(input), MoreExecutors.directExecutor());
    return future;
}
Also used : RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) UpdatedFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) OriginalFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) UpdateFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput) RemoveFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with AddFlowInputBuilder

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

the class LLDPPacketPuntEnforcer method onDataTreeChanged.

@Override
public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<FlowCapableNode>> modifications) {
    for (DataTreeModification<FlowCapableNode> modification : modifications) {
        if (modification.getRootNode().getModificationType() == ModificationType.WRITE) {
            AddFlowInputBuilder addFlowInput = new AddFlowInputBuilder(createFlow());
            addFlowInput.setNode(new NodeRef(modification.getRootPath().getRootIdentifier().firstIdentifierOf(Node.class)));
            final Future<RpcResult<AddFlowOutput>> resultFuture = this.flowService.addFlow(addFlowInput.build());
            JdkFutures.addErrorLogging(resultFuture, LOG, "addFlow");
        }
    }
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder)

Example 10 with AddFlowInputBuilder

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

the class FlowForwarder method add.

@Override
public Future<RpcResult<AddFlowOutput>> add(final InstanceIdentifier<Flow> identifier, final Flow addDataObj, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
    LOG.trace("Forwarding the Flow ADD request [Tbl id, node Id {} {} {}", identifier, nodeIdent, addDataObj);
    final Future<RpcResult<AddFlowOutput>> output;
    final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class);
    if (tableIdValidationPrecondition(tableKey, addDataObj)) {
        final AddFlowInputBuilder builder = new AddFlowInputBuilder(addDataObj);
        builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
        builder.setFlowRef(new FlowRef(identifier));
        builder.setFlowTable(new FlowTableRef(nodeIdent.child(Table.class, tableKey)));
        output = salFlowService.addFlow(builder.build());
    } else {
        output = RpcResultBuilder.<AddFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
    }
    return output;
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) FlowTableRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef) FlowRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)

Aggregations

AddFlowInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder)15 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 AddFlowInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput)7 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)7 ArrayList (java.util.ArrayList)4 AddFlowOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput)4 FlowRef (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 BigInteger (java.math.BigInteger)2 List (java.util.List)2 Test (org.junit.Test)2 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)2 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)2 FlowTableRef (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef)2 RemoveFlowInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder)2 InstructionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder)2 ApplyActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder)2 ApplyActionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder)2 FlowModInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder)2 ExecutionException (java.util.concurrent.ExecutionException)1