Search in sources :

Example 41 with PathId

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

the class SwitchOperationsServiceTest method shouldValidateFlowMirrorPointsWhenUpdatingSwitchLldpProperties.

@Test(expected = IllegalSwitchPropertiesException.class)
public void shouldValidateFlowMirrorPointsWhenUpdatingSwitchLldpProperties() {
    Switch mirrorSwitch = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build();
    switchRepository.add(mirrorSwitch);
    MirrorGroup mirrorGroup = MirrorGroup.builder().switchId(TEST_SWITCH_ID).groupId(new GroupId(12L)).pathId(new PathId("test_path_id")).flowId(TEST_FLOW_ID_1).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).mirrorDirection(MirrorDirection.INGRESS).build();
    mirrorGroupRepository.add(mirrorGroup);
    FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorGroup(mirrorGroup).mirrorSwitch(mirrorSwitch).build();
    flowMirrorPointsRepository.add(flowMirrorPoints);
    createSwitchProperties(mirrorSwitch, Collections.singleton(FlowEncapsulationType.TRANSIT_VLAN), true, false, false);
    SwitchPropertiesDto update = new SwitchPropertiesDto();
    update.setSupportedTransitEncapsulation(Collections.singleton(org.openkilda.messaging.payload.flow.FlowEncapsulationType.TRANSIT_VLAN));
    update.setMultiTable(true);
    update.setSwitchLldp(true);
    switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, update);
}
Also used : PathId(org.openkilda.model.PathId) SwitchPropertiesDto(org.openkilda.messaging.model.SwitchPropertiesDto) MirrorGroup(org.openkilda.model.MirrorGroup) Switch(org.openkilda.model.Switch) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) GroupId(org.openkilda.model.GroupId) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 42 with PathId

use of org.openkilda.model.PathId 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 43 with PathId

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

the class CommandBuilderImpl method buildGroupInstallContexts.

