Search in sources :

Example 16 with MessageContext

use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.

the class RecordHandler method doInstallFlowForSwitchManager.

/**
 * Install of flow on the switch from SwitchManager topology.
 *
 * @param message with list of flows.
 */
private void doInstallFlowForSwitchManager(final CommandMessage message) {
    InstallFlowForSwitchManagerRequest request = (InstallFlowForSwitchManagerRequest) message.getData();
    String replyToTopic = context.getKafkaSwitchManagerTopic();
    FlowSegmentResponseFactory responseFactory = new FlowSegmentSyncResponseFactory(message.getCorrelationId(), replyToTopic);
    MessageContext messageContext = new MessageContext(message);
    Optional<FlowSegmentWrapperCommand> syncCommand = makeSyncCommand(request.getFlowCommand(), messageContext, responseFactory);
    if (syncCommand.isPresent()) {
        handleSpeakerCommand(syncCommand.get());
        return;
    }
    try {
        installFlow(request.getFlowCommand());
    } catch (SwitchOperationException e) {
        logger.error("Error during flow installation", e);
        ErrorData errorData = new ErrorData(ErrorType.INTERNAL_ERROR, "Error during flow installation", "Switch operation error");
        ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId());
        getKafkaProducer().sendMessageAndTrack(replyToTopic, message.getCorrelationId(), error);
    } catch (FlowCommandException e) {
        String errorMessage = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
        logger.error("Failed to handle message {}: {}", message, errorMessage);
        ErrorData errorData = new FlowCommandErrorData(e.getFlowId(), e.getCookie(), e.getTransactionId(), e.getErrorType(), errorMessage, e.getMessage());
        ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId());
        getKafkaProducer().sendMessageAndTrack(replyToTopic, message.getCorrelationId(), error);
    }
    InfoMessage response = new InfoMessage(new FlowInstallResponse(), System.currentTimeMillis(), message.getCorrelationId());
    getKafkaProducer().sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) FlowCommandErrorData(org.openkilda.messaging.error.rule.FlowCommandErrorData) FlowSegmentWrapperCommand(org.openkilda.floodlight.command.flow.FlowSegmentWrapperCommand) InstallFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.InstallFlowForSwitchManagerRequest) FlowInstallResponse(org.openkilda.messaging.info.flow.FlowInstallResponse) FlowSegmentResponseFactory(org.openkilda.floodlight.command.flow.FlowSegmentResponseFactory) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowCommandException(org.openkilda.floodlight.error.FlowCommandException) MessageContext(org.openkilda.messaging.MessageContext) FlowSegmentSyncResponseFactory(org.openkilda.floodlight.command.flow.FlowSegmentSyncResponseFactory) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) FlowCommandErrorData(org.openkilda.messaging.error.rule.FlowCommandErrorData) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 17 with MessageContext

use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.

the class UpdateYFlowRulesAction method buildYFlowInstallRequest.

protected InstallSpeakerCommandsRequest buildYFlowInstallRequest(SwitchId switchId, PathId pathId, CommandContext context) {
    List<OfCommand> ofCommands = buildYFlowOfCommands(switchId, pathId);
    UUID commandId = commandIdGenerator.generate();
    MessageContext messageContext = new MessageContext(commandId.toString(), context.getCorrelationId());
    return new InstallSpeakerCommandsRequest(messageContext, switchId, commandId, ofCommands);
}
Also used : OfCommand(org.openkilda.floodlight.api.request.rulemanager.OfCommand) InstallSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest) MessageContext(org.openkilda.messaging.MessageContext) UUID(java.util.UUID)

Example 18 with MessageContext

use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.

the class UpdateYFlowRulesAction method buildYFlowDeleteRequest.

protected DeleteSpeakerCommandsRequest buildYFlowDeleteRequest(SwitchId switchId, PathId pathId, CommandContext context) {
    List<OfCommand> ofCommands = buildYFlowOfCommands(switchId, pathId);
    UUID commandId = commandIdGenerator.generate();
    MessageContext messageContext = new MessageContext(commandId.toString(), context.getCorrelationId());
    return new DeleteSpeakerCommandsRequest(messageContext, switchId, commandId, ofCommands);
}
Also used : OfCommand(org.openkilda.floodlight.api.request.rulemanager.OfCommand) MessageContext(org.openkilda.messaging.MessageContext) UUID(java.util.UUID) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)

Example 19 with MessageContext

