Search in sources :

Example 31 with SwitchProperties

use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.

the class SwitchOperationsService method updateSwitchProperties.

/**
 * Update switch properties.
 *
 * @param switchId            target switch id
 * @param switchPropertiesDto switch properties
 * @throws IllegalSwitchPropertiesException  if switch properties are incorrect
 * @throws SwitchPropertiesNotFoundException if switch properties is not found by switch id
 */
public SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto) {
    if (isEmpty(switchPropertiesDto.getSupportedTransitEncapsulation())) {
        throw new IllegalSwitchPropertiesException("Supported transit encapsulations should not be null or empty");
    }
    SwitchProperties update = SwitchPropertiesMapper.INSTANCE.map(switchPropertiesDto);
    UpdateSwitchPropertiesResult result = transactionManager.doInTransaction(() -> {
        SwitchProperties switchProperties = switchPropertiesRepository.findBySwitchId(switchId).orElseThrow(() -> new SwitchPropertiesNotFoundException(switchId));
        final SwitchProperties oldProperties = new SwitchProperties(switchProperties);
        validateSwitchProperties(switchId, update);
        // must be called before updating of switchProperties object
        final boolean isSwitchSyncNeeded = isSwitchSyncNeeded(switchProperties, update);
        switchProperties.setMultiTable(update.isMultiTable());
        switchProperties.setSwitchLldp(update.isSwitchLldp());
        switchProperties.setSwitchArp(update.isSwitchArp());
        switchProperties.setSupportedTransitEncapsulation(update.getSupportedTransitEncapsulation());
        switchProperties.setServer42FlowRtt(update.isServer42FlowRtt());
        switchProperties.setServer42IslRtt(update.getServer42IslRtt());
        switchProperties.setServer42Port(update.getServer42Port());
        switchProperties.setServer42Vlan(update.getServer42Vlan());
        switchProperties.setServer42MacAddress(update.getServer42MacAddress());
        log.info("Updating {} switch properties from {} to {}. Is switch sync needed: {}", switchId, oldProperties, switchProperties, isSwitchSyncNeeded);
        return new UpdateSwitchPropertiesResult(SwitchPropertiesMapper.INSTANCE.map(switchProperties), isSwitchSyncNeeded);
    });
    if (result.isSwitchSyncRequired()) {
        carrier.requestSwitchSync(switchId);
    }
    if (switchPropertiesDto.isServer42FlowRtt()) {
        carrier.enableServer42FlowRttOnSwitch(switchId);
    } else {
        carrier.disableServer42FlowRttOnSwitch(switchId);
    }
    if (switchPropertiesDto.getServer42IslRtt() != SwitchPropertiesDto.RttState.DISABLED) {
        carrier.enableServer42IslRttOnSwitch(switchId);
    } else {
        carrier.disableServer42IslRttOnSwitch(switchId);
    }
    return result.switchPropertiesDto;
}
Also used : SwitchPropertiesNotFoundException(org.openkilda.wfm.error.SwitchPropertiesNotFoundException) IllegalSwitchPropertiesException(org.openkilda.wfm.error.IllegalSwitchPropertiesException) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 32 with SwitchProperties

use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.

the class SwitchOperationsServiceTest method createServer42SwitchProperties.

private void createServer42SwitchProperties(Switch sw, boolean sever42FlowRtt, Integer port, Integer vlan, MacAddress macAddress) {
    SwitchProperties switchProperties = SwitchProperties.builder().switchObj(sw).supportedTransitEncapsulation(Collections.singleton(FlowEncapsulationType.TRANSIT_VLAN)).multiTable(true).server42FlowRtt(sever42FlowRtt).server42Port(port).server42Vlan(vlan).server42MacAddress(macAddress).build();
    switchPropertiesRepository.add(switchProperties);
}
Also used : SwitchProperties(org.openkilda.model.SwitchProperties)

Example 33 with SwitchProperties

use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.

the class SwitchOperationsServiceTest method shouldUpdateServer42FlowRttSwitchProperties.

