Search in sources :

Example 6 with FlowPath

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

the class RemoveRulesAction method buildResources.

private FlowResources buildResources(Flow flow, FlowPath path, FlowPath oppositePath) {
    FlowPath forwardPath;
    FlowPath reversePath;
    if (path.isForward()) {
        forwardPath = path;
        reversePath = oppositePath;
    } else {
        forwardPath = oppositePath;
        reversePath = path;
    }
    EncapsulationResources encapsulationResources;
    if (!flow.isOneSwitchFlow()) {
        encapsulationResources = resourcesManager.getEncapsulationResources(forwardPath.getPathId(), reversePath.getPathId(), flow.getEncapsulationType()).orElse(null);
    } else {
        encapsulationResources = null;
    }
    return FlowResources.builder().unmaskedCookie(forwardPath.getCookie().getFlowEffectiveId()).forward(PathResources.builder().pathId(forwardPath.getPathId()).meterId(forwardPath.getMeterId()).encapsulationResources(encapsulationResources).build()).reverse(PathResources.builder().pathId(reversePath.getPathId()).meterId(reversePath.getMeterId()).encapsulationResources(encapsulationResources).build()).build();
}
Also used : EncapsulationResources(org.openkilda.wfm.share.flow.resources.EncapsulationResources) FlowPath(org.openkilda.model.FlowPath)

Example 7 with FlowPath

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

the class RemoveRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
    Flow flow = getFlow(stateMachine.getFlowId());
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    Collection<FlowSegmentRequestFactory> commands = new ArrayList<>();
    Set<PathId> protectedPaths = Stream.of(flow.getProtectedForwardPathId(), flow.getProtectedReversePathId()).filter(Objects::nonNull).collect(Collectors.toSet());
    Set<PathId> processed = new HashSet<>();
    MirrorContext mirrorContext = MirrorContext.builder().removeFlowOperation(true).build();
    for (FlowPath path : flow.getPaths()) {
        PathId pathId = path.getPathId();
        if (processed.add(pathId)) {
            FlowPath oppositePath = flow.getOppositePathId(pathId).filter(oppPathId -> !pathId.equals(oppPathId)).flatMap(flow::getPath).orElse(null);
            if (oppositePath != null) {
                processed.add(oppositePath.getPathId());
            }
            if (oppositePath != null) {
                stateMachine.getFlowResources().add(buildResources(flow, path, oppositePath));
                if (protectedPaths.contains(pathId)) {
                    commands.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), flow, path, oppositePath, mirrorContext));
                } else {
                    SpeakerRequestBuildContext speakerRequestBuildContext = SpeakerRequestBuildContext.builder().forward(buildPathContext(flow, path)).reverse(buildPathContext(flow, oppositePath)).deleteOperation(true).build();
                    commands.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), flow, path, oppositePath, speakerRequestBuildContext, mirrorContext));
                }
            } else {
                log.warn("No opposite path found for {}, trying to delete as unpaired path", pathId);
                stateMachine.getFlowResources().add(buildResources(flow, path, path));
                if (protectedPaths.contains(pathId)) {
                    commands.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), flow, path, null, mirrorContext));
                } else {
                    SpeakerRequestBuildContext speakerRequestBuildContext = SpeakerRequestBuildContext.builder().forward(buildPathContext(flow, path)).reverse(PathContext.builder().build()).deleteOperation(true).build();
                    commands.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), flow, path, null, speakerRequestBuildContext, mirrorContext));
                }
            }
        }
    }
    stateMachine.clearPendingAndRetriedCommands();
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove rules");
        stateMachine.fire(Event.RULES_REMOVED);
    } else {
        SpeakerRemoveSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getRemoveCommands());
        stateMachine.getPendingCommands().addAll(stateMachine.getRemoveCommands().keySet());
        stateMachine.saveActionToHistory("Remove commands for rules have been sent");
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) MirrorContext(org.openkilda.wfm.share.model.MirrorContext) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowPath(org.openkilda.model.FlowPath) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext) Flow(org.openkilda.model.Flow) HashSet(java.util.HashSet)

Example 8 with FlowPath

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

the class EmitUpdateRulesRequestsAction method buildCommands.

