Search in sources :

Example 26 with GetPathsResult

use of org.openkilda.pce.GetPathsResult in project open-kilda by telstra.

the class InMemoryPathComputerBaseTest method shouldAlwaysFindPathForExistedFlow.

/**
 * Checks that existed flow should always have available path even there is only links with 0 available bandwidth.
 */
@Test
public void shouldAlwaysFindPathForExistedFlow() throws RecoverableException, UnroutableFlowException {
    String flowId = "flow-A1:01-A1:03";
    long bandwidth = 1000;
    createLinearTopoWithFlowSegments(10, "A1:", 1, 0L, flowId, bandwidth);
    Switch srcSwitch = getSwitchById("A1:01");
    Switch destSwitch = getSwitchById("A1:03");
    Flow flow = new TestFlowBuilder().flowId(flowId).srcSwitch(srcSwitch).destSwitch(destSwitch).bandwidth(bandwidth).ignoreBandwidth(false).build();
    Flow oldFlow = flowRepository.findById(flowId).orElseThrow(() -> new AssertionError("Flow not found"));
    PathComputer pathComputer = pathComputerFactory.getPathComputer();
    GetPathsResult result = pathComputer.getPath(flow, oldFlow.getPathIds());
    assertThat(result.getForward().getSegments(), Matchers.hasSize(2));
    assertThat(result.getReverse().getSegments(), Matchers.hasSize(2));
}
Also used : PathComputer(org.openkilda.pce.PathComputer) Switch(org.openkilda.model.Switch) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 27 with GetPathsResult

use of org.openkilda.pce.GetPathsResult in project open-kilda by telstra.

the class InMemoryPathComputerBaseTest method verifyConversionToPair.

/**
 * This verifies that the getPath in PathComputer returns what we expect. Essentially, this tests the additional
 * logic wrt taking the results of the algo and convert to something installable.
 */
@Test
public void verifyConversionToPair() throws UnroutableFlowException, RecoverableException {
    createDiamond(IslStatus.ACTIVE, IslStatus.ACTIVE, 10, 20, "09:", 1);
    Switch srcSwitch = getSwitchById("09:01");
    Switch destSwitch = getSwitchById("09:04");
    Flow flow = new TestFlowBuilder().srcSwitch(srcSwitch).destSwitch(destSwitch).bandwidth(10).ignoreBandwidth(false).build();
    PathComputer pathComputer = pathComputerFactory.getPathComputer();
    GetPathsResult result = pathComputer.getPath(flow);
    assertNotNull(result);
    // ensure start/end switches match
    List<Path.Segment> left = result.getForward().getSegments();
    assertEquals(srcSwitch.getSwitchId(), left.get(0).getSrcSwitchId());
    assertEquals(destSwitch.getSwitchId(), left.get(left.size() - 1).getDestSwitchId());
    List<Path.Segment> right = result.getReverse().getSegments();
    assertEquals(destSwitch.getSwitchId(), right.get(0).getSrcSwitchId());
    assertEquals(srcSwitch.getSwitchId(), right.get(right.size() - 1).getDestSwitchId());
}
Also used : PathComputer(org.openkilda.pce.PathComputer) Switch(org.openkilda.model.Switch) Segment(org.openkilda.pce.Path.Segment) PathSegment(org.openkilda.model.PathSegment) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 28 with GetPathsResult

use of org.openkilda.pce.GetPathsResult in project open-kilda by telstra.

the class MaxLatencyPathComputationStrategyBaseTest method nonGreedyMaxLatencyTest.

@Test
public void nonGreedyMaxLatencyTest() throws Exception {
    // non-greedy algorithm can't find the closest path to max-latency param
    createNonGreedyMaxLatencyTopo();
    Flow flow = Flow.builder().flowId("test flow").srcSwitch(getSwitchById("00:01")).srcPort(15).destSwitch(getSwitchById("00:06")).destPort(15).bandwidth(500).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).pathComputationStrategy(PathComputationStrategy.MAX_LATENCY).maxLatency(25L).build();
    PathComputer pathComputer = pathComputerFactory.getPathComputer();
    GetPathsResult path = pathComputer.getPath(flow);
    assertNotNull(path);
    // best path is A-D-B-C-F and has 4 segments and 24 latency but non-greedy algorithm can find only path A-D-E-F
    // with 3 segments and total latency 20
    assertEquals(path.getForward().getSegments().size(), 3);
}
Also used : PathComputer(org.openkilda.pce.PathComputer) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) Test(org.junit.Test)

