Search in sources :

Example 1 with PathsInfoData

use of org.openkilda.messaging.info.network.PathsInfoData in project open-kilda by telstra.

the class PathsServiceTest method findNPathsByTransitVlanAndTooSmallMaxLatencyEnoughTier2Latency.

@Test
public void findNPathsByTransitVlanAndTooSmallMaxLatencyEnoughTier2Latency() throws SwitchNotFoundException, RecoverableException, UnroutableFlowException {
    Duration maxLatencyTier2 = Duration.ofNanos(MIN_LATENCY * 2 + 1);
    List<PathsInfoData> paths = pathsService.getPaths(SWITCH_ID_1, SWITCH_ID_2, TRANSIT_VLAN, MAX_LATENCY, Duration.ofNanos(1L), maxLatencyTier2);
    assertMaxLatencyPaths(paths, maxLatencyTier2, 1, TRANSIT_VLAN);
}
Also used : PathsInfoData(org.openkilda.messaging.info.network.PathsInfoData) Duration(java.time.Duration) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 2 with PathsInfoData

use of org.openkilda.messaging.info.network.PathsInfoData in project open-kilda by telstra.

the class PathsServiceTest method assertMaxLatencyPaths.

private void assertMaxLatencyPaths(List<PathsInfoData> paths, Duration maxLatency, long expectedCount, FlowEncapsulationType encapsulationType) {
    assertEquals(expectedCount, paths.size());
    assertPathLength(paths);
    for (PathsInfoData path : paths) {
        assertTrue(path.getPath().getLatency().minus(maxLatency).isNegative());
        Optional<SwitchProperties> properties = switchPropertiesRepository.findBySwitchId(path.getPath().getNodes().get(1).getSwitchId());
        assertTrue(properties.isPresent());
        assertTrue(properties.get().getSupportedTransitEncapsulation().contains(encapsulationType));
    }
}
Also used : PathsInfoData(org.openkilda.messaging.info.network.PathsInfoData) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 3 with PathsInfoData

use of org.openkilda.messaging.info.network.PathsInfoData in project open-kilda by telstra.

the class PathsServiceTest method findNPathsByVxlanAndEnoughMaxLatencyZeroTier2Latency.

@Test
public void findNPathsByVxlanAndEnoughMaxLatencyZeroTier2Latency() throws SwitchNotFoundException, RecoverableException, UnroutableFlowException {
    Duration maxLatency = Duration.ofNanos(MIN_LATENCY * 2 + 1);
    List<PathsInfoData> paths = pathsService.getPaths(SWITCH_ID_1, SWITCH_ID_2, VXLAN, MAX_LATENCY, maxLatency, Duration.ZERO);
    assertMaxLatencyPaths(paths, maxLatency, 1, VXLAN);
}
Also used : PathsInfoData(org.openkilda.messaging.info.network.PathsInfoData) Duration(java.time.Duration) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 4 with PathsInfoData

use of org.openkilda.messaging.info.network.PathsInfoData in project open-kilda by telstra.

the class PathsServiceTest method assertPathLength.

private void assertPathLength(List<PathsInfoData> paths) {
    for (PathsInfoData path : paths) {
        assertEquals(3, path.getPath().getNodes().size());
        assertEquals(SWITCH_ID_1, path.getPath().getNodes().get(0).getSwitchId());
        assertEquals(SWITCH_ID_2, path.getPath().getNodes().get(2).getSwitchId());
    }
}
Also used : PathsInfoData(org.openkilda.messaging.info.network.PathsInfoData)

Example 5 with PathsInfoData

use of org.openkilda.messaging.info.network.PathsInfoData 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)

Aggregations

PathsInfoData (org.openkilda.messaging.info.network.PathsInfoData)5 Duration (java.time.Duration)3 Test (org.junit.Test)2 SwitchProperties (org.openkilda.model.SwitchProperties)2 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)2 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)1 KildaConfiguration (org.openkilda.model.KildaConfiguration)1 PathComputationStrategy (org.openkilda.model.PathComputationStrategy)1 SwitchId (org.openkilda.model.SwitchId)1 AvailableNetworkFactory (org.openkilda.pce.AvailableNetworkFactory)1 Path (org.openkilda.pce.Path)1 PathComputer (org.openkilda.pce.PathComputer)1 PathComputerConfig (org.openkilda.pce.PathComputerConfig)1 PathComputerFactory (org.openkilda.pce.PathComputerFactory)1 RecoverableException (org.openkilda.pce.exception.RecoverableException)1