@Override
public List<GroupInstallContext> buildGroupInstallContexts(SwitchId switchId, List<Integer> groupIds) {
    List<GroupInstallContext> groupInstallContexts = new ArrayList<>();
    Map<PathId, MirrorGroup> mirrorGroups = new HashMap<>();
    groupIds.stream().map(GroupId::new).map(mirrorGroupRepository::findByGroupId).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).forEach(mirrorGroup -> mirrorGroups.put(mirrorGroup.getPathId(), mirrorGroup));
    flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
        if (mirrorGroups.containsKey(flowPath.getPathId())) {
            PathSegment segment = flowPath.getSegments().stream().filter(pathSegment -> pathSegment.getDestSwitchId().equals(switchId)).findAny().orElseThrow(() -> new IllegalStateException(format("PathSegment not found, path %s, switch %s", flowPath, switchId)));
            Flow flow = flowPath.getFlow();
            if (segment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
                MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, flow.getDestSwitchId(), flow.getDestPort());
                groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
                log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
            }
        }
    });
    flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
        if (mirrorGroups.containsKey(flowPath.getPathId())) {
            Flow flow = getFlow(flowPath);
            if (flowPath.isOneSwitchFlow()) {
                SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
                int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
                MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
                groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
                log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
            } else if (flowPath.getSrcSwitchId().equals(switchId)) {
                if (flowPath.getSegments().isEmpty()) {
                    log.warn("Output port was not found for mirror config");
                } else {
                    PathSegment foundIngressSegment = flowPath.getSegments().get(0);
                    MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
                    EncapsulationResources encapsulation = getEncapsulationResources(flowPath, flow);
                    groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).encapsulation(new FlowTransitEncapsulation(encapsulation.getTransitEncapsulationId(), encapsulation.getEncapsulationType())).egressSwitchId(flowPath.getDestSwitchId()).build());
                    log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
                }
            }
        }
    });
    return groupInstallContexts;
}
Also used : ModifyDefaultMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest) MirrorConfig(org.openkilda.model.MirrorConfig) NoArgGenerator(com.fasterxml.uuid.NoArgGenerator) EncapsulationResources(org.openkilda.wfm.share.flow.resources.EncapsulationResources) InstallServer42Flow(org.openkilda.messaging.command.flow.InstallServer42Flow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowPath(org.openkilda.model.FlowPath) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) FlowResourcesConfig(org.openkilda.wfm.share.flow.resources.FlowResourcesConfig) SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE) NumberUtils(org.apache.commons.lang.math.NumberUtils) LogicalPortInfoEntry(org.openkilda.messaging.info.switches.LogicalPortInfoEntry) ReinstallDefaultFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest) Flow(org.openkilda.model.Flow) MirrorGroup(org.openkilda.model.MirrorGroup) Map(java.util.Map) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) ModifyFlowMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyFlowMeterForSwitchManagerRequest) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteLogicalPortRequest(org.openkilda.messaging.command.grpc.DeleteLogicalPortRequest) SwitchProperties(org.openkilda.model.SwitchProperties) IpSocketAddress(org.openkilda.model.IpSocketAddress) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) NonNull(lombok.NonNull) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Set(java.util.Set) CookieType(org.openkilda.model.cookie.CookieBase.CookieType) InstallServer42FlowBuilder(org.openkilda.messaging.command.flow.InstallServer42Flow.InstallServer42FlowBuilder) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) FlowInstructions(org.openkilda.messaging.info.rule.FlowInstructions) Optional(java.util.Optional) FlowCommandFactory(org.openkilda.wfm.share.flow.service.FlowCommandFactory) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) PathSegment(org.openkilda.model.PathSegment) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) CreateLogicalPortRequest(org.openkilda.messaging.command.grpc.CreateLogicalPortRequest) Cookie(org.openkilda.model.cookie.Cookie) LogicalPortMapper(org.openkilda.wfm.topology.switchmanager.mappers.LogicalPortMapper) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) PersistenceManager(org.openkilda.persistence.PersistenceManager) CommandBuilder(org.openkilda.wfm.topology.switchmanager.service.CommandBuilder) PathId(org.openkilda.model.PathId) SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE) SharedSegmentType(org.openkilda.model.cookie.FlowSharedSegmentCookie.SharedSegmentType) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) Switch(org.openkilda.model.Switch) GroupInstallContext(org.openkilda.wfm.topology.switchmanager.model.GroupInstallContext) SERVER_42_ISL_RTT_OUTPUT_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_ISL_RTT_OUTPUT_COOKIE) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) PortColourCookie(org.openkilda.model.cookie.PortColourCookie) FlowSharedSegmentCookie(org.openkilda.model.cookie.FlowSharedSegmentCookie) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) MirrorGroupRepository(org.openkilda.persistence.repositories.MirrorGroupRepository) InstallSharedFlow(org.openkilda.messaging.command.flow.InstallSharedFlow) SwitchId(org.openkilda.model.SwitchId) MirrorConfigData(org.openkilda.model.MirrorConfig.MirrorConfigData) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) Generators(com.fasterxml.uuid.Generators) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FlowMatchField(org.openkilda.messaging.info.rule.FlowMatchField) GroupId(org.openkilda.model.GroupId) Collections(java.util.Collections) MirrorGroup(org.openkilda.model.MirrorGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) InstallServer42Flow(org.openkilda.messaging.command.flow.InstallServer42Flow) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) Flow(org.openkilda.model.Flow) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) InstallSharedFlow(org.openkilda.messaging.command.flow.InstallSharedFlow) PathId(org.openkilda.model.PathId) GroupInstallContext(org.openkilda.wfm.topology.switchmanager.model.GroupInstallContext) EncapsulationResources(org.openkilda.wfm.share.flow.resources.EncapsulationResources) MirrorConfig(org.openkilda.model.MirrorConfig) Stream(java.util.stream.Stream)

Example 44 with PathId

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

the class PersistenceDataAdapterTest method shouldProvideCorrectFlowPaths.

