Search in sources :

Example 1 with FlowSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory 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 2 with FlowSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.

the class EmitUpdateRulesRequestsAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    stateMachine.getCommands().clear();
    stateMachine.getPendingCommands().clear();
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    Collection<FlowSegmentRequestFactory> commands = buildCommands(stateMachine, flow);
    // emitting
    PathId flowPathId = stateMachine.getFlowPathId();
    SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
    FlowMirrorPoints mirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElse(null);
    SpeakerRequestEmitter requestEmitter;
    if (mirrorPoints != null && 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 update rules");
    } else {
        stateMachine.saveActionToHistory("Commands for updating rules have been sent");
        stateMachine.setRulesInstalled(true);
    }
}
Also used : PathId(org.openkilda.model.PathId) SpeakerRequestEmitter(org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow)

Example 3 with FlowSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.

the class RevertNewRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    Collection<FlowSegmentRequestFactory> installCommands = new ArrayList<>();
    // Reinstall old ingress rules that may be overridden by new ingress.
    SpeakerRequestBuildContext installContext = buildBaseSpeakerContextForInstall(flow.getSrcSwitchId(), flow.getDestSwitchId());
    installCommands.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, flow.getForwardPath(), flow.getReversePath(), installContext));
    installCommands.addAll(commandBuilder.buildEgressOnly(stateMachine.getCommandContext(), flow, flow.getForwardPath(), flow.getReversePath(), MirrorContext.builder().buildMirrorFactoryOnly(true).build()));
    // need to clean previous requests
    stateMachine.getIngressCommands().clear();
    SpeakerInstallSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), installCommands, stateMachine.getIngressCommands());
    stateMachine.getIngressCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
    // Remove possible installed segments
    Collection<FlowSegmentRequestFactory> removeCommands = new ArrayList<>();
    SpeakerRequestBuildContext removeContext = buildSpeakerContextForRemovalIngressOnly(flow.getSrcSwitchId(), flow.getDestSwitchId());
    removeCommands.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath(), removeContext, MirrorContext.builder().removeFlowOperation(true).build()));
    removeCommands.addAll(commandBuilder.buildEgressOnlyOneDirection(stateMachine.getCommandContext(), flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath(), MirrorContext.builder().buildMirrorFactoryOnly(true).removeFlowOperation(true).build()));
    stateMachine.getRemoveCommands().clear();
    SpeakerRemoveSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), removeCommands, stateMachine.getRemoveCommands());
    stateMachine.getRemoveCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
    stateMachine.saveActionToHistory("Commands for removing new rules and re-installing original ingress rule 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) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext) Flow(org.openkilda.model.Flow)

Example 4 with FlowSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory 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)

Example 5 with FlowSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.

the class InstallRulesAction method emitInstallRequests.

protected void emitInstallRequests(FlowCreateFsm stateMachine, List<FlowSegmentRequestFactory> factories) {
    Map<UUID, SpeakerCommandObserver> pendingRequests = stateMachine.getPendingCommands();
    List<FlowSegmentRequestFactory> sentCommands = stateMachine.getSentCommands();
    for (FlowSegmentRequestFactory factory : factories) {
        FlowSegmentRequest request = factory.makeInstallRequest(commandIdGenerator.generate());
        SpeakerCommandObserver commandObserver = new SpeakerCommandObserver(speakerCommandFsmBuilder, request);
        commandObserver.start();
        sentCommands.add(factory);
        // TODO ensure no conflicts
        pendingRequests.put(request.getCommandId(), commandObserver);
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerCommandObserver(org.openkilda.wfm.topology.flowhs.service.SpeakerCommandObserver) UUID(java.util.UUID)

Aggregations

FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)53 UUID (java.util.UUID)33 Flow (org.openkilda.model.Flow)21 ArrayList (java.util.ArrayList)19 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)15 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)14 FlowCommandBuilder (org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder)14 FlowPath (org.openkilda.model.FlowPath)12 IngressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory)11 SpeakerRequestBuildContext (org.openkilda.wfm.share.model.SpeakerRequestBuildContext)11 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)9 EgressMirrorFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressMirrorFlowSegmentRequestFactory)7 EgressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressFlowSegmentRequestFactory)6 IngressMirrorFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressMirrorFlowSegmentRequestFactory)6 TransitFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.TransitFlowSegmentRequestFactory)6 Switch (org.openkilda.model.Switch)5 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)5 MirrorContext (org.openkilda.wfm.share.model.MirrorContext)5 Test (org.junit.Test)4 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)4