Search in sources :

Example 36 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method shouldChooseExpensiveOverTooDeepForReverseOrder.

@Test
public void shouldChooseExpensiveOverTooDeepForReverseOrder() throws UnroutableFlowException {
    AvailableNetwork network = buildLongAndExpensivePathsNetwork();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(2);
    Pair<List<Edge>, List<Edge>> pairPath = pathFinder.findPathWithMinWeight(network, SWITCH_ID_4, SWITCH_ID_1, WEIGHT_FUNCTION).getFoundPath();
    List<Edge> fpath = pairPath.getLeft();
    assertThat(fpath, Matchers.hasSize(2));
    assertEquals(SWITCH_ID_2, fpath.get(1).getSrcSwitch().getSwitchId());
    List<Edge> rpath = pairPath.getRight();
    assertThat(rpath, Matchers.hasSize(2));
    assertEquals(SWITCH_ID_2, rpath.get(0).getDestSwitch().getSwitchId());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Edge(org.openkilda.pce.model.Edge) Test(org.junit.Test)

Example 37 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method addIntermediateSwitchWeightOnceMaxWeightStrategy.

private FindPathResult addIntermediateSwitchWeightOnceMaxWeightStrategy(long maxWeight, long backUpMaxWeight) throws UnroutableFlowException {
    // given 3 paths that cost: 198, 200, 201
    AvailableNetwork network = buildThreePathsNetwork();
    // switch on '200' path has a diversity weight increase
    network.getSwitch(SWITCH_ID_3).increaseDiversityGroupUseCounter();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    // when: request a path with maxWeight 201
    FindPathResult pathResult = pathFinder.findPathWithWeightCloseToMaxWeight(network, SWITCH_ID_1, SWITCH_ID_5, WEIGHT_FUNCTION, maxWeight, backUpMaxWeight);
    Pair<List<Edge>, List<Edge>> pairPath = pathResult.getFoundPath();
    // then: system picks 198 path (since 200 path is no longer '200' due to diversity weight rise)
    List<SwitchId> forwardSwitches = getInvolvedSwitches(pairPath.getLeft());
    assertThat(forwardSwitches, equalTo(Arrays.asList(SWITCH_ID_1, SWITCH_ID_2, SWITCH_ID_5)));
    assertThat(getInvolvedSwitches(pairPath.getRight()), equalTo(Lists.reverse(forwardSwitches)));
    return pathResult;
}
Also used : FindPathResult(org.openkilda.pce.model.FindPathResult) ArrayList(java.util.ArrayList) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork)

Example 38 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method shouldChooseCheaperWithSameDepth.

@Test
public void shouldChooseCheaperWithSameDepth() throws UnroutableFlowException {
    AvailableNetwork network = buildLongAndExpensivePathsNetwork();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(3);
    Pair<List<Edge>, List<Edge>> pairPath = pathFinder.findPathWithMinWeight(network, SWITCH_ID_1, SWITCH_ID_5, WEIGHT_FUNCTION).getFoundPath();
    List<Edge> fpath = pairPath.getLeft();
    assertThat(fpath, Matchers.hasSize(3));
    assertEquals(SWITCH_ID_3, fpath.get(2).getSrcSwitch().getSwitchId());
    List<Edge> rpath = pairPath.getRight();
    assertThat(rpath, Matchers.hasSize(3));
    assertEquals(SWITCH_ID_3, rpath.get(0).getDestSwitch().getSwitchId());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Edge(org.openkilda.pce.model.Edge) Test(org.junit.Test)

Example 39 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method shouldChooseCheaperOverTooDeepMaxWeightStrategy.

@Test
public void shouldChooseCheaperOverTooDeepMaxWeightStrategy() throws UnroutableFlowException {
    AvailableNetwork network = buildLongAndExpensivePathsNetwork();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(2);
    Pair<List<Edge>, List<Edge>> pairPath = pathFinder.findPathWithWeightCloseToMaxWeight(network, SWITCH_ID_1, SWITCH_ID_3, WEIGHT_FUNCTION, Long.MAX_VALUE, Long.MAX_VALUE).getFoundPath();
    List<Edge> fpath = pairPath.getLeft();
    assertThat(fpath, Matchers.hasSize(2));
    assertEquals(SWITCH_ID_2, fpath.get(1).getSrcSwitch().getSwitchId());
    List<Edge> rpath = pairPath.getRight();
    assertThat(rpath, Matchers.hasSize(2));
    assertEquals(SWITCH_ID_2, rpath.get(0).getDestSwitch().getSwitchId());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Edge(org.openkilda.pce.model.Edge) Test(org.junit.Test)

Example 40 with AvailableNetwork

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

the class AvailableNetworkFactoryTest method shouldBuildAvailableNetworkUsingSymmetricCostStrategy.

@Test
public void shouldBuildAvailableNetworkUsingSymmetricCostStrategy() throws RecoverableException {
    Flow flow = getFlow(false);
    IslImmutableView isl = getIslView(flow);
    when(config.getNetworkStrategy()).thenReturn("SYMMETRIC_COST");
    when(islRepository.findSymmetricActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(Collections.singletonList(isl));
    AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
    assertAvailableNetworkIsCorrect(isl, availableNetwork);
}
Also used : IslImmutableView(org.openkilda.persistence.repositories.IslRepository.IslImmutableView) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Aggregations

AvailableNetwork (org.openkilda.pce.impl.AvailableNetwork)43 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)24 List (java.util.List)23 Edge (org.openkilda.pce.model.Edge)13 SwitchId (org.openkilda.model.SwitchId)9 Flow (org.openkilda.model.Flow)7 IslImmutableView (org.openkilda.persistence.repositories.IslRepository.IslImmutableView)7 FindPathResult (org.openkilda.pce.model.FindPathResult)6 FlowPath (org.openkilda.model.FlowPath)3 PathId (org.openkilda.model.PathId)3 Collectors (java.util.stream.Collectors)2 Lists (com.google.common.collect.Lists)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 IntStream (java.util.stream.IntStream)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Pair (org.apache.commons.lang3.tuple.Pair)1 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)1