Search in sources :

Example 1 with KildaConfiguration

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;
}
Also used : KildaConfiguration(org.openkilda.model.KildaConfiguration)

Example 2 with KildaConfiguration

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();
}
Also used : FlowStatusDetails(org.openkilda.messaging.payload.flow.FlowStatusDetails) FlowStats(org.openkilda.model.FlowStats) Mapping(org.mapstruct.Mapping) FlowPath(org.openkilda.model.FlowPath) FlowStatus(org.openkilda.model.FlowStatus) Supplier(java.util.function.Supplier) FlowPathStatus(org.openkilda.model.FlowPathStatus) Flow(org.openkilda.model.Flow) Mapper(org.mapstruct.Mapper) SwapFlowDto(org.openkilda.messaging.model.SwapFlowDto) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Mappers(org.mapstruct.factory.Mappers) PathId(org.openkilda.model.PathId) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) Switch(org.openkilda.model.Switch) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) KildaConfiguration(org.openkilda.model.KildaConfiguration) Set(java.util.Set) FlowDto(org.openkilda.messaging.model.FlowDto) UUID(java.util.UUID) Instant(java.time.Instant) MeterId(org.openkilda.model.MeterId) List(java.util.List) FlowPairDto(org.openkilda.messaging.model.FlowPairDto) MirrorPointStatusDto(org.openkilda.messaging.model.MirrorPointStatusDto) SwitchId(org.openkilda.model.SwitchId) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) FlowState(org.openkilda.messaging.payload.flow.FlowState) Switch(org.openkilda.model.Switch)

Example 3 with KildaConfiguration

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());
}
Also used : Path(org.openkilda.pce.Path) KildaConfigurationRepository(org.openkilda.persistence.repositories.KildaConfigurationRepository) PathsInfoData(org.openkilda.messaging.info.network.PathsInfoData) RecoverableException(org.openkilda.pce.exception.RecoverableException) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) AvailableNetworkFactory(org.openkilda.pce.AvailableNetworkFactory) Duration(java.time.Duration) PathComputerConfig(org.openkilda.pce.PathComputerConfig) Path(org.openkilda.pce.Path) SwitchProperties(org.openkilda.model.SwitchProperties) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) KildaConfiguration(org.openkilda.model.KildaConfiguration) Collectors(java.util.stream.Collectors) PathComputerFactory(org.openkilda.pce.PathComputerFactory) Objects(java.util.Objects) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) SwitchPropertiesNotFoundException(org.openkilda.wfm.error.SwitchPropertiesNotFoundException) PathComputer(org.openkilda.pce.PathComputer) Optional(java.util.Optional) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) PathMapper(org.openkilda.wfm.share.mappers.PathMapper) SwitchPropertiesNotFoundException(org.openkilda.wfm.error.SwitchPropertiesNotFoundException) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) SwitchProperties(org.openkilda.model.SwitchProperties) KildaConfiguration(org.openkilda.model.KildaConfiguration)

Example 4 with KildaConfiguration

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);
}
Also used : KildaConfiguration(org.openkilda.model.KildaConfiguration) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Aggregations

KildaConfiguration (org.openkilda.model.KildaConfiguration)4 List (java.util.List)2 Optional (java.util.Optional)2 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)2 PathComputationStrategy (org.openkilda.model.PathComputationStrategy)2 SwitchId (org.openkilda.model.SwitchId)2 Duration (java.time.Duration)1 Instant (java.time.Instant)1 Objects (java.util.Objects)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Test (org.junit.Test)1 Mapper (org.mapstruct.Mapper)1 Mapping (org.mapstruct.Mapping)1 Mappers (org.mapstruct.factory.Mappers)1 PathsInfoData (org.openkilda.messaging.info.network.PathsInfoData)1 FlowDto (org.openkilda.messaging.model.FlowDto)1