Search in sources :

Example 6 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class ValidateRequestAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    RequestedFlowMirrorPoint mirrorPoint = context.getMirrorPoint();
    PathId mirrorPathId = new PathId(mirrorPoint.getMirrorPointId());
    stateMachine.setMirrorPathId(mirrorPathId);
    stateMachine.setMirrorSwitchId(mirrorPoint.getMirrorPointSwitchId());
    dashboardLogger.onFlowMirrorPointCreate(flowId, mirrorPoint.getMirrorPointSwitchId(), mirrorPoint.getMirrorPointDirection().toString(), mirrorPoint.getSinkEndpoint().getSwitchId(), mirrorPoint.getSinkEndpoint().getPortNumber(), mirrorPoint.getSinkEndpoint().getOuterVlanId());
    stateMachine.setRequestedFlowMirrorPoint(mirrorPoint);
    Flow flow = transactionManager.doInTransaction(() -> {
        Flow foundFlow = getFlow(flowId);
        if (foundFlow.getStatus() == FlowStatus.IN_PROGRESS) {
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow %s is in progress now", flowId));
        }
        stateMachine.setFlowStatus(foundFlow.getStatus());
        flowRepository.updateStatus(flowId, FlowStatus.IN_PROGRESS);
        return foundFlow;
    });
    if (!mirrorPoint.getMirrorPointSwitchId().equals(mirrorPoint.getSinkEndpoint().getSwitchId())) {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid sink endpoint switch id: %s. In the current implementation, " + "the sink switch id cannot differ from the mirror point switch id.", mirrorPoint.getSinkEndpoint().getSwitchId()));
    }
    if (!mirrorPoint.getMirrorPointSwitchId().equals(flow.getSrcSwitchId()) && !mirrorPoint.getMirrorPointSwitchId().equals(flow.getDestSwitchId())) {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid mirror point switch id: %s", mirrorPoint.getMirrorPointSwitchId()));
    }
    if (flowMirrorPathRepository.exists(mirrorPathId)) {
        throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Flow mirror point %s already exists", mirrorPathId));
    }
    Optional<PhysicalPort> physicalPort = physicalPortRepository.findBySwitchIdAndPortNumber(mirrorPoint.getSinkEndpoint().getSwitchId(), mirrorPoint.getSinkEndpoint().getPortNumber());
    if (physicalPort.isPresent()) {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid sink port %d on switch %s. This port is part of LAG %d. Please delete LAG port " + "or choose another sink port.", mirrorPoint.getSinkEndpoint().getPortNumber(), mirrorPoint.getSinkEndpoint().getSwitchId(), physicalPort.get().getLagLogicalPort().getLogicalPortNumber()));
    }
    try {
        flowValidator.flowMirrorPointValidate(mirrorPoint);
    } catch (InvalidFlowException e) {
        throw new FlowProcessingException(e.getType(), e.getMessage(), e);
    } catch (UnavailableFlowEndpointException e) {
        throw new FlowProcessingException(ErrorType.DATA_INVALID, e.getMessage(), e);
    }
    stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.FLOW_MIRROR_POINT_CREATE);
    return Optional.empty();
}
Also used : PathId(org.openkilda.model.PathId) UnavailableFlowEndpointException(org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) PhysicalPort(org.openkilda.model.PhysicalPort) InvalidFlowException(org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException) Flow(org.openkilda.model.Flow)

Example 7 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class CompleteFlowPathInstallationAction method perform.