use of org.openkilda.messaging.MessageContext 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;
}
Also used : MirrorConfig(org.openkilda.model.MirrorConfig) Getter(lombok.Getter) Session(org.openkilda.floodlight.service.session.Session) OFGroupMod(org.projectfloodlight.openflow.protocol.OFGroupMod) FlowTransitData(org.openkilda.floodlight.model.FlowTransitData) MessageContext(org.openkilda.messaging.MessageContext) CompletableFuture(java.util.concurrent.CompletableFuture) InvalidGroupIdException(org.openkilda.floodlight.error.InvalidGroupIdException) OFGroupModFailedErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFGroupModFailedErrorMsg) SwitchIncorrectMirrorGroupException(org.openkilda.floodlight.error.SwitchIncorrectMirrorGroupException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) OFGroupModFailedCode(org.projectfloodlight.openflow.protocol.OFGroupModFailedCode) SwitchId(org.openkilda.model.SwitchId) SpeakerCommandProcessor(org.openkilda.floodlight.command.SpeakerCommandProcessor) SwitchGroupConflictException(org.openkilda.floodlight.error.SwitchGroupConflictException) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) Optional(java.util.Optional) SwitchMissingGroupException(org.openkilda.floodlight.error.SwitchMissingGroupException) OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) IOfErrorResponseHandler(org.openkilda.floodlight.command.IOfErrorResponseHandler) GroupId(org.openkilda.model.GroupId) SwitchErrorResponseException(org.openkilda.floodlight.error.SwitchErrorResponseException) CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) SwitchErrorResponseException(org.openkilda.floodlight.error.SwitchErrorResponseException)

Example 20 with MessageContext

use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.

the class SpeakerFlowSegmentRequestBuilder method makeEgressSegmentRequests.

private List<FlowSegmentRequestFactory> makeEgressSegmentRequests(CommandContext context, FlowPath path, FlowTransitEncapsulation encapsulation, PathSegment segment, FlowSideAdapter flowSide, FlowSideAdapter ingressFlowSide, MirrorContext mirrorContext) {
    Flow flow = flowSide.getFlow();
    PathSegmentSide segmentSide = makePathSegmentDestSide(segment);
    UUID commandId = commandIdGenerator.generate();
    MessageContext messageContext = new MessageContext(commandId.toString(), context.getCorrelationId());
    FlowSegmentMetadata metadata = makeMetadata(path, ensureEqualMultiTableFlag(segmentSide.isMultiTable(), path.isDestWithMultiTable(), String.format("Last flow(id:%s, path:%s) segment and flow path level multi-table flags value " + "are incompatible to each other - segment(%s) != flow path(%s)", flow.getFlowId(), path.getPathId(), segmentSide.isMultiTable(), path.isDestWithMultiTable())));
    List<FlowSegmentRequestFactory> egressFactories = new ArrayList<>();
    if (!mirrorContext.isBuildMirrorFactoryOnly()) {
        egressFactories.add(EgressFlowSegmentRequestFactory.builder().messageContext(messageContext).metadata(metadata).endpoint(flowSide.getEndpoint()).ingressEndpoint(ingressFlowSide.getEndpoint()).islPort(segmentSide.getEndpoint().getPortNumber()).encapsulation(encapsulation).build());
    }
    Optional<MirrorConfig> mirrorConfig = makeMirrorConfig(path, flowSide.getEndpoint(), mirrorContext);
    if (mirrorConfig.isPresent() || mirrorContext.isRemoveFlowOperation()) {
        FlowSegmentCookie mirrorCookie = path.getCookie().toBuilder().mirror(true).build();
        egressFactories.add(EgressMirrorFlowSegmentRequestFactory.builder().messageContext(new MessageContext(commandIdGenerator.generate().toString(), context.getCorrelationId())).metadata(makeMetadata(metadata.getFlowId(), mirrorCookie, metadata.isMultiTable())).endpoint(flowSide.getEndpoint()).ingressEndpoint(ingressFlowSide.getEndpoint()).islPort(segmentSide.getEndpoint().getPortNumber()).encapsulation(encapsulation).mirrorConfig(mirrorConfig.orElse(null)).build());
    }
    return egressFactories;
}
Also used : IngressMirrorFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.IngressMirrorFlowSegmentRequestFactory) IngressFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory) EgressMirrorFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.EgressMirrorFlowSegmentRequestFactory) EgressFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.EgressFlowSegmentRequestFactory) TransitFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.TransitFlowSegmentRequestFactory) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) MirrorConfig(org.openkilda.model.MirrorConfig) ArrayList(java.util.ArrayList) MessageContext(org.openkilda.messaging.MessageContext) UUID(java.util.UUID) FlowSegmentMetadata(org.openkilda.floodlight.model.FlowSegmentMetadata) Flow(org.openkilda.model.Flow)

Aggregations

MessageContext (org.openkilda.messaging.MessageContext)28 UUID (java.util.UUID)13 FlowSegmentMetadata (org.openkilda.floodlight.model.FlowSegmentMetadata)9 SwitchId (org.openkilda.model.SwitchId)9 ArrayList (java.util.ArrayList)7 Cookie (org.openkilda.model.cookie.Cookie)6 EgressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressFlowSegmentRequestFactory)5 InfoMessage (org.openkilda.messaging.info.InfoMessage)5 FlowEndpoint (org.openkilda.model.FlowEndpoint)5 MirrorConfig (org.openkilda.model.MirrorConfig)5 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)5 Session (org.openkilda.floodlight.service.session.Session)4 MeterConfig (org.openkilda.model.MeterConfig)4 MeterId (org.openkilda.model.MeterId)4 List (java.util.List)3 Optional (java.util.Optional)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 EgressMirrorFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressMirrorFlowSegmentRequestFactory)3 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)3 IngressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory)3