use of org.openkilda.model.SwitchId 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;
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class InMemoryPathComputer method getNPaths.
@Override
public List<Path> getNPaths(SwitchId srcSwitchId, SwitchId dstSwitchId, int count, FlowEncapsulationType flowEncapsulationType, PathComputationStrategy pathComputationStrategy, Duration maxLatency, Duration maxLatencyTier2) throws RecoverableException, UnroutableFlowException {
final long maxLatencyNs = maxLatency != null ? maxLatency.toNanos() : 0;
final long maxLatencyTier2Ns = maxLatencyTier2 != null ? maxLatencyTier2.toNanos() : 0;
Flow flow = Flow.builder().flowId(// just any id, as not used.
"").srcSwitch(Switch.builder().switchId(srcSwitchId).build()).destSwitch(Switch.builder().switchId(dstSwitchId).build()).ignoreBandwidth(false).encapsulationType(flowEncapsulationType).bandwidth(// to get ISLs with non zero available bandwidth
1).maxLatency(maxLatencyNs).maxLatencyTier2(maxLatencyTier2Ns).build();
AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
if (MAX_LATENCY.equals(pathComputationStrategy) && (flow.getMaxLatency() == null || flow.getMaxLatency() == 0)) {
pathComputationStrategy = LATENCY;
}
List<List<Edge>> paths;
switch(pathComputationStrategy) {
case COST:
case LATENCY:
case COST_AND_AVAILABLE_BANDWIDTH:
paths = pathFinder.findNPathsBetweenSwitches(availableNetwork, srcSwitchId, dstSwitchId, count, getWeightFunctionByStrategy(pathComputationStrategy));
break;
case MAX_LATENCY:
paths = pathFinder.findNPathsBetweenSwitches(availableNetwork, srcSwitchId, dstSwitchId, count, getWeightFunctionByStrategy(pathComputationStrategy), maxLatencyNs, maxLatencyTier2Ns);
break;
default:
throw new UnsupportedOperationException(String.format("Unsupported strategy type %s", pathComputationStrategy));
}
Comparator<Path> comparator;
if (pathComputationStrategy == LATENCY || pathComputationStrategy == MAX_LATENCY) {
comparator = Comparator.comparing(Path::getLatency).thenComparing(Comparator.comparing(Path::getMinAvailableBandwidth).reversed());
} else {
comparator = Comparator.comparing(Path::getMinAvailableBandwidth).reversed().thenComparing(Path::getLatency);
}
return paths.stream().map(edges -> convertToPath(srcSwitchId, dstSwitchId, edges)).sorted(comparator).limit(count).collect(Collectors.toList());
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class BestWeightAndShortestPathFinderTest method failToFindASwitch.
@Test(expected = UnroutableFlowException.class)
public void failToFindASwitch() throws UnroutableFlowException {
AvailableNetwork network = buildTestNetwork();
SwitchId srcDpid = new SwitchId("00:00:00:00:00:00:00:ff");
BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
pathFinder.findPathWithMinWeight(network, srcDpid, SWITCH_ID_F, WEIGHT_FUNCTION);
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class BestWeightAndShortestPathFinderTest method testForwardAndBackwardPathsEquality.
@Test
public void testForwardAndBackwardPathsEquality() throws UnroutableFlowException {
AvailableNetwork network = buildEqualCostsNetwork();
BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
Pair<List<Edge>, List<Edge>> paths = pathFinder.findPathWithMinWeight(network, SWITCH_ID_1, SWITCH_ID_5, WEIGHT_FUNCTION).getFoundPath();
List<SwitchId> forwardSwitchPath = getSwitchIdsFlowPath(paths.getLeft());
List<SwitchId> backwardSwitchPath = Lists.reverse(getSwitchIdsFlowPath(paths.getRight()));
assertEquals(forwardSwitchPath, backwardSwitchPath);
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class CostAndBandwidthPathComputationStrategyTest method shouldFindPathOverDiamondWithOneActiveRouteByCostAndBandwidth.
@Test
public void shouldFindPathOverDiamondWithOneActiveRouteByCostAndBandwidth() throws UnroutableFlowException, RecoverableException {
createDiamond(IslStatus.INACTIVE, IslStatus.ACTIVE, 10, 20, "01:", 1);
Switch srcSwitch = getSwitchById("01:01");
Switch destSwitch = getSwitchById("01:04");
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("01:03"), path.getForward().getSegments().get(0).getDestSwitchId());
}
Aggregations