@TimedExecution("fsm.complete_flow_path_install")
@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    if (stateMachine.getNewPrimaryForwardPath() != null && stateMachine.getNewPrimaryReversePath() != null) {
        PathId newForward = stateMachine.getNewPrimaryForwardPath();
        PathId newReverse = stateMachine.getNewPrimaryReversePath();
        log.debug("Completing installation of the flow primary path {} / {}", newForward, newReverse);
        FlowPathStatus primaryPathStatus;
        if (stateMachine.isIgnoreBandwidth() || stateMachine.isBackUpPrimaryPathComputationWayUsed()) {
            primaryPathStatus = FlowPathStatus.DEGRADED;
        } else {
            primaryPathStatus = FlowPathStatus.ACTIVE;
        }
        transactionManager.doInTransaction(() -> {
            flowPathRepository.updateStatus(newForward, primaryPathStatus);
            flowPathRepository.updateStatus(newReverse, primaryPathStatus);
        });
        stateMachine.saveActionToHistory("Flow paths were installed", format("The flow paths %s / %s were installed", newForward, newReverse));
    }
    if (stateMachine.getNewProtectedForwardPath() != null && stateMachine.getNewProtectedReversePath() != null) {
        PathId newForward = stateMachine.getNewProtectedForwardPath();
        PathId newReverse = stateMachine.getNewProtectedReversePath();
        FlowPathStatus protectedPathStatus;
        if (stateMachine.isIgnoreBandwidth() || stateMachine.isBackUpProtectedPathComputationWayUsed()) {
            protectedPathStatus = FlowPathStatus.DEGRADED;
        } else {
            protectedPathStatus = FlowPathStatus.ACTIVE;
        }
        log.debug("Completing installation of the flow protected path {} / {}", newForward, newReverse);
        transactionManager.doInTransaction(() -> {
            flowPathRepository.updateStatus(newForward, protectedPathStatus);
            flowPathRepository.updateStatus(newReverse, protectedPathStatus);
        });
        stateMachine.saveActionToHistory("Flow paths were installed", format("The flow paths %s / %s were installed", newForward, newReverse));
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowPathStatus(org.openkilda.model.FlowPathStatus) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Example 8 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class PostFlowMirrorPathDeallocationAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
    PathId flowPathId = stateMachine.getFlowPathId();
    SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
    boolean mirrorPointsWereDeallocated = transactionManager.doInTransaction(() -> {
        FlowMirrorPoints flowMirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElse(null);
        if (flowMirrorPoints != null && flowMirrorPoints.getMirrorPaths().isEmpty()) {
            flowMirrorPointsRepository.remove(flowMirrorPoints);
            resourcesManager.deallocateMirrorGroup(flowPathId, mirrorSwitchId);
            return true;
        }
        return false;
    });
    if (mirrorPointsWereDeallocated) {
        stateMachine.saveActionToHistory("Flow mirror group was deallocated", format("The flow mirror group for flow path %s and switch id %s was deallocated", flowPathId, mirrorSwitchId));
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SwitchId(org.openkilda.model.SwitchId)

Example 9 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class ValidateRequestAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    PathId mirrorPathId = new PathId(context.getFlowMirrorPointId());
    stateMachine.setMirrorPathId(mirrorPathId);
    dashboardLogger.onFlowMirrorPointDelete(flowId, context.getFlowMirrorPointId());
    FlowMirrorPointResponse response = transactionManager.doInTransaction(() -> {
        Flow foundFlow = getFlow(flowId);
        if (foundFlow.getStatus() == FlowStatus.IN_PROGRESS) {
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow %s is in progress now", flowId));
        }
        stateMachine.setFlowStatus(foundFlow.getStatus());
        flowRepository.updateStatus(flowId, FlowStatus.IN_PROGRESS);
        FlowMirrorPath flowMirrorPath = flowMirrorPathRepository.findById(mirrorPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror point %s not found", mirrorPathId)));
        if (flowMirrorPath.getStatus() == FlowPathStatus.IN_PROGRESS) {
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow mirror point %s is in progress now", mirrorPathId));
        }
        stateMachine.setOriginalFlowMirrorPathStatus(flowMirrorPath.getStatus());
        flowMirrorPathRepository.updateStatus(mirrorPathId, FlowPathStatus.IN_PROGRESS);
        String direction = flowMirrorPath.getFlowMirrorPoints().getFlowPath().isForward() ? "forward" : "reverse";
        return FlowMirrorPointResponse.builder().flowId(foundFlow.getFlowId()).mirrorPointId(flowMirrorPath.getPathId().getId()).mirrorPointDirection(direction).mirrorPointSwitchId(flowMirrorPath.getMirrorSwitchId()).sinkEndpoint(FlowEndpoint.builder().switchId(flowMirrorPath.getEgressSwitchId()).portNumber(flowMirrorPath.getEgressPort()).innerVlanId(flowMirrorPath.getEgressInnerVlan()).outerVlanId(flowMirrorPath.getEgressOuterVlan()).build()).build();
    });
    stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.FLOW_MIRROR_POINT_DELETE);
    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 10 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class PostFlowMirrorPathDeallocationAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
    PathId flowPathId = transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(mirrorPoint.getFlowId());
        FlowPath flowPath = getFlowPath(mirrorPoint, flow);
        FlowMirrorPoints flowMirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPath.getPathId(), mirrorPoint.getMirrorPointSwitchId()).orElse(null);
        if (flowMirrorPoints != null && flowMirrorPoints.getMirrorPaths().isEmpty()) {
            flowMirrorPointsRepository.remove(flowMirrorPoints);
            resourcesManager.deallocateMirrorGroup(flowPath.getPathId(), mirrorPoint.getMirrorPointSwitchId());
            return flowPath.getPathId();
        }
        return null;
    });
    if (flowPathId != null) {
        stateMachine.saveActionToHistory("Flow mirror group was deallocated", format("The flow mirror group for flow path %s and switch id %s was deallocated", flowPathId, mirrorPoint.getMirrorPointSwitchId()));
    }
}
Also used : PathId(org.openkilda.model.PathId) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Aggregations

PathId (org.openkilda.model.PathId)124 Flow (org.openkilda.model.Flow)65 FlowPath (org.openkilda.model.FlowPath)65 Test (org.junit.Test)44 Switch (org.openkilda.model.Switch)29 SwitchId (org.openkilda.model.SwitchId)28 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)27 PathSegment (org.openkilda.model.PathSegment)26 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)21 MeterId (org.openkilda.model.MeterId)19 ArrayList (java.util.ArrayList)18 List (java.util.List)13 Slf4j (lombok.extern.slf4j.Slf4j)11 GetPathsResult (org.openkilda.pce.GetPathsResult)11 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)10 Path (org.openkilda.pce.Path)10 Collection (java.util.Collection)9 RecoverableException (org.openkilda.pce.exception.RecoverableException)9 String.format (java.lang.String.format)8 HashMap (java.util.HashMap)8