Search in sources :

Example 16 with Edge

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);
}
Also used : Edge(org.openkilda.pce.model.Edge)

Example 17 with Edge

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();
}
Also used : Node(org.openkilda.pce.model.Node) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) FindOneDirectionPathResult(org.openkilda.pce.model.FindOneDirectionPathResult) Edge(org.openkilda.pce.model.Edge)

Example 18 with Edge

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;
        }
    }
}
Also used : ToString(lombok.ToString) PathSegment(org.openkilda.model.PathSegment) Edge(org.openkilda.pce.model.Edge) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet)

Example 19 with Edge

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();
        }
    }
}
Also used : Node(org.openkilda.pce.model.Node) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) Edge(org.openkilda.pce.model.Edge)

Example 20 with Edge

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);
}
Also used : PathSegment(org.openkilda.model.PathSegment) Set(java.util.Set) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Edge(org.openkilda.pce.model.Edge) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Flow(org.openkilda.model.Flow) SwitchId(org.openkilda.model.SwitchId) Node(org.openkilda.pce.model.Node) Map(java.util.Map) ToString(lombok.ToString) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Node(org.openkilda.pce.model.Node) PathSegment(org.openkilda.model.PathSegment) Edge(org.openkilda.pce.model.Edge) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet)

Aggregations

Edge (org.openkilda.pce.model.Edge)39 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)16 List (java.util.List)16 Node (org.openkilda.pce.model.Node)15 AvailableNetwork (org.openkilda.pce.impl.AvailableNetwork)13 SwitchId (org.openkilda.model.SwitchId)7 WeightFunction (org.openkilda.pce.model.WeightFunction)7 HashSet (java.util.HashSet)5 PathSegment (org.openkilda.model.PathSegment)5 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)5 LinkedList (java.util.LinkedList)4 FindPathResult (org.openkilda.pce.model.FindPathResult)4 Collections.emptyList (java.util.Collections.emptyList)3 Objects (java.util.Objects)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3 PathWeight (org.openkilda.pce.model.PathWeight)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2