@Test
public void shouldUpdateServer42FlowRttSwitchProperties() {
    Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).features(Collections.singleton(SwitchFeature.MULTI_TABLE)).build();
    switchRepository.add(sw);
    createServer42SwitchProperties(sw, false, SERVER_42_PORT_1, SERVER_42_VLAN_1, SERVER_42_MAC_ADDRESS_1);
    SwitchPropertiesDto update = new SwitchPropertiesDto();
    update.setSupportedTransitEncapsulation(Collections.singleton(org.openkilda.messaging.payload.flow.FlowEncapsulationType.TRANSIT_VLAN));
    update.setMultiTable(true);
    update.setServer42FlowRtt(true);
    update.setServer42Port(SERVER_42_PORT_2);
    update.setServer42Vlan(SERVER_42_VLAN_2);
    update.setServer42MacAddress(SERVER_42_MAC_ADDRESS_2);
    switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, update);
    Optional<SwitchProperties> updated = switchPropertiesRepository.findBySwitchId(TEST_SWITCH_ID);
    assertTrue(updated.isPresent());
    assertTrue(updated.get().isServer42FlowRtt());
    assertEquals(SERVER_42_PORT_2, updated.get().getServer42Port());
    assertEquals(SERVER_42_VLAN_2, updated.get().getServer42Vlan());
    assertEquals(SERVER_42_MAC_ADDRESS_2, updated.get().getServer42MacAddress());
}
Also used : SwitchPropertiesDto(org.openkilda.messaging.model.SwitchPropertiesDto) Switch(org.openkilda.model.Switch) SwitchProperties(org.openkilda.model.SwitchProperties) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 34 with SwitchProperties

use of org.openkilda.model.SwitchProperties in project open-kilda by telstra.

the class SwitchOperationsServiceTest method shouldUpdateServer42IslRttSwitchProperties.

@Test
public void shouldUpdateServer42IslRttSwitchProperties() {
    Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).features(Collections.singleton(SwitchFeature.MULTI_TABLE)).build();
    switchRepository.add(sw);
    SwitchProperties switchProperties = SwitchProperties.builder().switchObj(sw).supportedTransitEncapsulation(Collections.singleton(FlowEncapsulationType.TRANSIT_VLAN)).multiTable(false).server42IslRtt(SwitchProperties.RttState.DISABLED).server42Port(SERVER_42_PORT_1).server42Vlan(SERVER_42_VLAN_1).server42MacAddress(SERVER_42_MAC_ADDRESS_1).build();
    switchPropertiesRepository.add(switchProperties);
    SwitchPropertiesDto update = new SwitchPropertiesDto();
    update.setSupportedTransitEncapsulation(Collections.singleton(org.openkilda.messaging.payload.flow.FlowEncapsulationType.TRANSIT_VLAN));
    update.setServer42IslRtt(RttState.ENABLED);
    update.setServer42Port(SERVER_42_PORT_2);
    update.setServer42Vlan(SERVER_42_VLAN_2);
    update.setServer42MacAddress(SERVER_42_MAC_ADDRESS_2);
    switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, update);
    Optional<SwitchProperties> updated = switchPropertiesRepository.findBySwitchId(TEST_SWITCH_ID);
    assertTrue(updated.isPresent());
    assertEquals(SwitchProperties.RttState.ENABLED, updated.get().getServer42IslRtt());
    assertEquals(SERVER_42_PORT_2, updated.get().getServer42Port());
    assertEquals(SERVER_42_VLAN_2, updated.get().getServer42Vlan());
    assertEquals(SERVER_42_MAC_ADDRESS_2, updated.get().getServer42MacAddress());
}
Also used : SwitchPropertiesDto(org.openkilda.messaging.model.SwitchPropertiesDto) Switch(org.openkilda.model.Switch) SwitchProperties(org.openkilda.model.SwitchProperties) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 35 with SwitchProperties

use of org.openkilda.model.SwitchProperties 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

SwitchProperties (org.openkilda.model.SwitchProperties)45 Switch (org.openkilda.model.Switch)19 SwitchId (org.openkilda.model.SwitchId)19 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 List (java.util.List)8 Set (java.util.Set)7 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)7 KildaFeatureToggles (org.openkilda.model.KildaFeatureToggles)6 Utils.buildSwitch (org.openkilda.rulemanager.Utils.buildSwitch)6 Utils.buildSwitchProperties (org.openkilda.rulemanager.Utils.buildSwitchProperties)6 Sets (com.google.common.collect.Sets)5 Map (java.util.Map)5 Before (org.junit.Before)5 Collections (java.util.Collections)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 Mockito.mock (org.mockito.Mockito.mock)4