Search in sources :

Example 36 with FlowProcessingException

use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.

the class YFlowUpdateHubBolt method onRequest.

@Override
protected void onRequest(Tuple input) throws PipelineException {
    currentKey = pullKey(input);
    CommandData payload = pullValue(input, FIELD_ID_PAYLOAD, CommandData.class);
    try {
        if (payload instanceof YFlowRequest) {
            yflowUpdateService.handleRequest(currentKey, pullContext(input), (YFlowRequest) payload);
        } else if (payload instanceof YFlowPartialUpdateRequest) {
            yflowUpdateService.handlePartialUpdateRequest(currentKey, pullContext(input), (YFlowPartialUpdateRequest) payload);
        } else {
            unhandledInput(input);
        }
    } catch (DuplicateKeyException e) {
        log.error("Failed to handle a request with key {}. {}", currentKey, e.getMessage());
    } catch (FlowProcessingException e) {
        ErrorData errorData = new ErrorData(e.getErrorType(), "Y-flow update error", e.getMessage());
        CommandContext commandContext = getCommandContext();
        ErrorMessage errorMessage = new ErrorMessage(errorData, commandContext.getCreateTime(), commandContext.getCorrelationId());
        sendNorthboundResponse(errorMessage);
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) YFlowPartialUpdateRequest(org.openkilda.messaging.command.yflow.YFlowPartialUpdateRequest) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 37 with FlowProcessingException

use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.

the class ResourceAllocationAction method allocate.

@Override
protected void allocate(FlowMirrorPointCreateFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
    RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
    transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(mirrorPoint.getFlowId());
        FlowPath flowPath = getFlowPath(mirrorPoint, flow);
        stateMachine.setFlowPathId(flowPath.getPathId());
        Optional<FlowMirrorPoints> foundFlowMirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPath.getPathId(), mirrorPoint.getMirrorPointSwitchId());
        FlowMirrorPoints flowMirrorPoints;
        if (foundFlowMirrorPoints.isPresent()) {
            flowMirrorPoints = foundFlowMirrorPoints.get();
        } else {
            flowMirrorPoints = createFlowMirrorPoints(mirrorPoint, flowPath);
            stateMachine.setAddNewGroup(true);
        }
        Switch sinkSwitch = switchRepository.findById(mirrorPoint.getSinkEndpoint().getSwitchId()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", mirrorPoint.getSinkEndpoint().getSwitchId())));
        stateMachine.setUnmaskedCookie(resourcesManager.getAllocatedCookie(flow.getFlowId()));
        FlowSegmentCookie cookie = FlowSegmentCookie.builder().flowEffectiveId(stateMachine.getUnmaskedCookie()).mirror(true).build();
        SwitchProperties switchProperties = getSwitchProperties(sinkSwitch.getSwitchId());
        boolean dstWithMultiTable = switchProperties != null ? switchProperties.isMultiTable() : kildaConfigurationRepository.getOrDefault().getUseMultiTable();
        FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(stateMachine.getMirrorPathId()).mirrorSwitch(flowMirrorPoints.getMirrorSwitch()).egressSwitch(sinkSwitch).egressPort(mirrorPoint.getSinkEndpoint().getPortNumber()).egressOuterVlan(mirrorPoint.getSinkEndpoint().getOuterVlanId()).egressInnerVlan(mirrorPoint.getSinkEndpoint().getInnerVlanId()).cookie(cookie).bandwidth(flow.getBandwidth()).ignoreBandwidth(flow.isIgnoreBandwidth()).status(FlowPathStatus.IN_PROGRESS).egressWithMultiTable(dstWithMultiTable).build();
        flowMirrorPathRepository.add(flowMirrorPath);
        flowMirrorPoints.addPaths(flowMirrorPath);
    // TODO: add path allocation in case when src switch is not equal to dst switch
    });
    stateMachine.saveActionToHistory("New mirror path was created", format("The flow mirror path %s was created (with allocated resources)", stateMachine.getMirrorPathId()));
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) Switch(org.openkilda.model.Switch) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowPath(org.openkilda.model.FlowPath) SwitchProperties(org.openkilda.model.SwitchProperties) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Flow(org.openkilda.model.Flow)

Example 38 with FlowProcessingException

use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.

