Search in sources :

Example 6 with BestWeightAndShortestPathFinder

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

the class InMemoryPathComputerBaseTest method shouldThrowSharedSwitchIsNotEndpointSwitch.

@Test
public void shouldThrowSharedSwitchIsNotEndpointSwitch() {
    FlowPath flowPathA = buildFlowPath("flow_path_a", 6, 2, 3);
    FlowPath flowPathB = buildFlowPath("flow_path_b", 1, 2, 4, 5);
    InMemoryPathComputer pathComputer = new InMemoryPathComputer(availableNetworkFactory, new BestWeightAndShortestPathFinder(config.getMaxAllowedDepth()), config);
    Exception exception = assertThrows(IllegalArgumentException.class, () -> pathComputer.convertFlowPathsToSwitchLists(SWITCH_1, flowPathA, flowPathB));
    assertEquals("Shared switch '00:00:00:00:00:00:00:01' is not an endpoint switch for path 'flow_path_a'", exception.getMessage());
}
Also used : BestWeightAndShortestPathFinder(org.openkilda.pce.finder.BestWeightAndShortestPathFinder) FlowPath(org.openkilda.model.FlowPath) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) RecoverableException(org.openkilda.pce.exception.RecoverableException) ExpectedException(org.junit.rules.ExpectedException) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 7 with BestWeightAndShortestPathFinder

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

the class InMemoryPathComputerBaseTest method shouldFindOverLargeIslands.

/**
 * See how it works with a large network. It takes a while to create the network .. therefore @Ignore so that it
 * doesn't slow down unit tests.
 */
@Test
@Ignore
public void shouldFindOverLargeIslands() throws RecoverableException, UnroutableFlowException {
    createDiamond(IslStatus.ACTIVE, IslStatus.ACTIVE, 10, 20, "08:", 1);
    for (int i = 0; i < 50; i++) {
        createDiamond(IslStatus.ACTIVE, IslStatus.ACTIVE, 10, 20, "10:", 4 * i + 1);
        createDiamond(IslStatus.ACTIVE, IslStatus.ACTIVE, 10, 20, "11:", 4 * i + 1);
        createDiamond(IslStatus.ACTIVE, IslStatus.ACTIVE, 10, 20, "12:", 4 * i + 1);
        createDiamond(IslStatus.ACTIVE, IslStatus.ACTIVE, 10, 20, "13:", 4 * i + 1);
    }
    for (int i = 0; i < 49; i++) {
        String prev = format("%02X", 4 * i + 4);
        String next = format("%02X", 4 * i + 5);
        connectDiamonds(new SwitchId("10:" + prev), new SwitchId("10:" + next), IslStatus.ACTIVE, 20, 50);
        connectDiamonds(new SwitchId("11:" + prev), new SwitchId("11:" + next), IslStatus.ACTIVE, 20, 50);
        connectDiamonds(new SwitchId("12:" + prev), new SwitchId("12:" + next), IslStatus.ACTIVE, 20, 50);
        connectDiamonds(new SwitchId("13:" + prev), new SwitchId("13:" + next), IslStatus.ACTIVE, 20, 50);
    }
    connectDiamonds(new SwitchId("10:99"), new SwitchId("11:22"), IslStatus.ACTIVE, 20, 50);
    connectDiamonds(new SwitchId("11:99"), new SwitchId("12:22"), IslStatus.ACTIVE, 20, 50);
    connectDiamonds(new SwitchId("12:99"), new SwitchId("13:22"), IslStatus.ACTIVE, 20, 50);
    connectDiamonds(new SwitchId("13:99"), new SwitchId("10:22"), IslStatus.ACTIVE, 20, 50);
    Switch srcSwitch1 = getSwitchById("10:01");
    Switch destSwitch1 = getSwitchById("11:03");
    // THIS ONE SHOULD WORK
    Flow f1 = new TestFlowBuilder().srcSwitch(srcSwitch1).destSwitch(destSwitch1).bandwidth(0).ignoreBandwidth(false).build();
    PathComputer pathComputer = new InMemoryPathComputer(availableNetworkFactory, new BestWeightAndShortestPathFinder(200), config);
    GetPathsResult path = pathComputer.getPath(f1);
    assertNotNull(path);
    assertThat(path.getForward().getSegments(), Matchers.hasSize(278));
    Switch srcSwitch2 = getSwitchById("08:01");
    Switch destSwitch2 = getSwitchById("11:04");
    // THIS ONE SHOULD FAIL
    Flow f2 = new TestFlowBuilder().srcSwitch(srcSwitch2).destSwitch(destSwitch2).bandwidth(0).ignoreBandwidth(false).build();
    thrown.expect(UnroutableFlowException.class);
    pathComputer.getPath(f2);
}
Also used : PathComputer(org.openkilda.pce.PathComputer) Switch(org.openkilda.model.Switch) BestWeightAndShortestPathFinder(org.openkilda.pce.finder.BestWeightAndShortestPathFinder) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) Ignore(org.junit.Ignore) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 8 with BestWeightAndShortestPathFinder

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

the class InMemoryPathComputerBaseTest method shouldConvertFlowPathsToSwitchLists.

