use of org.openkilda.pce.model.Node in project open-kilda by telstra.
the class BestWeightAndShortestPathFinder method findPath.
private FindPathResult findPath(AvailableNetwork network, SwitchId startSwitchId, SwitchId endSwitchId, Supplier<FindOneDirectionPathResult> getPath) throws UnroutableFlowException {
Node start = network.getSwitch(startSwitchId);
Node end = network.getSwitch(endSwitchId);
if (start == null || end == null) {
throw new UnroutableFlowException(format("Switch %s doesn't have links with enough bandwidth", start == null ? startSwitchId : endSwitchId));
}
FindOneDirectionPathResult pathFindResult = getPath.get();
List<Edge> forwardPath = pathFindResult.getFoundPath();
if (forwardPath.isEmpty()) {
throw new UnroutableFlowException(format("Can't find a path from %s to %s", start, end));
}
List<Edge> reversePath = getReversePath(end, start, forwardPath);
if (reversePath.isEmpty()) {
throw new UnroutableFlowException(format("Can't find a reverse path from %s to %s. Forward path : %s", end, start, StringUtils.join(forwardPath, ", ")));
}
return FindPathResult.builder().foundPath(Pair.of(forwardPath, reversePath)).backUpPathComputationWayUsed(pathFindResult.isBackUpPathComputationWayUsed()).build();
}
use of org.openkilda.pce.model.Node in project open-kilda by telstra.
the class AvailableNetwork method processDiversitySegments.
/**
* Adds diversity weights into {@link AvailableNetwork} based on passed path segments and configuration.
*/
public void processDiversitySegments(List<PathSegment> segments, Flow flow) {
Set<SwitchId> terminatingSwitches = newHashSet(flow.getSrcSwitchId(), flow.getDestSwitchId());
for (PathSegment segment : segments) {
Node srcNode = getSwitch(segment.getSrcSwitchId());
Node dstNode = getSwitch(segment.getDestSwitchId());
if (dstNode != null && !terminatingSwitches.contains(dstNode.getSwitchId())) {
dstNode.increaseDiversityGroupUseCounter();
}
if (srcNode != null && segment.getSeqId() == 0 && !terminatingSwitches.contains(srcNode.getSwitchId())) {
srcNode.increaseDiversityGroupUseCounter();
}
if (srcNode == null || dstNode == null) {
log.debug("Diversity segment {} don't present in AvailableNetwork", segment);
continue;
}
Edge segmentEdge = Edge.builder().srcSwitch(srcNode).srcPort(segment.getSrcPort()).destSwitch(dstNode).destPort(segment.getDestPort()).build();
Optional<Edge> edgeOptional = dstNode.getIncomingLinks().stream().filter(segmentEdge::equals).findAny();
if (edgeOptional.isPresent()) {
Edge edge = edgeOptional.get();
edge.increaseDiversityGroupUseCounter();
}
}
}
use of org.openkilda.pce.model.Node in project open-kilda by telstra.
the class AvailableNetwork method processAffinitySegments.
/**
* Adds affinity weights into {@link AvailableNetwork} based on passed path segments and configuration.
*/
public void processAffinitySegments(List<PathSegment> segments) {
Set<Edge> pathEdges = new HashSet<>();
for (PathSegment segment : segments) {
Node srcNode = getSwitch(segment.getSrcSwitchId());
Node dstNode = getSwitch(segment.getDestSwitchId());
if (srcNode == null || dstNode == null) {
log.debug("Affinity segment {} doesn't present in AvailableNetwork", segment);
continue;
}
Edge segmentEdge = Edge.builder().srcSwitch(srcNode).srcPort(segment.getSrcPort()).destSwitch(dstNode).destPort(segment.getDestPort()).build();
pathEdges.add(segmentEdge);
Edge reverseSegmentEdge = segmentEdge.swap();
pathEdges.add(reverseSegmentEdge);
}
edges.stream().filter(edge -> !pathEdges.contains(edge)).forEach(Edge::increaseAffinityGroupUseCounter);
}
use of org.openkilda.pce.model.Node in project open-kilda by telstra.
the class AvailableNetworkTest method shouldFillDiversityWeightsPartiallyConnected.
/*
A = B - C = D
*/
@Test
public void shouldFillDiversityWeightsPartiallyConnected() {
SwitchId switchA = new SwitchId("A");
SwitchId switchB = new SwitchId("B");
SwitchId switchC = new SwitchId("C");
SwitchId switchD = new SwitchId("D");
AvailableNetwork network = new AvailableNetwork();
addLink(network, switchA, switchB, 1, 1, 10, 3);
addLink(network, switchB, switchC, 2, 2, 10, 3);
addLink(network, switchC, switchD, 3, 3, 10, 3);
network.processDiversitySegments(asList(buildPathSegment(switchA, switchB, 1, 1, 0), buildPathSegment(switchC, switchD, 3, 3, 0)), DUMMY_FLOW);
Node nodeB = network.getSwitch(switchB);
Edge edge = nodeB.getOutgoingLinks().stream().filter(link -> link.getDestSwitch().getSwitchId().equals(switchC)).findAny().orElseThrow(() -> new IllegalStateException("Link 'B-C' not found"));
assertEquals(0, edge.getDiversityGroupUseCounter());
assertEquals(1, edge.getDestSwitch().getDiversityGroupUseCounter());
}
use of org.openkilda.pce.model.Node in project open-kilda by telstra.
the class AvailableNetworkTest method shouldProcessAbsentDiversitySegment.
@Test
public void shouldProcessAbsentDiversitySegment() {
AvailableNetwork network = new AvailableNetwork();
addLink(network, SRC_SWITCH, DST_SWITCH, 7, 60, 10, 3);
network.processDiversitySegments(singletonList(buildPathSegment(SRC_SWITCH, DST_SWITCH, 1, 2, 0)), DUMMY_FLOW);
Node srcSwitch = network.getSwitch(SRC_SWITCH);
Edge edge = srcSwitch.getOutgoingLinks().iterator().next();
assertEquals(0, edge.getDiversityGroupUseCounter());
// as switches are in AvailableNetwork
assertEquals(1, edge.getDestSwitch().getDiversityGroupUseCounter());
assertEquals(1, edge.getSrcSwitch().getDiversityGroupUseCounter());
}
Aggregations