use of org.openkilda.pce.model.Edge in project open-kilda by telstra.
the class BestWeightAndShortestPathFinder method restoreEdge.
private void restoreEdge(Edge edge) {
edge.getSrcSwitch().getOutgoingLinks().add(edge);
edge.getDestSwitch().getIncomingLinks().add(edge);
Edge reverseEdge = edge.swap();
reverseEdge.getSrcSwitch().getOutgoingLinks().add(reverseEdge);
reverseEdge.getDestSwitch().getIncomingLinks().add(reverseEdge);
}
use of org.openkilda.pce.model.Edge 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.Edge in project open-kilda by telstra.
the class AvailableNetwork method processDiversitySegmentsWithPop.
/**
* Adds diversity weights into {@link AvailableNetwork} based on passed path segments and configuration.
*/
public void processDiversitySegmentsWithPop(List<PathSegment> segments) {
if (segments.size() <= 1) {
return;
}
Set<String> allocatedPopSet = new HashSet<>();
for (PathSegment ps : segments) {
allocatedPopSet.add(ps.getSrcSwitch().getPop());
allocatedPopSet.add(ps.getDestSwitch().getPop());
}
String inPop = segments.get(0).getSrcSwitch().getPop();
allocatedPopSet.remove(inPop);
String outPop = segments.get(segments.size() - 1).getDestSwitch().getPop();
allocatedPopSet.remove(outPop);
for (Edge edge : edges) {
String srcPop = edge.getSrcSwitch().getPop();
if (srcPop != null && allocatedPopSet.contains(srcPop)) {
edge.increaseDiversityGroupPerPopUseCounter();
continue;
}
String dstPop = edge.getDestSwitch().getPop();
if (dstPop != null && allocatedPopSet.contains(dstPop)) {
edge.increaseDiversityGroupPerPopUseCounter();
continue;
}
}
}
use of org.openkilda.pce.model.Edge 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.Edge 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);
}
Aggregations