private Collection<FlowSegmentRequestFactory> buildCommands(FlowMirrorPointCreateFsm stateMachine, Flow flow) {
    final FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    PathId flowPathId = stateMachine.getFlowPathId();
    FlowPath path = flow.getPath(flowPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow path %s not found", flowPathId)));
    PathId oppositePathId = flow.getOppositePathId(flowPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Opposite flow path id for path %s not found", flowPathId)));
    FlowPath oppositePath = flow.getPath(oppositePathId).orElse(null);
    RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
    CommandContext context = stateMachine.getCommandContext();
    SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(path.getSrcSwitchId(), path.getDestSwitchId());
    if (mirrorPoint.getMirrorPointSwitchId().equals(path.getSrcSwitchId())) {
        return new ArrayList<>(commandBuilder.buildIngressOnlyOneDirection(context, flow, path, oppositePath, speakerContext.getForward(), MirrorContext.builder().buildMirrorFactoryOnly(true).addNewGroup(stateMachine.isAddNewGroup()).build()));
    } else if (mirrorPoint.getMirrorPointSwitchId().equals(path.getDestSwitchId())) {
        return new ArrayList<>(commandBuilder.buildEgressOnlyOneDirection(context, flow, path, oppositePath, MirrorContext.builder().buildMirrorFactoryOnly(true).addNewGroup(stateMachine.isAddNewGroup()).build()));
    }
    return Collections.emptyList();
}
Also used : PathId(org.openkilda.model.PathId) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowPath(org.openkilda.model.FlowPath) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext)

Example 9 with FlowPath

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

the class EmitCommandRequestsAction method buildCommands.

private Collection<FlowSegmentRequestFactory> buildCommands(FlowCommandBuilder commandBuilder, FlowMirrorPointDeleteFsm stateMachine, Flow flow, FlowMirrorPoints mirrorPoints) {
    FlowPath path = mirrorPoints.getFlowPath();
    FlowPath oppositePath = path.isForward() ? flow.getReversePath() : flow.getForwardPath();
    CommandContext context = stateMachine.getCommandContext();
    SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(path.getSrcSwitchId(), path.getDestSwitchId());
    if (mirrorPoints.getMirrorSwitchId().equals(path.getSrcSwitchId())) {
        return new ArrayList<>(commandBuilder.buildIngressOnlyOneDirection(context, flow, path, oppositePath, speakerContext.getForward(), MirrorContext.builder().buildMirrorFactoryOnly(true).build()));
    } else if (mirrorPoints.getMirrorSwitchId().equals(path.getDestSwitchId())) {
        return new ArrayList<>(commandBuilder.buildEgressOnlyOneDirection(context, flow, path, oppositePath, MirrorContext.builder().buildMirrorFactoryOnly(true).build()));
    }
    return Collections.emptyList();
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) ArrayList(java.util.ArrayList) FlowPath(org.openkilda.model.FlowPath) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext)

Example 10 with FlowPath

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

the class RemoveOldRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
    Flow flow = getFlow(stateMachine.getFlowId());
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    FlowPath oldPrimaryForward = flow.getProtectedForwardPath();
    FlowPath oldPrimaryReverse = flow.getProtectedReversePath();
    SpeakerRequestBuildContext speakerContext = buildSpeakerContextForRemovalIngressOnly(flow.getSrcSwitchId(), flow.getDestSwitchId());
    Collection<FlowSegmentRequestFactory> commands = new ArrayList<>(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, oldPrimaryForward, oldPrimaryReverse, speakerContext, MirrorContext.builder().removeFlowOperation(true).build()));
    commands.addAll(commandBuilder.buildEgressOnly(stateMachine.getCommandContext(), flow, oldPrimaryForward, oldPrimaryReverse, MirrorContext.builder().buildMirrorFactoryOnly(true).removeFlowOperation(true).build()));
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    SpeakerRemoveSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getRemoveCommands());
    stateMachine.getRemoveCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
    stateMachine.saveActionToHistory("Remove commands for old rules have been sent");
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowPath(org.openkilda.model.FlowPath) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext) Flow(org.openkilda.model.Flow)

Aggregations

FlowPath (org.openkilda.model.FlowPath)229 Flow (org.openkilda.model.Flow)128 Test (org.junit.Test)108 PathId (org.openkilda.model.PathId)65 PathSegment (org.openkilda.model.PathSegment)42 SwitchId (org.openkilda.model.SwitchId)40 ArrayList (java.util.ArrayList)39 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)33 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)29 Switch (org.openkilda.model.Switch)28 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)27 SpeakerData (org.openkilda.rulemanager.SpeakerData)27 Action (org.openkilda.rulemanager.action.Action)26 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)26 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)26 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)26 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)26 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)26 MeterId (org.openkilda.model.MeterId)20 YFlow (org.openkilda.model.YFlow)19