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;
}
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();
}
Aggregations