Search in sources :

Example 1 with BaseFlow

use of org.openkilda.messaging.command.flow.BaseFlow in project open-kilda by telstra.

the class CommandBuilderImpl method buildCommandsToSyncMissingRules.

@Override
public List<BaseFlow> buildCommandsToSyncMissingRules(SwitchId switchId, List<Long> switchRules) {
    List<BaseFlow> commands = new ArrayList<>(buildInstallDefaultRuleCommands(switchId, switchRules));
    commands.addAll(buildInstallFlowSharedRuleCommands(switchId, switchRules));
    flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
        FlowSegmentCookie mirrorCookie = flowPath.getCookie().toBuilder().mirror(true).build();
        boolean switchRulesContainsFlowPathCookie = switchRules.contains(flowPath.getCookie().getValue());
        boolean switchRulesContainsMirrorCookie = switchRules.contains(mirrorCookie.getValue());
        if (switchRulesContainsFlowPathCookie || switchRulesContainsMirrorCookie) {
            PathSegment segment = flowPath.getSegments().stream().filter(pathSegment -> pathSegment.getDestSwitchId().equals(switchId)).findAny().orElseThrow(() -> new IllegalStateException(format("PathSegment not found, path %s, switch %s", flowPath, switchId)));
            log.info("Rule {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
            commands.addAll(buildInstallCommandFromSegment(flowPath, segment, switchRulesContainsFlowPathCookie, switchRulesContainsMirrorCookie));
        }
    });
    SwitchProperties switchProperties = getSwitchProperties(switchId);
    flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
        FlowSegmentCookie mirrorCookie = flowPath.getCookie().toBuilder().mirror(true).build();
        boolean switchRulesContainsFlowPathCookie = switchRules.contains(flowPath.getCookie().getValue());
        boolean switchRulesContainsMirrorCookie = switchRules.contains(mirrorCookie.getValue());
        if (switchRulesContainsFlowPathCookie || switchRulesContainsMirrorCookie) {
            Flow flow = getFlow(flowPath);
            if (flowPath.isOneSwitchFlow()) {
                log.info("One-switch flow {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
                SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
                int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
                if (switchRulesContainsMirrorCookie) {
                    MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
                    commands.add(flowCommandFactory.makeOneSwitchMirrorRule(flow, flowPath, mirrorConfig));
                }
                if (switchRulesContainsFlowPathCookie) {
                    commands.add(flowCommandFactory.makeOneSwitchRule(flow, flowPath));
                }
            } else if (flowPath.getSrcSwitchId().equals(switchId)) {
                log.info("Ingress flow {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
                if (flowPath.getSegments().isEmpty()) {
                    log.warn("Output port was not found for ingress flow rule");
                } else {
                    PathSegment foundIngressSegment = flowPath.getSegments().get(0);
                    EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
                    if (switchRulesContainsMirrorCookie) {
                        MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
                        commands.add(flowCommandFactory.buildInstallIngressMirrorFlow(flow, flowPath, foundIngressSegment.getSrcPort(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable(), mirrorConfig));
                    }
                    if (switchRulesContainsFlowPathCookie) {
                        commands.add(flowCommandFactory.buildInstallIngressFlow(flow, flowPath, foundIngressSegment.getSrcPort(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable()));
                    }
                }
            }
        }
        long server42Cookie = flowPath.getCookie().toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build().getValue();
        if (switchRules.contains(server42Cookie) && !flowPath.isOneSwitchFlow() && flowPath.getSrcSwitchId().equals(switchId)) {
            log.info("Ingress server 42 flow {} is to be (re)installed on switch {}", server42Cookie, switchId);
            if (flowPath.getSegments().isEmpty()) {
                log.warn("Output port was not found for server 42 ingress flow rule {}", server42Cookie);
            } else {
                Flow flow = getFlow(flowPath);
                PathSegment foundIngressSegment = flowPath.getSegments().get(0);
                EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
                commands.add(flowCommandFactory.buildInstallServer42IngressFlow(flow, flowPath, foundIngressSegment.getSrcPort(), switchProperties.getServer42Port(), switchProperties.getServer42MacAddress(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable()));
            }
        }
        long loopCookie = flowPath.getCookie().toBuilder().looped(true).build().getValue();
        if (switchRules.contains(loopCookie)) {
            log.info("Loop rule with cookie {} is to be reinstalled on switch {}", loopCookie, switchId);
            Flow flow = getFlow(flowPath);
            EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
            if (flowPath.getSrcSwitch().getSwitchId().equals(switchId)) {
                boolean srcWithMultiTable = flowPath.getSegments().get(0).isSrcWithMultiTable();
                commands.add(flowCommandFactory.buildInstallIngressLoopFlow(flow, flowPath, encapsulationResources, srcWithMultiTable));
            } else {
                PathSegment lastSegment = flowPath.getSegments().get(flowPath.getSegments().size() - 1);
                boolean destWithMultiTable = lastSegment.isDestWithMultiTable();
                commands.add(flowCommandFactory.buildInstallTransitLoopFlow(flow, flowPath, lastSegment.getDestPort(), encapsulationResources, destWithMultiTable));
            }
        }
    });
    return commands;
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) InstallServer42Flow(org.openkilda.messaging.command.flow.InstallServer42Flow) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) Flow(org.openkilda.model.Flow) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) InstallSharedFlow(org.openkilda.messaging.command.flow.InstallSharedFlow) EncapsulationResources(org.openkilda.wfm.share.flow.resources.EncapsulationResources) MirrorConfig(org.openkilda.model.MirrorConfig) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 2 with BaseFlow