the class EmitCommandRequestsAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    PathId flowPathId = stateMachine.getFlowPathId();
    SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
    FlowMirrorPoints mirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror points for flow path %s and mirror switch id %s not found", flowPathId, mirrorSwitchId)));
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    Collection<FlowSegmentRequestFactory> commands = buildCommands(commandBuilder, stateMachine, flow, mirrorPoints);
    // emitting
    SpeakerRequestEmitter requestEmitter;
    if (mirrorPoints.getMirrorPaths().isEmpty()) {
        requestEmitter = SpeakerRemoveSegmentEmitter.INSTANCE;
    } else {
        requestEmitter = SpeakerInstallSegmentEmitter.INSTANCE;
    }
    requestEmitter.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getCommands());
    stateMachine.getCommands().forEach((key, value) -> stateMachine.getPendingCommands().put(key, value.getSwitchId()));
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove group");
    } else {
        stateMachine.saveActionToHistory("Commands for removing group have been sent");
    }
}
Also used : PathId(org.openkilda.model.PathId) SpeakerRequestEmitter(org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow)

Example 39 with FlowProcessingException

use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.

the class PostResourceAllocationAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    Flow flow = getFlow(stateMachine.getFlowId());
    PathId flowMirrorPathId = stateMachine.getMirrorPathId();
    FlowMirrorPath flowMirrorPath = flowMirrorPathRepository.findById(flowMirrorPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror path %s not found", flowMirrorPathId)));
    String direction = flowMirrorPath.getFlowMirrorPoints().getFlowPath().isForward() ? "forward" : "reverse";
    FlowMirrorPointResponse response = FlowMirrorPointResponse.builder().flowId(flow.getFlowId()).mirrorPointId(flowMirrorPath.getPathId().getId()).mirrorPointDirection(direction).mirrorPointSwitchId(flowMirrorPath.getMirrorSwitchId()).sinkEndpoint(FlowEndpoint.builder().switchId(flowMirrorPath.getEgressSwitchId()).portNumber(flowMirrorPath.getEgressPort()).outerVlanId(flowMirrorPath.getEgressOuterVlan()).innerVlanId(flowMirrorPath.getEgressInnerVlan()).build()).build();
    CommandContext commandContext = stateMachine.getCommandContext();
    return Optional.of(new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId()));
}
Also used : PathId(org.openkilda.model.PathId) FlowMirrorPointResponse(org.openkilda.messaging.info.flow.FlowMirrorPointResponse) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Flow(org.openkilda.model.Flow)

Example 40 with FlowProcessingException

use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.

the class DeallocateFlowMirrorPathResourcesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
    PathId mirrorPathId = stateMachine.getMirrorPathId();
    FlowMirrorPath flowMirrorPath = flowMirrorPathRepository.findById(mirrorPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror point %s not found", mirrorPathId)));
    FlowMirrorPoints flowMirrorPoints = flowMirrorPath.getFlowMirrorPoints();
    stateMachine.setFlowPathId(flowMirrorPoints.getFlowPathId());
    stateMachine.setMirrorSwitchId(flowMirrorPoints.getMirrorSwitchId());
    resourcesManager.deallocateCookie(flowMirrorPath.getCookie().getFlowEffectiveId());
    flowMirrorPathRepository.remove(stateMachine.getMirrorPathId());
    stateMachine.saveActionToHistory("Flow mirror path resources were deallocated", format("The flow resources for mirror path %s were deallocated", stateMachine.getMirrorPathId()));
    stateMachine.setMirrorPathResourcesDeallocated(true);
}
Also used : PathId(org.openkilda.model.PathId) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowMirrorPath(org.openkilda.model.FlowMirrorPath)

Aggregations

FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)40 Flow (org.openkilda.model.Flow)24 YFlow (org.openkilda.model.YFlow)20 YSubFlow (org.openkilda.model.YSubFlow)11 SwitchId (org.openkilda.model.SwitchId)7 CommandContext (org.openkilda.wfm.CommandContext)7 FlowEndpoint (org.openkilda.model.FlowEndpoint)6 PathId (org.openkilda.model.PathId)6 RequestedFlow (org.openkilda.wfm.topology.flowhs.model.RequestedFlow)6 InvalidFlowException (org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException)6 UnavailableFlowEndpointException (org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException)6 ArrayList (java.util.ArrayList)5 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)5 Switch (org.openkilda.model.Switch)5 SubFlowDto (org.openkilda.messaging.command.yflow.SubFlowDto)4 SubFlowSharedEndpointEncapsulation (org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation)4 FlowMirrorPath (org.openkilda.model.FlowMirrorPath)4 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)4 FlowPath (org.openkilda.model.FlowPath)4 InfoMessage (org.openkilda.messaging.info.InfoMessage)3