Search in sources :

Example 91 with PathId

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

the class AvailableNetworkFactory method getAvailableNetwork.

/**
 * Gets a {@link AvailableNetwork}.
 *
 * @param flow                      the flow, for which {@link AvailableNetwork} is constructing.
 * @param reusePathsResources       reuse resources already allocated by {@param reusePathsResources} paths.
 * @return {@link AvailableNetwork} instance.
 */
public AvailableNetwork getAvailableNetwork(Flow flow, Collection<PathId> reusePathsResources) throws RecoverableException {
    BuildStrategy buildStrategy = BuildStrategy.from(config.getNetworkStrategy());
    AvailableNetwork network = new AvailableNetwork();
    try {
        // Reads all active links from the database and creates representation of the network.
        getAvailableIsls(buildStrategy, flow).forEach(link -> addIslAsEdge(link, network));
        if (!reusePathsResources.isEmpty() && !flow.isIgnoreBandwidth()) {
            reusePathsResources.stream().filter(pathId -> flowPathRepository.findById(pathId).map(path -> !path.isIgnoreBandwidth()).orElse(false)).forEach(pathId -> {
                // ISLs occupied by the flow (take the bandwidth already occupied by the flow into account).
                islRepository.findActiveByPathAndBandwidthAndEncapsulationType(pathId, flow.getBandwidth(), flow.getEncapsulationType()).forEach(link -> addIslAsEdge(link, network));
            });
        }
    } catch (PersistenceException e) {
        throw new RecoverableException("An error from the database", e);
    }
    if (flow.getDiverseGroupId() != null) {
        log.info("Filling AvailableNetwork diverse weights for group with id {}", flow.getDiverseGroupId());
        Collection<PathId> flowPaths = flowPathRepository.findPathIdsByFlowDiverseGroupId(flow.getDiverseGroupId());
        if (!reusePathsResources.isEmpty()) {
            flowPaths = flowPaths.stream().filter(s -> !reusePathsResources.contains(s)).collect(Collectors.toList());
        }
        Collection<PathId> affinityPathIds = flowPathRepository.findPathIdsByFlowAffinityGroupId(flow.getAffinityGroupId());
        flowPaths.forEach(pathId -> flowPathRepository.findById(pathId).filter(flowPath -> !affinityPathIds.contains(flowPath.getPathId()) || flowPath.getFlowId().equals(flow.getFlowId())).ifPresent(flowPath -> {
            network.processDiversitySegments(flowPath.getSegments(), flow);
            network.processDiversitySegmentsWithPop(flowPath.getSegments());
        }));
    }
    // The main flow should not take into account the rest of the flows in this affinity group.
    if (flow.getAffinityGroupId() != null && !flow.getAffinityGroupId().equals(flow.getFlowId())) {
        log.info("Filling AvailableNetwork affinity weights for group with id {}", flow.getAffinityGroupId());
        flowPathRepository.findByFlowId(flow.getAffinityGroupId()).stream().filter(flowPath -> !flowPath.isProtected()).filter(FlowPath::isForward).map(FlowPath::getSegments).forEach(network::processAffinitySegments);
    }
    return network;
}
Also used : IslImmutableView(org.openkilda.persistence.repositories.IslRepository.IslImmutableView) FlowPath(org.openkilda.model.FlowPath) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) Collection(java.util.Collection) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Collectors(java.util.stream.Collectors) RecoverableException(org.openkilda.pce.exception.RecoverableException) ArrayList(java.util.ArrayList) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Edge(org.openkilda.pce.model.Edge) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Flow(org.openkilda.model.Flow) Node(org.openkilda.pce.model.Node) IslRepository(org.openkilda.persistence.repositories.IslRepository) PathId(org.openkilda.model.PathId) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) PathId(org.openkilda.model.PathId) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) FlowPath(org.openkilda.model.FlowPath) RecoverableException(org.openkilda.pce.exception.RecoverableException)

Example 92 with PathId

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

the class LinkOperationsServiceTest method createFlow.

