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());
}
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);
}
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());
}
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());
}
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")));
}
Aggregations