use of org.openkilda.model.FlowPath 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.FlowPath in project open-kilda by telstra.
the class AvailableNetworkFactoryTest method shouldBuildAvailableNetworkForFlowWithIgnoreBandwidthPaths.
@Test
public void shouldBuildAvailableNetworkForFlowWithIgnoreBandwidthPaths() throws Exception {
Flow flow = getFlow(false);
IslImmutableView isl = getIslView(flow);
PathId pathId = new PathId("flow-path-id");
FlowPath flowPath = FlowPath.builder().pathId(pathId).srcSwitch(flow.getSrcSwitch()).destSwitch(flow.getDestSwitch()).ignoreBandwidth(true).build();
when(config.getNetworkStrategy()).thenReturn("SYMMETRIC_COST");
when(islRepository.findSymmetricActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(Collections.singletonList(isl));
when(flowPathRepository.findById(pathId)).thenReturn(Optional.of(flowPath));
AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.singletonList(pathId));
assertAvailableNetworkIsCorrect(isl, availableNetwork);
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class AvailableNetworkFactoryTest method shouldIncreaseDiversityGroupUseCounter.
@Test
public void shouldIncreaseDiversityGroupUseCounter() throws RecoverableException {
// Topology:
// A----B----C Already created flow: B-D
// | Requested flow: A-B-C
// D
// there is no ISL B-D because we assume that is has no enough bandwidth
List<IslImmutableView> isls = new ArrayList<>();
isls.addAll(getBidirectionalIsls(switchA, 1, switchB, 2));
isls.addAll(getBidirectionalIsls(switchB, 3, switchC, 4));
FlowPath forwardPath = FlowPath.builder().srcSwitch(switchB).destSwitch(switchD).pathId(FORWARD_PATH_ID).segments(Collections.singletonList(PathSegment.builder().pathId(FORWARD_PATH_ID).srcSwitch(switchB).srcPort(SRC_PORT).destSwitch(switchD).destPort(DEST_PORT).build())).build();
when(flowPathRepository.findById(FORWARD_PATH_ID)).thenReturn(java.util.Optional.of(forwardPath));
FlowPath reversePath = FlowPath.builder().srcSwitch(switchD).destSwitch(switchB).pathId(REVERSE_PATH_ID).segments(Collections.singletonList(PathSegment.builder().pathId(REVERSE_PATH_ID).srcSwitch(switchD).srcPort(DEST_PORT).destSwitch(switchB).destPort(SRC_PORT).build())).build();
when(flowPathRepository.findById(REVERSE_PATH_ID)).thenReturn(java.util.Optional.of(reversePath));
Flow flow = getFlow(false);
flow.setSrcSwitch(switchA);
flow.setDestSwitch(switchC);
flow.setDiverseGroupId(DIVERSE_GROUP_ID);
flow.setForwardPathId(new PathId("forward_path_id"));
flow.setReversePathId(new PathId("reverse_path_id"));
when(config.getNetworkStrategy()).thenReturn(BuildStrategy.COST.name());
when(islRepository.findActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(isls);
when(flowPathRepository.findPathIdsByFlowDiverseGroupId(DIVERSE_GROUP_ID)).thenReturn(Lists.newArrayList(FORWARD_PATH_ID, REVERSE_PATH_ID));
AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
assertEquals(2, availableNetwork.getSwitch(switchB.getSwitchId()).getDiversityGroupUseCounter());
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class LatencyPathComputationStrategyBaseTest method shouldFindTheSameDiversePath.
@Test
public void shouldFindTheSameDiversePath() throws RecoverableException, UnroutableFlowException {
createDiamondWithDiversity();
Flow flow = Flow.builder().flowId("new-flow").diverseGroupId("diverse").bandwidth(10).srcSwitch(getSwitchById("00:0A")).srcPort(10).destSwitch(getSwitchById("00:0D")).destPort(10).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).pathComputationStrategy(PathComputationStrategy.LATENCY).build();
PathComputer pathComputer = pathComputerFactory.getPathComputer();
GetPathsResult diversePath = pathComputer.getPath(flow);
FlowPath forwardPath = FlowPath.builder().pathId(new PathId(UUID.randomUUID().toString())).srcSwitch(flow.getSrcSwitch()).destSwitch(flow.getDestSwitch()).bandwidth(flow.getBandwidth()).build();
addPathSegments(forwardPath, diversePath.getForward());
flow.setForwardPath(forwardPath);
FlowPath reversePath = FlowPath.builder().pathId(new PathId(UUID.randomUUID().toString())).srcSwitch(flow.getDestSwitch()).destSwitch(flow.getSrcSwitch()).bandwidth(flow.getBandwidth()).build();
addPathSegments(reversePath, diversePath.getReverse());
flow.setReversePath(reversePath);
flowRepository.add(flow);
GetPathsResult path2 = pathComputer.getPath(flow, flow.getPathIds());
assertEquals(diversePath, path2);
}
use of org.openkilda.model.FlowPath in project open-kilda by telstra.
the class AvailableNetworkTest method buildPathWithSegment.
private PathSegment buildPathWithSegment(SwitchId srcDpid, SwitchId dstDpid, int srcPort, int dstPort, String srcPop, String dstPop, int seqId) {
Switch srcSwitch = Switch.builder().switchId(srcDpid).pop(srcPop).build();
Switch dstSwitch = Switch.builder().switchId(dstDpid).pop(dstPop).build();
PathId pathId = new PathId(UUID.randomUUID().toString());
FlowPath flowPath = FlowPath.builder().pathId(pathId).srcSwitch(srcSwitch).destSwitch(dstSwitch).segments(IntStream.rangeClosed(0, seqId).mapToObj(i -> PathSegment.builder().pathId(pathId).srcSwitch(srcSwitch).destSwitch(dstSwitch).srcPort(srcPort).destPort(dstPort).build()).collect(toList())).build();
return flowPath.getSegments().get(seqId);
}
Aggregations