private Flow createFlow(String flowId, SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort) {
    Switch srcSwitch = createSwitchIfNotExist(srcSwitchId);
    Switch dstSwitch = createSwitchIfNotExist(dstSwitchId);
    Flow flow = Flow.builder().flowId(flowId).srcSwitch(srcSwitch).srcPort(srcPort).destSwitch(dstSwitch).destPort(dstPort).status(FlowStatus.UP).build();
    FlowPath forwardPath = FlowPath.builder().pathId(new PathId("forward_path_id")).srcSwitch(srcSwitch).destSwitch(dstSwitch).cookie(new FlowSegmentCookie(1L)).build();
    FlowPath reversePath = FlowPath.builder().pathId(new PathId("reverse_path_id")).srcSwitch(dstSwitch).destSwitch(srcSwitch).cookie(new FlowSegmentCookie(1L)).build();
    forwardPath.setSegments(newArrayList(createPathSegment(forwardPath.getPathId(), srcSwitch, srcPort, dstSwitch, dstPort)));
    reversePath.setSegments(newArrayList(createPathSegment(reversePath.getPathId(), dstSwitch, dstPort, srcSwitch, srcPort)));
    flow.setForwardPath(forwardPath);
    flow.setReversePath(reversePath);
    flowRepository.add(flow);
    return flow;
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Switch(org.openkilda.model.Switch) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Example 93 with PathId

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

the class SwitchOperationsServiceTest method shouldValidateFlowMirrorPathWhenUpdatingServer42PortSwitchProperties.

@Test(expected = IllegalSwitchPropertiesException.class)
public void shouldValidateFlowMirrorPathWhenUpdatingServer42PortSwitchProperties() {
    Switch firstSwitch = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build();
    Switch secondSwitch = Switch.builder().switchId(TEST_SWITCH_ID_2).status(SwitchStatus.ACTIVE).build();
    switchRepository.add(firstSwitch);
    switchRepository.add(secondSwitch);
    FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(new PathId("test_path_id")).mirrorSwitch(secondSwitch).egressSwitch(firstSwitch).egressPort(TEST_FLOW_SRC_PORT).build();
    flowMirrorPathRepository.add(flowMirrorPath);
    createSwitchProperties(firstSwitch, 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.setServer42Port(TEST_FLOW_SRC_PORT);
    switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, update);
}
Also used : PathId(org.openkilda.model.PathId) SwitchPropertiesDto(org.openkilda.messaging.model.SwitchPropertiesDto) Switch(org.openkilda.model.Switch) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 94 with PathId

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

the class SwitchOperationsServiceTest method shouldValidateFlowMirrorPointsWhenUpdatingSwitchArpProperties.

@Test(expected = IllegalSwitchPropertiesException.class)
public void shouldValidateFlowMirrorPointsWhenUpdatingSwitchArpProperties() {
    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.setSwitchArp(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 95 with PathId

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

the class RerouteServiceTest method setup.

@Before
public void setup() throws Throwable {
    doAnswer(invocation -> {
        TransactionCallbackWithoutResult<?> arg = invocation.getArgument(0);
        arg.doInTransaction();
        return null;
    }).when(transactionManager).doInTransaction(Mockito.<TransactionCallbackWithoutResult<?>>any());
    doAnswer(invocation -> {
        TransactionCallback<?, ?> arg = invocation.getArgument(0);
        return arg.doInTransaction();
    }).when(transactionManager).doInTransaction(Mockito.<TransactionCallback<?, ?>>any());
    pinnedFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(true).build();
    FlowPath pinnedFlowForwardPath = FlowPath.builder().pathId(new PathId("1")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1)).build();
    List<PathSegment> pinnedFlowForwardSegments = new ArrayList<>();
    pinnedFlowForwardSegments.add(PathSegment.builder().pathId(pinnedFlowForwardPath.getPathId()).srcSwitch(SWITCH_A).srcPort(1).destSwitch(SWITCH_B).destPort(1).build());
    pinnedFlowForwardSegments.add(PathSegment.builder().pathId(pinnedFlowForwardPath.getPathId()).srcSwitch(SWITCH_B).srcPort(2).destSwitch(SWITCH_C).destPort(1).build());
    pinnedFlowForwardPath.setSegments(pinnedFlowForwardSegments);
    FlowPath pinnedFlowReversePath = FlowPath.builder().pathId(new PathId("2")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 2)).build();
    List<PathSegment> pinnedFlowReverseSegments = new ArrayList<>();
    pinnedFlowReverseSegments.add(PathSegment.builder().pathId(pinnedFlowReversePath.getPathId()).srcSwitch(SWITCH_C).srcPort(1).destSwitch(SWITCH_B).destPort(2).build());
    pinnedFlowReverseSegments.add(PathSegment.builder().pathId(pinnedFlowReversePath.getPathId()).srcSwitch(SWITCH_B).srcPort(1).destSwitch(SWITCH_A).destPort(1).build());
    pinnedFlowReversePath.setSegments(pinnedFlowReverseSegments);
    pinnedFlow.setForwardPath(pinnedFlowForwardPath);
    pinnedFlow.setReversePath(pinnedFlowReversePath);
    regularFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(false).priority(2).build();
    FlowPath regularFlowForwardPath = FlowPath.builder().pathId(new PathId("3")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 3)).status(FlowPathStatus.ACTIVE).build();
    List<PathSegment> unpinnedFlowForwardSegments = new ArrayList<>();
    unpinnedFlowForwardSegments.add(PathSegment.builder().pathId(regularFlowForwardPath.getPathId()).srcSwitch(SWITCH_A).srcPort(1).destSwitch(SWITCH_B).destPort(1).build());
    unpinnedFlowForwardSegments.add(PathSegment.builder().pathId(regularFlowForwardPath.getPathId()).srcSwitch(SWITCH_B).srcPort(2).destSwitch(SWITCH_C).destPort(1).build());
    regularFlowForwardPath.setSegments(unpinnedFlowForwardSegments);
    FlowPath regularFlowReversePath = FlowPath.builder().pathId(new PathId("4")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 3)).status(FlowPathStatus.ACTIVE).build();
    List<PathSegment> unpinnedFlowReverseSegments = new ArrayList<>();
    unpinnedFlowReverseSegments.add(PathSegment.builder().pathId(regularFlowReversePath.getPathId()).srcSwitch(SWITCH_C).srcPort(1).destSwitch(SWITCH_B).destPort(2).build());
    unpinnedFlowReverseSegments.add(PathSegment.builder().pathId(regularFlowReversePath.getPathId()).srcSwitch(SWITCH_B).srcPort(1).destSwitch(SWITCH_A).destPort(1).build());
    regularFlowReversePath.setSegments(unpinnedFlowReverseSegments);
    regularFlow.setForwardPath(regularFlowForwardPath);
    regularFlow.setReversePath(regularFlowReversePath);
    oneSwitchFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).build();
    FlowPath oneSwitchFlowForwardPath = FlowPath.builder().pathId(new PathId("5")).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 4)).status(FlowPathStatus.ACTIVE).build();
    FlowPath oneSwitchFlowReversePath = FlowPath.builder().pathId(new PathId("6")).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 4)).status(FlowPathStatus.ACTIVE).build();
    oneSwitchFlow.setForwardPath(oneSwitchFlowForwardPath);
    oneSwitchFlow.setReversePath(oneSwitchFlowReversePath);
    regularYFlow = YFlow.builder().yFlowId(YFLOW_ID).priority(2).sharedEndpoint(new SharedEndpoint(SWITCH_A.getSwitchId(), 10)).build();
    FlowPath regularYFlowForwardPath = FlowPath.builder().pathId(new PathId("3")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 3)).status(FlowPathStatus.ACTIVE).build();
    regularYFlowForwardPath.setSegments(unpinnedFlowForwardSegments);
    FlowPath regularYFlowReversePath = FlowPath.builder().pathId(new PathId("4")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 3)).status(FlowPathStatus.ACTIVE).build();
    regularYFlowReversePath.setSegments(unpinnedFlowReverseSegments);
    subFlow = Flow.builder().flowId(SUB_YFLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(false).priority(2).yFlowId(YFLOW_ID).yFlow(regularYFlow).build();
    subFlow.setForwardPath(regularYFlowForwardPath);
    subFlow.setReversePath(regularYFlowReversePath);
    Set<YSubFlow> subFlows = Collections.singleton(YSubFlow.builder().yFlow(regularYFlow).flow(subFlow).build());
    regularYFlow.setSubFlows(subFlows);
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) ArrayList(java.util.ArrayList) SharedEndpoint(org.openkilda.model.YFlow.SharedEndpoint) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) YSubFlow(org.openkilda.model.YSubFlow) Before(org.junit.Before)

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