Example 29 with GetPathsResult

use of org.openkilda.pce.GetPathsResult in project open-kilda by telstra.

the class CostAndBandwidthPathComputationStrategyTest method shouldFindPathOverDiamondWithAllActiveLinksAndIgnoreBandwidth.

@Test
public void shouldFindPathOverDiamondWithAllActiveLinksAndIgnoreBandwidth() throws RecoverableException, UnroutableFlowException {
    createDiamond(IslStatus.ACTIVE, IslStatus.ACTIVE, 10, 20, "05:", 1);
    Switch srcSwitch1 = getSwitchById("05:01");
    Switch destSwitch1 = getSwitchById("05:03");
    Flow f1 = getTestFlowBuilder(srcSwitch1, destSwitch1).bandwidth(0).ignoreBandwidth(false).build();
    PathComputer pathComputer = pathComputerFactory.getPathComputer();
    GetPathsResult path = pathComputer.getPath(f1);
    assertNotNull(path);
    assertThat(path.getForward().getSegments(), Matchers.hasSize(1));
    Switch srcSwitch2 = getSwitchById("05:01");
    Switch destSwitch2 = getSwitchById("05:04");
    Flow f2 = getTestFlowBuilder(srcSwitch2, destSwitch2).bandwidth(0).ignoreBandwidth(false).build();
    path = pathComputer.getPath(f2);
    assertNotNull(path);
    assertThat(path.getForward().getSegments(), Matchers.hasSize(2));
    assertEquals(new SwitchId("05:02"), path.getForward().getSegments().get(0).getDestSwitchId());
}
Also used : PathComputer(org.openkilda.pce.PathComputer) Switch(org.openkilda.model.Switch) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) Test(org.junit.Test)

Example 30 with GetPathsResult

use of org.openkilda.pce.GetPathsResult in project open-kilda by telstra.

the class CostAndBandwidthPathComputationStrategyTest method shouldFindPathOverTriangleWithOneActiveRouteByCostAndBandwidth.

@Test
public void shouldFindPathOverTriangleWithOneActiveRouteByCostAndBandwidth() throws UnroutableFlowException, RecoverableException {
    /*
         * simple happy path test .. but lowest path is inactive
         */
    createTriangleTopo(IslStatus.INACTIVE, 5, 20, "02:", 1);
    Switch srcSwitch = getSwitchById("02:01");
    Switch destSwitch = getSwitchById("02:02");
    Flow f = getTestFlowBuilder(srcSwitch, destSwitch).build();
    PathComputer pathComputer = pathComputerFactory.getPathComputer();
    GetPathsResult path = pathComputer.getPath(f);
    assertNotNull(path);
    assertThat(path.getForward().getSegments(), Matchers.hasSize(2));
    // ====> only difference is it should now have C as first hop .. since B is inactive
    // chooses path C
    assertEquals(new SwitchId("02:03"), path.getForward().getSegments().get(0).getDestSwitchId());
}
Also used : PathComputer(org.openkilda.pce.PathComputer) Switch(org.openkilda.model.Switch) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) Test(org.junit.Test)

Aggregations

Flow (org.openkilda.model.Flow)50 GetPathsResult (org.openkilda.pce.GetPathsResult)50 PathComputer (org.openkilda.pce.PathComputer)42 Test (org.junit.Test)40 SwitchId (org.openkilda.model.SwitchId)30 Switch (org.openkilda.model.Switch)22 FlowPath (org.openkilda.model.FlowPath)8 PathId (org.openkilda.model.PathId)8 FlowResources (org.openkilda.wfm.share.flow.resources.FlowResources)7 PathSegment (org.openkilda.model.PathSegment)5 BestWeightAndShortestPathFinder (org.openkilda.pce.finder.BestWeightAndShortestPathFinder)5 FlowPathPair (org.openkilda.wfm.topology.flow.model.FlowPathPair)5 ArrayList (java.util.ArrayList)4 Segment (org.openkilda.pce.Path.Segment)4 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)4 ResourceAllocationException (org.openkilda.wfm.share.flow.resources.ResourceAllocationException)4 List (java.util.List)3 Predicate (java.util.function.Predicate)3 Slf4j (lombok.extern.slf4j.Slf4j)3 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)3