@Test
public void shouldProvideCorrectFlowPaths() {
    PathId pathId = new PathId("path1");
    Set<PathId> pathIds = Sets.newHashSet(pathId);
    FlowPath flowPath = FlowPath.builder().pathId(pathId).srcSwitch(buildSwitch(SWITCH_ID_1, Collections.emptySet())).destSwitch(buildSwitch(SWITCH_ID_2, Collections.emptySet())).build();
    Map<PathId, FlowPath> flowPaths = new HashMap<>();
    flowPaths.put(pathId, flowPath);
    when(flowPathRepository.findByIds(pathIds)).thenReturn(flowPaths);
    adapter = PersistenceDataAdapter.builder().pathIds(pathIds).persistenceManager(persistenceManager).build();
    Map<PathId, FlowPath> actual = adapter.getFlowPaths();
    assertEquals(1, actual.size());
    assertEquals(flowPath, actual.get(pathId));
    adapter.getFlowPaths();
    verify(flowPathRepository).findByIds(pathIds);
    verifyNoMoreInteractions(flowPathRepository);
}
Also used : PathId(org.openkilda.model.PathId) HashMap(java.util.HashMap) FlowPath(org.openkilda.model.FlowPath) Test(org.junit.Test)

Example 45 with PathId

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

the class RuleManagerImpl method buildRulesForFlowPath.

@Override
public List<SpeakerData> buildRulesForFlowPath(FlowPath flowPath, boolean filterOutUsedSharedRules, DataAdapter adapter) {
    List<SpeakerData> result = new ArrayList<>();
    Flow flow = adapter.getFlow(flowPath.getPathId());
    PathId oppositePathId = flow.getOppositePathId(flowPath.getPathId()).orElse(null);
    FlowTransitEncapsulation encapsulation = adapter.getTransitEncapsulation(flowPath.getPathId(), oppositePathId);
    if (!flow.isProtectedPath(flowPath.getPathId())) {
        Set<FlowSideAdapter> overlappingAdapters = new HashSet<>();
        if (filterOutUsedSharedRules) {
            overlappingAdapters = getOverlappingMultiTableIngressAdapters(flowPath, adapter);
        }
        buildIngressCommands(adapter.getSwitch(flowPath.getSrcSwitchId()), flowPath, flow, encapsulation, overlappingAdapters, adapter.getSwitchProperties(flowPath.getSrcSwitchId()), adapter.getFeatureToggles());
    }
    if (flowPath.isOneSwitchFlow()) {
        return result;
    }
    result.addAll(buildEgressCommands(adapter.getSwitch(flowPath.getDestSwitchId()), flowPath, flow, encapsulation));
    for (int i = 1; i < flowPath.getSegments().size(); i++) {
        PathSegment firstSegment = flowPath.getSegments().get(i - 1);
        PathSegment secondSegment = flowPath.getSegments().get(i);
        result.addAll(buildTransitCommands(adapter.getSwitch(firstSegment.getDestSwitchId()), flowPath, encapsulation, firstSegment, secondSegment));
    }
    if (flow.isLooped()) {
        Switch loopedSwitch = adapter.getSwitch(flow.getLoopSwitchId());
        result.addAll(buildTransitLoopCommands(loopedSwitch, flowPath, flow, encapsulation));
    }
    return postProcessCommands(result);
}
Also used : PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) ArrayList(java.util.ArrayList) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) PathSegment(org.openkilda.model.PathSegment) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) HashSet(java.util.HashSet)

Aggregations

PathId (org.openkilda.model.PathId)124 Flow (org.openkilda.model.Flow)65 FlowPath (org.openkilda.model.FlowPath)65 Test (org.junit.Test)44 Switch (org.openkilda.model.Switch)29 SwitchId (org.openkilda.model.SwitchId)28 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)27 PathSegment (org.openkilda.model.PathSegment)26 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)21 MeterId (org.openkilda.model.MeterId)19 ArrayList (java.util.ArrayList)18 List (java.util.List)13 Slf4j (lombok.extern.slf4j.Slf4j)11 GetPathsResult (org.openkilda.pce.GetPathsResult)11 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)10 Path (org.openkilda.pce.Path)10 Collection (java.util.Collection)9 RecoverableException (org.openkilda.pce.exception.RecoverableException)9 String.format (java.lang.String.format)8 HashMap (java.util.HashMap)8