use of org.openkilda.model.KildaConfiguration in project open-kilda by telstra.
the class FermaKildaConfigurationRepository method getOrDefault.
@Override
public KildaConfiguration getOrDefault() {
KildaConfiguration result = new KildaConfiguration(find().orElse(KildaConfiguration.DEFAULTS));
KildaConfiguration.KildaConfigurationCloner.INSTANCE.replaceNullProperties(KildaConfiguration.DEFAULTS, result);
return result;
}
use of org.openkilda.model.KildaConfiguration in project open-kilda by telstra.
the class FlowMapper method map.
/**
* Convert {@link FlowDto} to {@link Flow}.
* If encapsulation type and/or path computation strategy is not provided then values from KildaConfiguration
* will be used.
*/
public Flow map(FlowDto flow, Supplier<KildaConfiguration> kildaConfiguration) {
Switch srcSwitch = Switch.builder().switchId(flow.getSourceSwitch()).build();
Switch destSwitch = Switch.builder().switchId(flow.getDestinationSwitch()).build();
return Flow.builder().flowId(flow.getFlowId()).srcSwitch(srcSwitch).destSwitch(destSwitch).srcPort(flow.getSourcePort()).destPort(flow.getDestinationPort()).srcVlan(flow.getSourceVlan()).destVlan(flow.getDestinationVlan()).status(map(flow.getState())).statusInfo(flow.getStatusInfo()).description(flow.getDescription()).bandwidth(flow.getBandwidth()).ignoreBandwidth(flow.isIgnoreBandwidth()).periodicPings(Boolean.TRUE.equals(flow.getPeriodicPings())).allocateProtectedPath(flow.isAllocateProtectedPath()).encapsulationType(Optional.ofNullable(flow.getEncapsulationType()).map(encapsulationType -> FlowEncapsulationType.valueOf(encapsulationType.name())).orElse(kildaConfiguration.get().getFlowEncapsulationType())).pathComputationStrategy(Optional.ofNullable(flow.getPathComputationStrategy()).map(pathComputationStrategy -> PathComputationStrategy.valueOf(pathComputationStrategy.name())).orElse(kildaConfiguration.get().getPathComputationStrategy())).maxLatency(flow.getMaxLatency()).priority(flow.getPriority()).pinned(flow.isPinned()).detectConnectedDevices(DetectConnectedDevicesMapper.INSTANCE.map(flow.getDetectConnectedDevices())).build();
}
use of org.openkilda.model.KildaConfiguration in project open-kilda by telstra.
the class PathsService method getPaths.
/**
* Get paths.
*/
public List<PathsInfoData> getPaths(SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy, Duration maxLatency, Duration maxLatencyTier2) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException {
if (Objects.equals(srcSwitchId, dstSwitchId)) {
throw new IllegalArgumentException(String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId));
}
if (!switchRepository.exists(srcSwitchId)) {
throw new SwitchNotFoundException(srcSwitchId);
}
if (!switchRepository.exists(dstSwitchId)) {
throw new SwitchNotFoundException(dstSwitchId);
}
KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault();
FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType).orElse(kildaConfiguration.getFlowEncapsulationType());
SwitchProperties srcProperties = switchPropertiesRepository.findBySwitchId(srcSwitchId).orElseThrow(() -> new SwitchPropertiesNotFoundException(srcSwitchId));
if (!srcProperties.getSupportedTransitEncapsulation().contains(flowEncapsulationType)) {
throw new IllegalArgumentException(String.format("Switch %s doesn't support %s encapslation type. Choose " + "one of the supported encapsulation types %s or update switch properties and add needed " + "encapsulation type.", srcSwitchId, flowEncapsulationType, srcProperties.getSupportedTransitEncapsulation()));
}
SwitchProperties dstProperties = switchPropertiesRepository.findBySwitchId(dstSwitchId).orElseThrow(() -> new SwitchPropertiesNotFoundException(dstSwitchId));
if (!dstProperties.getSupportedTransitEncapsulation().contains(flowEncapsulationType)) {
throw new IllegalArgumentException(String.format("Switch %s doesn't support %s encapslation type. Choose " + "one of the supported encapsulation types %s or update switch properties and add needed " + "encapsulation type.", dstSwitchId, requestEncapsulationType, dstProperties.getSupportedTransitEncapsulation()));
}
PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy).orElse(kildaConfiguration.getPathComputationStrategy());
List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy, maxLatency, maxLatencyTier2);
return flowPaths.stream().map(PathMapper.INSTANCE::map).map(path -> PathsInfoData.builder().path(path).build()).collect(Collectors.toList());
}
use of org.openkilda.model.KildaConfiguration in project open-kilda by telstra.
the class FermaKildaConfigurationRepositoryTest method shouldCreateAndUpdateKildaConfiguration.
@Test
public void shouldCreateAndUpdateKildaConfiguration() {
KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault();
assertEquals(KildaConfiguration.DEFAULTS, kildaConfiguration);
KildaConfiguration emptyKildaConfiguration = KildaConfiguration.builder().build();
kildaConfigurationRepository.add(emptyKildaConfiguration);
KildaConfiguration foundKildaConfiguration = kildaConfigurationRepository.getOrDefault();
assertEquals(KildaConfiguration.DEFAULTS.getFlowEncapsulationType(), foundKildaConfiguration.getFlowEncapsulationType());
assertEquals(KildaConfiguration.DEFAULTS.getPathComputationStrategy(), foundKildaConfiguration.getPathComputationStrategy());
kildaConfiguration = kildaConfigurationRepository.find().orElse(null);
kildaConfiguration.setFlowEncapsulationType(FlowEncapsulationType.VXLAN);
kildaConfiguration.setUseMultiTable(false);
kildaConfiguration.setPathComputationStrategy(PathComputationStrategy.LATENCY);
KildaConfiguration updatedKildaConfiguration = kildaConfigurationRepository.find().orElse(null);
assertEquals(kildaConfiguration, updatedKildaConfiguration);
updatedKildaConfiguration.setFlowEncapsulationType(FlowEncapsulationType.TRANSIT_VLAN);
updatedKildaConfiguration.setUseMultiTable(false);
updatedKildaConfiguration.setPathComputationStrategy(PathComputationStrategy.COST);
}
Aggregations