Search in sources :

Example 31 with FlowPath

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

the class InMemoryPathComputer method convertFlowPathsToSwitchLists.

@VisibleForTesting
List<LinkedList<SwitchId>> convertFlowPathsToSwitchLists(SwitchId sharedSwitchId, FlowPath... flowPaths) {
    List<LinkedList<SwitchId>> paths = new ArrayList<>();
    for (FlowPath flowPath : flowPaths) {
        List<PathSegment> pathSegments = flowPath.getSegments();
        if (pathSegments == null || pathSegments.isEmpty()) {
            throw new IllegalArgumentException(format("The path '%s' has no path segments", flowPath.getPathId()));
        }
        LinkedList<SwitchId> path = new LinkedList<>();
        path.add(pathSegments.get(0).getSrcSwitchId());
        for (PathSegment pathSegment : pathSegments) {
            path.add(pathSegment.getDestSwitchId());
        }
        if (sharedSwitchId.equals(path.getLast())) {
            Collections.reverse(path);
        } else if (!sharedSwitchId.equals(path.getFirst())) {
            throw new IllegalArgumentException(format("Shared switch '%s' is not an endpoint switch for path '%s'", sharedSwitchId, flowPath.getPathId()));
        }
        paths.add(path);
    }
    return paths;
}
Also used : ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) LinkedList(java.util.LinkedList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 32 with FlowPath

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

the class AvailableNetworkFactoryTest method shouldBuildAvailableNetworkForFlowWithIgnoreBandwidthPaths.

@Test
public void shouldBuildAvailableNetworkForFlowWithIgnoreBandwidthPaths() throws Exception {
    Flow flow = getFlow(false);
    IslImmutableView isl = getIslView(flow);
    PathId pathId = new PathId("flow-path-id");
    FlowPath flowPath = FlowPath.builder().pathId(pathId).srcSwitch(flow.getSrcSwitch()).destSwitch(flow.getDestSwitch()).ignoreBandwidth(true).build();
    when(config.getNetworkStrategy()).thenReturn("SYMMETRIC_COST");
    when(islRepository.findSymmetricActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(Collections.singletonList(isl));
    when(flowPathRepository.findById(pathId)).thenReturn(Optional.of(flowPath));
    AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.singletonList(pathId));
    assertAvailableNetworkIsCorrect(isl, availableNetwork);
}
Also used : IslImmutableView(org.openkilda.persistence.repositories.IslRepository.IslImmutableView) PathId(org.openkilda.model.PathId) FlowPath(org.openkilda.model.FlowPath) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 33 with FlowPath

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

the class AvailableNetworkFactoryTest method shouldIncreaseDiversityGroupUseCounter.

@Test
public void shouldIncreaseDiversityGroupUseCounter() throws RecoverableException {
    // Topology:
    // A----B----C     Already created flow: B-D
    // |          Requested flow: A-B-C
    // D
    // there is no ISL B-D because we assume that is has no enough bandwidth
    List<IslImmutableView> isls = new ArrayList<>();
    isls.addAll(getBidirectionalIsls(switchA, 1, switchB, 2));
    isls.addAll(getBidirectionalIsls(switchB, 3, switchC, 4));
    FlowPath forwardPath = FlowPath.builder().srcSwitch(switchB).destSwitch(switchD).pathId(FORWARD_PATH_ID).segments(Collections.singletonList(PathSegment.builder().pathId(FORWARD_PATH_ID).srcSwitch(switchB).srcPort(SRC_PORT).destSwitch(switchD).destPort(DEST_PORT).build())).build();
    when(flowPathRepository.findById(FORWARD_PATH_ID)).thenReturn(java.util.Optional.of(forwardPath));
    FlowPath reversePath = FlowPath.builder().srcSwitch(switchD).destSwitch(switchB).pathId(REVERSE_PATH_ID).segments(Collections.singletonList(PathSegment.builder().pathId(REVERSE_PATH_ID).srcSwitch(switchD).srcPort(DEST_PORT).destSwitch(switchB).destPort(SRC_PORT).build())).build();
    when(flowPathRepository.findById(REVERSE_PATH_ID)).thenReturn(java.util.Optional.of(reversePath));
    Flow flow = getFlow(false);
    flow.setSrcSwitch(switchA);
    flow.setDestSwitch(switchC);
    flow.setDiverseGroupId(DIVERSE_GROUP_ID);
    flow.setForwardPathId(new PathId("forward_path_id"));
    flow.setReversePathId(new PathId("reverse_path_id"));
    when(config.getNetworkStrategy()).thenReturn(BuildStrategy.COST.name());
    when(islRepository.findActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(isls);
    when(flowPathRepository.findPathIdsByFlowDiverseGroupId(DIVERSE_GROUP_ID)).thenReturn(Lists.newArrayList(FORWARD_PATH_ID, REVERSE_PATH_ID));
    AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
    assertEquals(2, availableNetwork.getSwitch(switchB.getSwitchId()).getDiversityGroupUseCounter());
}
Also used : IslImmutableView(org.openkilda.persistence.repositories.IslRepository.IslImmutableView) PathId(org.openkilda.model.PathId) ArrayList(java.util.ArrayList) FlowPath(org.openkilda.model.FlowPath) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 34 with FlowPath

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

the class LatencyPathComputationStrategyBaseTest method shouldFindTheSameDiversePath.

@Test
public void shouldFindTheSameDiversePath() throws RecoverableException, UnroutableFlowException {
    createDiamondWithDiversity();
    Flow flow = Flow.builder().flowId("new-flow").diverseGroupId("diverse").bandwidth(10).srcSwitch(getSwitchById("00:0A")).srcPort(10).destSwitch(getSwitchById("00:0D")).destPort(10).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).pathComputationStrategy(PathComputationStrategy.LATENCY).build();
    PathComputer pathComputer = pathComputerFactory.getPathComputer();
    GetPathsResult diversePath = pathComputer.getPath(flow);
    FlowPath forwardPath = FlowPath.builder().pathId(new PathId(UUID.randomUUID().toString())).srcSwitch(flow.getSrcSwitch()).destSwitch(flow.getDestSwitch()).bandwidth(flow.getBandwidth()).build();
    addPathSegments(forwardPath, diversePath.getForward());
    flow.setForwardPath(forwardPath);
    FlowPath reversePath = FlowPath.builder().pathId(new PathId(UUID.randomUUID().toString())).srcSwitch(flow.getDestSwitch()).destSwitch(flow.getSrcSwitch()).bandwidth(flow.getBandwidth()).build();
    addPathSegments(reversePath, diversePath.getReverse());
    flow.setReversePath(reversePath);
    flowRepository.add(flow);
    GetPathsResult path2 = pathComputer.getPath(flow, flow.getPathIds());
    assertEquals(diversePath, path2);
}
Also used : PathId(org.openkilda.model.PathId) PathComputer(org.openkilda.pce.PathComputer) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) Test(org.junit.Test)