@Test
public void shouldConvertFlowPathsToSwitchLists() {
    int[] switchIdsA = { 1, 2, 3 };
    int[] switchIdsB = { 1, 2, 4, 5 };
    FlowPath flowPathA = buildFlowPath("flow_path_a", switchIdsA);
    FlowPath flowPathB = buildFlowPath("flow_path_b", switchIdsB);
    InMemoryPathComputer pathComputer = new InMemoryPathComputer(availableNetworkFactory, new BestWeightAndShortestPathFinder(config.getMaxAllowedDepth()), config);
    List<LinkedList<SwitchId>> result = pathComputer.convertFlowPathsToSwitchLists(SWITCH_1, flowPathA, flowPathB);
    assertEquals(2, result.size());
    assertArrayEquals(switchIdsA, result.get(0).stream().mapToInt(id -> (int) id.toLong()).toArray());
    assertArrayEquals(switchIdsB, result.get(1).stream().mapToInt(id -> (int) id.toLong()).toArray());
}
Also used : BestWeightAndShortestPathFinder(org.openkilda.pce.finder.BestWeightAndShortestPathFinder) FlowPath(org.openkilda.model.FlowPath) LinkedList(java.util.LinkedList) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 9 with BestWeightAndShortestPathFinder

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

the class InMemoryPathComputerBaseTest method shouldThrowPathHasNoSegmentsWhenSegmentsIsEmpty.

@Test
public void shouldThrowPathHasNoSegmentsWhenSegmentsIsEmpty() {
    FlowPath flowPathA = FlowPath.builder().pathId(new PathId("flow_path_a")).srcSwitch(Switch.builder().switchId(new SwitchId(1)).build()).destSwitch(Switch.builder().switchId(new SwitchId(3)).build()).segments(new ArrayList<>()).build();
    FlowPath flowPathB = buildFlowPath("flow_path_b", 1, 2, 4, 5);
    InMemoryPathComputer pathComputer = new InMemoryPathComputer(availableNetworkFactory, new BestWeightAndShortestPathFinder(config.getMaxAllowedDepth()), config);
    Exception exception = assertThrows(IllegalArgumentException.class, () -> pathComputer.convertFlowPathsToSwitchLists(SWITCH_1, flowPathA, flowPathB));
    assertEquals("The path 'flow_path_a' has no path segments", exception.getMessage());
}
Also used : PathId(org.openkilda.model.PathId) ArrayList(java.util.ArrayList) BestWeightAndShortestPathFinder(org.openkilda.pce.finder.BestWeightAndShortestPathFinder) SwitchId(org.openkilda.model.SwitchId) FlowPath(org.openkilda.model.FlowPath) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) RecoverableException(org.openkilda.pce.exception.RecoverableException) ExpectedException(org.junit.rules.ExpectedException) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 10 with BestWeightAndShortestPathFinder

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

the class MaxLatencyPathComputationStrategyBaseTest method maxLatencyStratWithZeroLatency.

/**
 * Special case: flow with MAX_LATENCY strategy and 'max-latency' set to 0 should pick path with least latency.
 */
@Test
public void maxLatencyStratWithZeroLatency() throws RecoverableException, UnroutableFlowException {
    // 1 - 2 - 4
    // + 3 +
    // path 1>2>4 has less latency than 1>3>4
    createDiamond(IslStatus.ACTIVE, IslStatus.ACTIVE, 100, 100, "00:", 1, 100, 101);
    // when: request a flow with MAX_LATENCY strategy and 'max-latency' set to 0
    Flow flow = Flow.builder().flowId("test flow").srcSwitch(getSwitchById("00:01")).srcPort(15).destSwitch(getSwitchById("00:04")).destPort(15).bandwidth(500).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).pathComputationStrategy(PathComputationStrategy.MAX_LATENCY).maxLatency(0L).build();
    PathComputer pathComputer = new InMemoryPathComputer(availableNetworkFactory, new BestWeightAndShortestPathFinder(5), config);
    GetPathsResult pathsResult = pathComputer.getPath(flow);
    // then: system returns a path with least weight
    assertFalse(pathsResult.isBackUpPathComputationWayUsed());
    assertThat(pathsResult.getForward().getSegments().get(1).getSrcSwitchId(), equalTo(new SwitchId("00:02")));
    assertThat(pathsResult.getReverse().getSegments().get(1).getSrcSwitchId(), equalTo(new SwitchId("00:02")));
}
Also used : PathComputer(org.openkilda.pce.PathComputer) BestWeightAndShortestPathFinder(org.openkilda.pce.finder.BestWeightAndShortestPathFinder) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 BestWeightAndShortestPathFinder (org.openkilda.pce.finder.BestWeightAndShortestPathFinder)10 SwitchId (org.openkilda.model.SwitchId)7 Flow (org.openkilda.model.Flow)6 PathComputer (org.openkilda.pce.PathComputer)6 GetPathsResult (org.openkilda.pce.GetPathsResult)5 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)5 FlowPath (org.openkilda.model.FlowPath)4 ExpectedException (org.junit.rules.ExpectedException)3 RecoverableException (org.openkilda.pce.exception.RecoverableException)3 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)3 PathId (org.openkilda.model.PathId)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Ignore (org.junit.Ignore)1 Switch (org.openkilda.model.Switch)1