use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput in project openflowplugin by opendaylight.
the class FlowForwarder method update.
@Override
public void update(final InstanceIdentifier<Flow> identifier, final Flow original, final Flow update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class);
if (tableIdValidationPrecondition(tableKey, update)) {
final UpdateFlowInputBuilder builder = new UpdateFlowInputBuilder();
builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
builder.setFlowRef(new FlowRef(identifier));
builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
// This method is called only when a given flow object in datastore
// has been updated. So FRM always needs to set strict flag into
// update-flow input so that only a flow entry associated with
// a given flow object is updated.
builder.setUpdatedFlow(new UpdatedFlowBuilder(update).setStrict(Boolean.TRUE).build());
builder.setOriginalFlow(new OriginalFlowBuilder(original).setStrict(Boolean.TRUE).build());
final Future<RpcResult<UpdateFlowOutput>> resultFuture = provider.getSalFlowService().updateFlow(builder.build());
JdkFutures.addErrorLogging(resultFuture, LOG, "updateFlow");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput in project openflowplugin by opendaylight.
the class SyncPlanPushStrategyIncrementalImpl method executeSyncStrategy.
@Override
public ListenableFuture<RpcResult<Void>> executeSyncStrategy(ListenableFuture<RpcResult<Void>> resultVehicle, final SynchronizationDiffInput diffInput, final SyncCrudCounters counters) {
final InstanceIdentifier<FlowCapableNode> nodeIdent = diffInput.getNodeIdent();
final NodeId nodeId = PathUtil.digNodeId(nodeIdent);
/* Tables - have to be pushed before groups */
// TODO enable table-update when ready
// resultVehicle = updateTableFeatures(nodeIdent, configTree);
resultVehicle = Futures.transformAsync(resultVehicle, input -> {
if (!input.isSuccessful()) {
// TODO chain errors but not skip processing on first error return Futures.immediateFuture(input);
// final ListenableFuture<RpcResult<Void>> singleVoidUpdateResult = Futures.transform(
// Futures.asList Arrays.asList(input, output),
// ReconcileUtil.<UpdateFlowOutput>createRpcResultCondenser("TODO"));
}
return addMissingGroups(nodeId, nodeIdent, diffInput.getGroupsToAddOrUpdate(), counters);
}, MoreExecutors.directExecutor());
Futures.addCallback(resultVehicle, FxChainUtil.logResultCallback(nodeId, "addMissingGroups"), MoreExecutors.directExecutor());
resultVehicle = Futures.transformAsync(resultVehicle, input -> {
if (!input.isSuccessful()) {
// TODO chain errors but not skip processing on first error return Futures.immediateFuture(input);
}
return addMissingMeters(nodeId, nodeIdent, diffInput.getMetersToAddOrUpdate(), counters);
}, MoreExecutors.directExecutor());
Futures.addCallback(resultVehicle, FxChainUtil.logResultCallback(nodeId, "addMissingMeters"), MoreExecutors.directExecutor());
resultVehicle = Futures.transformAsync(resultVehicle, input -> {
if (!input.isSuccessful()) {
// TODO chain errors but not skip processing on first error return Futures.immediateFuture(input);
}
return addMissingFlows(nodeId, nodeIdent, diffInput.getFlowsToAddOrUpdate(), counters);
}, MoreExecutors.directExecutor());
Futures.addCallback(resultVehicle, FxChainUtil.logResultCallback(nodeId, "addMissingFlows"), MoreExecutors.directExecutor());
resultVehicle = Futures.transformAsync(resultVehicle, input -> {
if (!input.isSuccessful()) {
// TODO chain errors but not skip processing on first error return Futures.immediateFuture(input);
}
return removeRedundantFlows(nodeId, nodeIdent, diffInput.getFlowsToRemove(), counters);
}, MoreExecutors.directExecutor());
Futures.addCallback(resultVehicle, FxChainUtil.logResultCallback(nodeId, "removeRedundantFlows"), MoreExecutors.directExecutor());
resultVehicle = Futures.transformAsync(resultVehicle, input -> {
if (!input.isSuccessful()) {
// TODO chain errors but not skip processing on first error return Futures.immediateFuture(input);
}
return removeRedundantMeters(nodeId, nodeIdent, diffInput.getMetersToRemove(), counters);
}, MoreExecutors.directExecutor());
Futures.addCallback(resultVehicle, FxChainUtil.logResultCallback(nodeId, "removeRedundantMeters"), MoreExecutors.directExecutor());
resultVehicle = Futures.transformAsync(resultVehicle, input -> {
if (!input.isSuccessful()) {
// TODO chain errors but not skip processing on first error return Futures.immediateFuture(input);
}
return removeRedundantGroups(nodeId, nodeIdent, diffInput.getGroupsToRemove(), counters);
}, MoreExecutors.directExecutor());
Futures.addCallback(resultVehicle, FxChainUtil.logResultCallback(nodeId, "removeRedundantGroups"), MoreExecutors.directExecutor());
return resultVehicle;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput in project openflowplugin by opendaylight.
the class FlowForwarder method update.
@Override
public Future<RpcResult<UpdateFlowOutput>> update(final InstanceIdentifier<Flow> identifier, final Flow original, final Flow update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
LOG.trace("Forwarding Flow UPDATE request [Tbl id, node Id {} {} {}", identifier, nodeIdent, update);
final Future<RpcResult<UpdateFlowOutput>> output;
final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class);
if (tableIdValidationPrecondition(tableKey, update)) {
final UpdateFlowInputBuilder builder = new UpdateFlowInputBuilder();
builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
builder.setFlowRef(new FlowRef(identifier));
// always needs to set strict flag into update-flow input so that
// only a flow entry associated with a given flow object is updated.
builder.setUpdatedFlow(new UpdatedFlowBuilder(update).setStrict(Boolean.TRUE).build());
builder.setOriginalFlow(new OriginalFlowBuilder(original).setStrict(Boolean.TRUE).build());
output = salFlowService.updateFlow(builder.build());
} else {
output = RpcResultBuilder.<UpdateFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
}
return output;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput in project openflowplugin by opendaylight.
the class SyncPlanPushStrategyIncrementalImpl method addMissingFlows.
ListenableFuture<RpcResult<Void>> addMissingFlows(final NodeId nodeId, final InstanceIdentifier<FlowCapableNode> nodeIdent, final Map<TableKey, ItemSyncBox<Flow>> flowsInTablesSyncBox, final SyncCrudCounters counters) {
if (flowsInTablesSyncBox.isEmpty()) {
LOG.trace("no tables in config for node: {} -> SKIPPING", nodeId.getValue());
return RpcResultBuilder.<Void>success().buildFuture();
}
final List<ListenableFuture<RpcResult<AddFlowOutput>>> allResults = new ArrayList<>();
final List<ListenableFuture<RpcResult<UpdateFlowOutput>>> allUpdateResults = new ArrayList<>();
final CrudCounts flowCrudCounts = counters.getFlowCrudCounts();
for (Map.Entry<TableKey, ItemSyncBox<Flow>> flowsInTableBoxEntry : flowsInTablesSyncBox.entrySet()) {
final TableKey tableKey = flowsInTableBoxEntry.getKey();
final ItemSyncBox<Flow> flowSyncBox = flowsInTableBoxEntry.getValue();
final KeyedInstanceIdentifier<Table, TableKey> tableIdent = nodeIdent.child(Table.class, tableKey);
for (final Flow flow : flowSyncBox.getItemsToPush()) {
final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent = tableIdent.child(Flow.class, flow.getKey());
LOG.trace("adding flow {} in table {} - absent on device {} match{}", flow.getId(), tableKey, nodeId, flow.getMatch());
allResults.add(JdkFutureAdapters.listenInPoolThread(flowForwarder.add(flowIdent, flow, nodeIdent)));
flowCrudCounts.incAdded();
}
for (final ItemSyncBox.ItemUpdateTuple<Flow> flowUpdate : flowSyncBox.getItemsToUpdate()) {
final Flow existingFlow = flowUpdate.getOriginal();
final Flow updatedFlow = flowUpdate.getUpdated();
final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent = tableIdent.child(Flow.class, updatedFlow.getKey());
LOG.trace("flow {} in table {} - needs update on device {} match{}", updatedFlow.getId(), tableKey, nodeId, updatedFlow.getMatch());
allUpdateResults.add(JdkFutureAdapters.listenInPoolThread(flowForwarder.update(flowIdent, existingFlow, updatedFlow, nodeIdent)));
flowCrudCounts.incUpdated();
}
}
final ListenableFuture<RpcResult<Void>> singleVoidAddResult = Futures.transform(Futures.allAsList(allResults), ReconcileUtil.<AddFlowOutput>createRpcResultCondenser("flow adding"), MoreExecutors.directExecutor());
final ListenableFuture<RpcResult<Void>> singleVoidUpdateResult = Futures.transform(Futures.allAsList(allUpdateResults), ReconcileUtil.<UpdateFlowOutput>createRpcResultCondenser("flow updating"), MoreExecutors.directExecutor());
return Futures.transform(Futures.allAsList(singleVoidAddResult, singleVoidUpdateResult), ReconcileUtil.<Void>createRpcResultCondenser("flow add/update"), MoreExecutors.directExecutor());
}
Aggregations