Example 35 with FlowPath

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

the class AvailableNetworkTest method buildPathWithSegment.

private PathSegment buildPathWithSegment(SwitchId srcDpid, SwitchId dstDpid, int srcPort, int dstPort, String srcPop, String dstPop, int seqId) {
    Switch srcSwitch = Switch.builder().switchId(srcDpid).pop(srcPop).build();
    Switch dstSwitch = Switch.builder().switchId(dstDpid).pop(dstPop).build();
    PathId pathId = new PathId(UUID.randomUUID().toString());
    FlowPath flowPath = FlowPath.builder().pathId(pathId).srcSwitch(srcSwitch).destSwitch(dstSwitch).segments(IntStream.rangeClosed(0, seqId).mapToObj(i -> PathSegment.builder().pathId(pathId).srcSwitch(srcSwitch).destSwitch(dstSwitch).srcPort(srcPort).destPort(dstPort).build()).collect(toList())).build();
    return flowPath.getSegments().get(seqId);
}
Also used : PathId(org.openkilda.model.PathId) IntStream(java.util.stream.IntStream) PathWeight(org.openkilda.pce.model.PathWeight) Switch(org.openkilda.model.Switch) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) Matchers(org.hamcrest.Matchers) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) Collections.singletonList(java.util.Collections.singletonList) WeightFunction(org.openkilda.pce.model.WeightFunction) Assert.assertThat(org.junit.Assert.assertThat) Collectors.toList(java.util.stream.Collectors.toList) Edge(org.openkilda.pce.model.Edge) Flow(org.openkilda.model.Flow) SwitchId(org.openkilda.model.SwitchId) Arrays.asList(java.util.Arrays.asList) Node(org.openkilda.pce.model.Node) Assert.assertEquals(org.junit.Assert.assertEquals) PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) FlowPath(org.openkilda.model.FlowPath)

Aggregations

FlowPath (org.openkilda.model.FlowPath)229 Flow (org.openkilda.model.Flow)128 Test (org.junit.Test)108 PathId (org.openkilda.model.PathId)65 PathSegment (org.openkilda.model.PathSegment)42 SwitchId (org.openkilda.model.SwitchId)40 ArrayList (java.util.ArrayList)39 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)33 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)29 Switch (org.openkilda.model.Switch)28 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)27 SpeakerData (org.openkilda.rulemanager.SpeakerData)27 Action (org.openkilda.rulemanager.action.Action)26 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)26 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)26 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)26 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)26 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)26 MeterId (org.openkilda.model.MeterId)20 YFlow (org.openkilda.model.YFlow)19