use of org.projectfloodlight.openflow.protocol.OFErrorMsg in project open-kilda by telstra.
the class MeterInstallCommand method handleOfError.
@Override
public CompletableFuture<Optional<OFMessage>> handleOfError(OFErrorMsg response) {
CompletableFuture<Optional<OFMessage>> future = new CompletableFuture<>();
if (!isInstallConflict(response)) {
future.completeExceptionally(new SwitchErrorResponseException(getSw().getId(), String.format("Can't install meter %s - %s", meterConfig.getId(), response)));
return future;
}
log.info("Meter conflict detected sw:{} meter:{}", getSw().getId(), meterConfig.getId());
MeterVerifyCommand verifyCommand = new MeterVerifyCommand(messageContext, switchId, meterConfig);
propagateFutureResponse(future, commandProcessor.chain(verifyCommand).thenAccept(this::handleMeterVerify).thenApply(ignore -> Optional.empty()));
return future;
}
use of org.projectfloodlight.openflow.protocol.OFErrorMsg in project open-kilda by telstra.
the class OfBatchExecutor method executeBatch.
/**
* Execute current batch of commands.
*/
public void executeBatch() {
log.debug("Execute batch start (key={})", kafkaKey);
List<UUID> stageCommandsUuids = holder.getCurrentStage();
List<OFMessage> ofMessages = new ArrayList<>();
for (UUID uuid : stageCommandsUuids) {
log.debug("Start processing UUID: {} (key={})", uuid, kafkaKey);
if (holder.canExecute(uuid)) {
BatchData batchData = holder.getByUUid(uuid);
hasFlows |= batchData.isFlow();
hasMeters |= batchData.isMeter();
hasGroups |= batchData.isGroup();
ofMessages.add(batchData.getMessage());
} else {
Map<UUID, String> blockingDependencies = holder.getBlockingDependencies(uuid);
holder.recordFailedUuid(uuid, "Not all dependencies are satisfied: " + (blockingDependencies.isEmpty() ? "can't execute" : Joiner.on(",").withKeyValueSeparator("=").join(blockingDependencies)));
}
}
List<CompletableFuture<Optional<OFMessage>>> requests = new ArrayList<>();
try (Session session = sessionService.open(messageContext, iofSwitch)) {
for (OFMessage message : ofMessages) {
requests.add(session.write(message).whenComplete((res, ex) -> {
log.debug("Check responses (key={})", kafkaKey);
if (ex == null) {
res.ifPresent(ofMessage -> {
UUID uuid = holder.popAwaitingXid(ofMessage.getXid());
if (ofMessage instanceof OFErrorMsg) {
OFErrorMsg errorMsg = (OFErrorMsg) ofMessage;
holder.recordFailedUuid(uuid, errorMsg.getErrType().toString());
}
});
} else {
log.error("Received error {}", ex.getMessage(), ex);
}
}));
}
}
CompletableFuture.allOf(requests.toArray(new CompletableFuture<?>[0])).thenAccept(ignore -> checkOfResponses());
}
use of org.projectfloodlight.openflow.protocol.OFErrorMsg in project open-kilda by telstra.
the class SpeakerCommand method setupErrorHandler.
protected CompletableFuture<Optional<OFMessage>> setupErrorHandler(CompletableFuture<Optional<OFMessage>> future, IOfErrorResponseHandler handler) {
CompletableFuture<Optional<OFMessage>> branch = new CompletableFuture<>();
future.whenComplete((response, error) -> {
if (error == null) {
branch.complete(response);
} else {
Throwable actualError = unwrapError(error);
if (actualError instanceof SessionErrorResponseException) {
OFErrorMsg errorResponse = ((SessionErrorResponseException) error).getErrorResponse();
propagateFutureResponse(branch, handler.handleOfError(errorResponse));
} else {
branch.completeExceptionally(actualError);
}
}
});
return branch;
}
use of org.projectfloodlight.openflow.protocol.OFErrorMsg in project open-kilda by telstra.
the class GroupInstallCommand method handleOfError.
@Override
public CompletableFuture<Optional<OFMessage>> handleOfError(OFErrorMsg response) {
CompletableFuture<Optional<OFMessage>> future = new CompletableFuture<>();
if (!isInstallConflict(response)) {
future.completeExceptionally(new SwitchErrorResponseException(getSw().getId(), String.format("Can't install group %s - %s", mirrorConfig.getGroupId(), response)));
return future;
}
log.info("Group conflict detected sw:{} group:{}", getSw().getId(), mirrorConfig.getGroupId());
GroupVerifyCommand verifyCommand = new GroupVerifyCommand(messageContext, switchId, mirrorConfig, flowTransitData);
propagateFutureResponse(future, commandProcessor.chain(verifyCommand).thenAccept(this::handleGroupVerify).thenApply(ignore -> Optional.empty()));
return future;
}
use of org.projectfloodlight.openflow.protocol.OFErrorMsg in project open-kilda by telstra.
the class Session method handleResponse.
/**
* Handle switch response.
*
* <p>Lookup sent request by message Xid and mark it as completed(errored) if found. Return "true" if the
* session is completed and can be wiped, return "false" if the session need more responses.
*/
boolean handleResponse(OFMessage message) {
CompletableFuture<Optional<OFMessage>> future;
future = requestsByXid.get(message.getXid());
if (future == null) {
throw new IllegalArgumentException(String.format("%s must never route \"foreign\" response", group.getClass().getName()));
}
if (future.isDone()) {
// it can already be marked as failed by results of some session wide errors
return false;
}
// Setup correlationId (because this method called asynchronously by FL core).
try (CorrelationContext.CorrelationContextClosable closable = CorrelationContext.create(context.getCorrelationId())) {
if (OFType.ERROR == message.getType()) {
future.completeExceptionally(new SessionErrorResponseException(sw.getId(), (OFErrorMsg) message));
} else {
future.complete(Optional.of(message));
}
// check session completion (we have received all responses, if we got response for closing barrier request)
if (closingBarrier != null && closingBarrier.isDone()) {
incompleteRequestsStream().forEach(entry -> entry.complete(Optional.empty()));
return true;
}
return false;
}
}
Aggregations