use of org.openkilda.messaging.command.flow.BaseFlow in project open-kilda by telstra.

the class SwitchSyncFsm method sendRulesCommands.

protected void sendRulesCommands(SwitchSyncState from, SwitchSyncState to, SwitchSyncEvent event, Object context) {
    if (missingRules.isEmpty() && excessRules.isEmpty() && misconfiguredRules.isEmpty()) {
        log.info("Nothing to do with rules (switch={}, key={})", switchId, key);
        fire(NEXT);
        return;
    }
    if (!missingRules.isEmpty()) {
        log.info("Request to install switch rules has been sent (switch={}, key={})", switchId, key);
        missingRulesPendingResponsesCount = missingRules.size();
        for (BaseFlow command : missingRules) {
            carrier.sendCommandToSpeaker(key, new InstallFlowForSwitchManagerRequest(command));
        }
    }
    if (!excessRules.isEmpty()) {
        log.info("Request to remove switch rules has been sent (switch={}, key={})", switchId, key);
        excessRulesPendingResponsesCount = excessRules.size();
        for (RemoveFlow command : excessRules) {
            carrier.sendCommandToSpeaker(key, new RemoveFlowForSwitchManagerRequest(switchId, command));
        }
    }
    if (!misconfiguredRules.isEmpty()) {
        log.info("Request to reinstall default switch rules has been sent (switch={}, key={})", switchId, key);
        reinstallDefaultRulesPendingResponsesCount = misconfiguredRules.size();
        for (ReinstallDefaultFlowForSwitchManagerRequest command : misconfiguredRules) {
            carrier.sendCommandToSpeaker(key, command);
        }
    }
    continueIfRulesSynchronized();
}
Also used : RemoveFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.RemoveFlowForSwitchManagerRequest) ReinstallDefaultFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) InstallFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.InstallFlowForSwitchManagerRequest)

Aggregations

BaseFlow (org.openkilda.messaging.command.flow.BaseFlow)2 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)2 ArrayList (java.util.ArrayList)1 BaseInstallFlow (org.openkilda.messaging.command.flow.BaseInstallFlow)1 InstallFlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.InstallFlowForSwitchManagerRequest)1 InstallServer42Flow (org.openkilda.messaging.command.flow.InstallServer42Flow)1 InstallSharedFlow (org.openkilda.messaging.command.flow.InstallSharedFlow)1 ReinstallDefaultFlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest)1 RemoveFlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.RemoveFlowForSwitchManagerRequest)1 Flow (org.openkilda.model.Flow)1 MirrorConfig (org.openkilda.model.MirrorConfig)1 PathSegment (org.openkilda.model.PathSegment)1 SwitchId (org.openkilda.model.SwitchId)1 SwitchProperties (org.openkilda.model.SwitchProperties)1 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)1 EncapsulationResources (org.openkilda.wfm.share.flow.resources.EncapsulationResources)1