use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class FlowPathBuilder method buildPathSegments.
/**
* Build a path segments using provided path.
*
* @param pathId a pathId the segments will be associated with.
* @param pathForSegments path to be used for the segments.
* @param bandwidth bandwidth to be used for the segments.
* @param ignoreBandwidth ignore bandwidth be used for the segments.
* @param sharedBandwidthGroupId a shared bandwidth group to be set for the segments
*/
public List<PathSegment> buildPathSegments(PathId pathId, Path pathForSegments, long bandwidth, boolean ignoreBandwidth, String sharedBandwidthGroupId) {
Map<SwitchId, SwitchProperties> switchProperties = getSwitchProperties(pathId);
List<PathSegment> result = new ArrayList<>();
for (int i = 0; i < pathForSegments.getSegments().size(); i++) {
Path.Segment segment = pathForSegments.getSegments().get(i);
SwitchProperties srcSwitchProperties = switchProperties.get(segment.getSrcSwitchId());
SwitchProperties dstSwitchProperties = switchProperties.get(segment.getDestSwitchId());
result.add(PathSegment.builder().seqId(i).pathId(pathId).srcSwitch(Switch.builder().switchId(segment.getSrcSwitchId()).build()).srcPort(segment.getSrcPort()).srcWithMultiTable(srcSwitchProperties.isMultiTable()).destSwitch(Switch.builder().switchId(segment.getDestSwitchId()).build()).destPort(segment.getDestPort()).destWithMultiTable(dstSwitchProperties.isMultiTable()).latency(segment.getLatency()).bandwidth(bandwidth).ignoreBandwidth(ignoreBandwidth).sharedBandwidthGroupId(sharedBandwidthGroupId).build());
}
return result;
}
use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class FlowProcessingWithHistorySupportAction method buildBasePathContextForInstall.
private PathContext buildBasePathContextForInstall(SwitchId switchId) {
SwitchProperties switchProperties = getSwitchProperties(switchId);
boolean serverFlowRtt = switchProperties.isServer42FlowRtt() && isServer42FlowRttFeatureToggle();
return PathContext.builder().installServer42OuterVlanMatchSharedRule(serverFlowRtt && switchProperties.isMultiTable()).installServer42InputRule(serverFlowRtt && switchProperties.isMultiTable()).installServer42IngressRule(serverFlowRtt).server42Port(switchProperties.getServer42Port()).server42MacAddress(switchProperties.getServer42MacAddress()).build();
}
use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class SwitchFsm method persistSwitchProperties.
private void persistSwitchProperties(Switch sw) {
boolean multiTable = kildaConfigurationRepository.getOrDefault().getUseMultiTable() && sw.getFeatures().contains(SwitchFeature.MULTI_TABLE);
Optional<SwitchProperties> switchPropertiesResult = switchPropertiesRepository.findBySwitchId(sw.getSwitchId());
if (!switchPropertiesResult.isPresent()) {
SwitchProperties switchProperties = SwitchProperties.builder().switchObj(sw).supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES).multiTable(multiTable).build();
switchPropertiesRepository.add(switchProperties);
}
}
use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.
the class LagPortOperationService method validatePhysicalPort.
private void validatePhysicalPort(SwitchId switchId, Set<SwitchFeature> features, Integer portNumber) throws InvalidDataException {
if (portNumber == null || portNumber <= 0) {
throw new InvalidDataException(format("Invalid physical port number %s. It can't be null or negative.", portNumber));
}
int bfdPortOffset = config.getBfdPortOffset();
int bfdPortMaxNumber = config.getBfdPortMaxNumber();
if (features.contains(BFD) && portNumber >= bfdPortOffset && portNumber <= bfdPortMaxNumber) {
throw new InvalidDataException(format("Physical port number %d intersects with BFD port range [%d, %d]", portNumber, bfdPortOffset, bfdPortMaxNumber));
}
long lagPortOffset = config.getPoolConfig().getIdMinimum();
if (portNumber >= lagPortOffset) {
throw new InvalidDataException(format("Physical port number %d can't be greater than LAG port offset %d.", portNumber, lagPortOffset));
}
Collection<Isl> isls = islRepository.findByEndpoint(switchId, portNumber);
if (!isls.isEmpty()) {
throw new InvalidDataException(format("Physical port number %d intersects with existing ISLs %s.", portNumber, isls));
}
Optional<SwitchProperties> properties = switchPropertiesRepository.findBySwitchId(switchId);
if (properties.isPresent() && Objects.equals(properties.get().getServer42Port(), portNumber)) {
throw new InvalidDataException(format("Physical port number %d on switch %s is server42 port.", portNumber, switchId));
}
Set<String> flowIds = flowRepository.findByEndpoint(switchId, portNumber).stream().map(Flow::getFlowId).collect(Collectors.toSet());
if (!flowIds.isEmpty()) {
throw new InvalidDataException(format("Physical port %d already used by following flows: %s. You must " + "remove these flows to be able to use the port in LAG.", portNumber, flowIds));
}
Collection<FlowMirrorPath> mirrorPaths = flowMirrorPathRepository.findByEgressSwitchIdAndPort(switchId, portNumber);
if (!mirrorPaths.isEmpty()) {
Map<String, List<PathId>> mirrorPathByFLowIdMap = new HashMap<>();
for (FlowMirrorPath path : mirrorPaths) {
String flowId = path.getFlowMirrorPoints().getFlowPath().getFlowId();
mirrorPathByFLowIdMap.computeIfAbsent(flowId, ignore -> new ArrayList<>());
mirrorPathByFLowIdMap.get(flowId).add(path.getPathId());
}
String message = mirrorPathByFLowIdMap.entrySet().stream().map(entry -> format("flow '%s': %s", entry.getKey(), entry.getValue())).collect(Collectors.joining(", "));
throw new InvalidDataException(format("Physical port %d already used as sink by following mirror points %s", portNumber, message));
}
}
use of org.openkilda.model.SwitchProperties 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;
}
Aggregations