Search in sources :

Example 16 with FlowMirrorPath

use of org.openkilda.model.FlowMirrorPath 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 17 with FlowMirrorPath

use of org.openkilda.model.FlowMirrorPath 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 18 with FlowMirrorPath

use of org.openkilda.model.FlowMirrorPath 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

FlowMirrorPath (org.openkilda.model.FlowMirrorPath)18 Flow (org.openkilda.model.Flow)6 PathId (org.openkilda.model.PathId)6 Test (org.junit.Test)5 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)5 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)5 Switch (org.openkilda.model.Switch)4 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)3 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)3 ArrayList (java.util.ArrayList)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 FlowMirrorPointResponse (org.openkilda.messaging.info.flow.FlowMirrorPointResponse)2 FlowPath (org.openkilda.model.FlowPath)2 PhysicalPort (org.openkilda.model.PhysicalPort)2 SwitchProperties (org.openkilda.model.SwitchProperties)2 Sets (com.google.common.collect.Sets)1 SetView (com.google.common.collect.Sets.SetView)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1