Search in sources :

Example 11 with Node

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();
}
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 12 with Node

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();
        }
    }
}
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 13 with Node

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);
}
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)

Example 14 with Node

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

Example 15 with Node

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

Aggregations

Node (org.openkilda.pce.model.Node)20 Edge (org.openkilda.pce.model.Edge)15 Test (org.junit.Test)8 SwitchId (org.openkilda.model.SwitchId)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)3 ArrayList (java.util.ArrayList)2 Collections.emptyList (java.util.Collections.emptyList)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Flow (org.openkilda.model.Flow)2 PathSegment (org.openkilda.model.PathSegment)2 FindOneDirectionPathResult (org.openkilda.pce.model.FindOneDirectionPathResult)2 PathWeight (org.openkilda.pce.model.PathWeight)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1