Search in sources :

Example 41 with Isl

use of org.openkilda.model.Isl 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));
    }
}
Also used : TransactionManager(org.openkilda.persistence.tx.TransactionManager) SwitchFeature(org.openkilda.model.SwitchFeature) LRUMap(org.apache.commons.collections4.map.LRUMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) Flow(org.openkilda.model.Flow) PoolManager(org.openkilda.wfm.share.utils.PoolManager) IslRepository(org.openkilda.persistence.repositories.IslRepository) Map(java.util.Map) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) LagLogicalPort(org.openkilda.model.LagLogicalPort) LagPortNotFoundException(org.openkilda.wfm.topology.switchmanager.error.LagPortNotFoundException) PathId(org.openkilda.model.PathId) SwitchProperties(org.openkilda.model.SwitchProperties) IpSocketAddress(org.openkilda.model.IpSocketAddress) Switch(org.openkilda.model.Switch) PhysicalPortRepository(org.openkilda.persistence.repositories.PhysicalPortRepository) InconsistentDataException(org.openkilda.wfm.topology.switchmanager.error.InconsistentDataException) NonNull(lombok.NonNull) Collection(java.util.Collection) SetView(com.google.common.collect.Sets.SetView) Set(java.util.Set) RetryPolicy(net.jodah.failsafe.RetryPolicy) BFD(org.openkilda.model.SwitchFeature.BFD) FlowMirrorPathRepository(org.openkilda.persistence.repositories.FlowMirrorPathRepository) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) 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) LagLogicalPortRepository(org.openkilda.persistence.repositories.LagLogicalPortRepository) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) Optional(java.util.Optional) ConstraintViolationException(org.openkilda.persistence.exceptions.ConstraintViolationException) Isl(org.openkilda.model.Isl) PhysicalPort(org.openkilda.model.PhysicalPort) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) Isl(org.openkilda.model.Isl) HashMap(java.util.HashMap) InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) ArrayList(java.util.ArrayList) List(java.util.List) SwitchProperties(org.openkilda.model.SwitchProperties) FlowMirrorPath(org.openkilda.model.FlowMirrorPath)

Example 42 with Isl

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

the class IslMapperTest method islMapperTest.

@Test
public void islMapperTest() {
    IslInfoData islInfoData = IslInfoData.builder().latency(1L).source(new PathNode(TEST_SWITCH_A_ID, 1, 0)).destination(new PathNode(TEST_SWITCH_B_ID, 1, 1)).speed(2L).state(IslChangeType.DISCOVERED).actualState(IslChangeType.MOVED).roundTripStatus(IslChangeType.FAILED).cost(700).availableBandwidth(4L).underMaintenance(false).build();
    Isl isl = IslMapper.INSTANCE.map(islInfoData);
    Assert.assertEquals(IslStatus.ACTIVE, isl.getStatus());
    IslInfoData islInfoDataMapping = IslMapper.INSTANCE.map(isl);
    Assert.assertEquals(islInfoData, islInfoDataMapping);
}
Also used : Isl(org.openkilda.model.Isl) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 43 with Isl

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

the class IslMapper method map.

/**
 * Convert {@link IslInfoData} to {@link org.openkilda.model.Isl}.
 */
public org.openkilda.model.Isl map(IslInfoData islInfoData) {
    if (islInfoData == null) {
        return null;
    }
    Isl.IslBuilder isl = Isl.builder();
    PathNode sourcePathNode = islInfoData.getSource();
    if (sourcePathNode != null) {
        isl.srcSwitch(Switch.builder().switchId(sourcePathNode.getSwitchId()).build()).srcPort(sourcePathNode.getPortNo());
    }
    PathNode destinationPathNode = islInfoData.getDestination();
    if (destinationPathNode != null) {
        isl.destSwitch(Switch.builder().switchId(destinationPathNode.getSwitchId()).build()).destPort(destinationPathNode.getPortNo());
    }
    isl.latency((int) islInfoData.getLatency()).speed(islInfoData.getSpeed()).availableBandwidth(islInfoData.getAvailableBandwidth()).status(map(islInfoData.getState())).actualStatus(map(islInfoData.getActualState())).roundTripStatus(map(islInfoData.getRoundTripStatus())).cost(islInfoData.getCost()).underMaintenance(islInfoData.isUnderMaintenance()).bfdSessionStatus(map(islInfoData.getBfdSessionStatus()));
    return isl.build();
}
Also used : Isl(org.openkilda.model.Isl) PathNode(org.openkilda.messaging.info.event.PathNode)

Example 44 with Isl

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

the class CacheServiceTest method updateIslStatus.

private void updateIslStatus(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort, IslStatus status) {
    Isl isl = islRepository.findByEndpoints(srcSwitchId, srcPort, dstSwitchId, dstPort).get();
    isl.setStatus(status);
}
Also used : Isl(org.openkilda.model.Isl)

Example 45 with Isl

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

the class CacheServiceTest method createIsl.

private void createIsl(Switch srcSwitch, int srcPort, Switch dstSwitch, int dstPort, long latency, IslStatus status) {
    Isl isl = Isl.builder().srcSwitch(srcSwitch).srcPort(srcPort).destSwitch(dstSwitch).destPort(dstPort).status(status).latency(latency).build();
    islRepository.add(isl);
}
Also used : Isl(org.openkilda.model.Isl)

Aggregations

Isl (org.openkilda.model.Isl)83 Test (org.junit.Test)49 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)25 Endpoint (org.openkilda.wfm.share.model.Endpoint)18 Switch (org.openkilda.model.Switch)17 IslReference (org.openkilda.wfm.share.model.IslReference)11 SwitchId (org.openkilda.model.SwitchId)10 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)9 IslDataHolder (org.openkilda.wfm.topology.network.model.IslDataHolder)8 ArrayList (java.util.ArrayList)6 PathId (org.openkilda.model.PathId)6 Flow (org.openkilda.model.Flow)5 IslRepository (org.openkilda.persistence.repositories.IslRepository)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 FlowPath (org.openkilda.model.FlowPath)4 PersistenceException (org.openkilda.persistence.exceptions.PersistenceException)4 IslFrame (org.openkilda.persistence.ferma.frames.IslFrame)4