Search in sources :

Example 6 with Edge

use of org.openkilda.pce.model.Edge in project open-kilda by telstra.

the class AvailableNetworkTest method addLink.

private void addLink(AvailableNetwork network, SwitchId srcDpid, SwitchId dstDpid, int srcPort, int dstPort, int cost, int latency, String srcPop, String dstPop) {
    Edge edge = Edge.builder().srcSwitch(network.getOrAddNode(srcDpid, srcPop)).srcPort(srcPort).destSwitch(network.getOrAddNode(dstDpid, dstPop)).destPort(dstPort).latency(latency).cost(cost).availableBandwidth(500000).underMaintenance(false).unstable(false).build();
    network.addEdge(edge);
}
Also used : Edge(org.openkilda.pce.model.Edge)

Example 7 with Edge

use of org.openkilda.pce.model.Edge in project open-kilda by telstra.

the class AvailableNetworkTest method shouldCreateSymmetricOutgoingAndIncomming.

@Test
public void shouldCreateSymmetricOutgoingAndIncomming() {
    AvailableNetwork network = new AvailableNetwork();
    addLink(network, SRC_SWITCH, DST_SWITCH, 7, 60, 10, 3);
    Node srcSwitch = network.getSwitch(SRC_SWITCH);
    Node dstSwitch = network.getSwitch(DST_SWITCH);
    Set<Edge> outgoingLinks = srcSwitch.getOutgoingLinks();
    assertThat(outgoingLinks, Matchers.hasSize(1));
    Edge outgoingIsl = outgoingLinks.iterator().next();
    assertEquals(dstSwitch, outgoingIsl.getDestSwitch());
    Set<Edge> incomingLinks = dstSwitch.getIncomingLinks();
    assertThat(incomingLinks, Matchers.hasSize(1));
    Edge incomingIsl = incomingLinks.iterator().next();
    assertEquals(srcSwitch, incomingIsl.getSrcSwitch());
}
Also used : Node(org.openkilda.pce.model.Node) Edge(org.openkilda.pce.model.Edge) Test(org.junit.Test)

Example 8 with Edge

use of org.openkilda.pce.model.Edge in project open-kilda by telstra.

the class AvailableNetworkTest method shouldUpdateEdgeWeightWithPopDiversityPenalty.

@Test
public void shouldUpdateEdgeWeightWithPopDiversityPenalty() {
    int cost = 700;
    final WeightFunction weightFunction = WEIGHT_FUNCTION;
    AvailableNetwork network = new AvailableNetwork();
    addLink(network, SWITCH_1, SWITCH_2, 1, 2, cost, 5, POP_1, POP_2);
    addLink(network, SWITCH_1, SWITCH_3, 2, 1, cost, 5, POP_1, POP_4);
    addLink(network, SWITCH_1, SWITCH_4, 3, 1, cost, 5, POP_1, POP_4);
    addLink(network, SWITCH_5, SWITCH_4, 1, 2, cost, 5, POP_3, POP_4);
    addLink(network, SWITCH_5, SWITCH_3, 2, 2, cost, 5, POP_3, POP_4);
    addLink(network, SWITCH_5, SWITCH_2, 3, 2, cost, 5, POP_3, POP_2);
    network.processDiversitySegmentsWithPop(asList(buildPathWithSegment(SWITCH_1, SWITCH_3, 2, 1, POP_1, POP_4, 0), buildPathWithSegment(SWITCH_3, SWITCH_5, 2, 2, POP_4, POP_3, 1)));
    long expectedWeight = cost + 1000L;
    for (Edge edge : network.edges) {
        long currentWeight = weightFunction.apply(edge).toLong();
        if (edge.getSrcSwitch().getPop().equals(POP_4) || edge.getDestSwitch().getPop().equals(POP_4)) {
            assertEquals(expectedWeight, currentWeight);
        } else {
            assertEquals(cost, currentWeight);
        }
    }
}
Also used : WeightFunction(org.openkilda.pce.model.WeightFunction) Edge(org.openkilda.pce.model.Edge) Test(org.junit.Test)

Example 9 with Edge

use of org.openkilda.pce.model.Edge in project open-kilda by telstra.

the class AvailableNetworkTest method shouldNotUpdateWeightsWhenTransitSegmentsOnlyInPop.

@Test
public void shouldNotUpdateWeightsWhenTransitSegmentsOnlyInPop() {
    int cost = 700;
    final WeightFunction weightFunction = WEIGHT_FUNCTION;
    AvailableNetwork network = new AvailableNetwork();
    addLink(network, SWITCH_1, SWITCH_2, 1, 2, cost, 5, null, null);
    addLink(network, SWITCH_1, SWITCH_3, 2, 1, cost, 5, null, POP_4);
    addLink(network, SWITCH_1, SWITCH_4, 3, 1, cost, 5, null, null);
    addLink(network, SWITCH_5, SWITCH_4, 1, 2, cost, 5, null, null);
    addLink(network, SWITCH_5, SWITCH_3, 2, 2, cost, 5, null, POP_4);
    addLink(network, SWITCH_5, SWITCH_2, 3, 2, cost, 5, null, null);
    network.processDiversitySegmentsWithPop(asList(buildPathWithSegment(SWITCH_1, SWITCH_3, 2, 1, POP_1, null, 0), buildPathWithSegment(SWITCH_3, SWITCH_5, 2, 2, null, POP_3, 1)));
    for (Edge edge : network.edges) {
        long currentWeight = weightFunction.apply(edge).toLong();
        assertEquals(cost, currentWeight);
    }
}
Also used : WeightFunction(org.openkilda.pce.model.WeightFunction) Edge(org.openkilda.pce.model.Edge) Test(org.junit.Test)

Example 10 with Edge

use of org.openkilda.pce.model.Edge in project open-kilda by telstra.

the class BestWeightAndShortestPathFinder method isPathValid.

/**
 * This helper function is used with getReversePath(hint) to confirm the hint path exists.
 */
private boolean isPathValid(List<Edge> path) {
    boolean validPath = true;
    for (Edge i : path) {
        Node srcSwitch = i.getSrcSwitch();
        Set<Edge> pathsToDst = srcSwitch.getOutgoingLinks().stream().filter(link -> link.getDestSwitch().equals(i.getDestSwitch())).collect(toSet());
        if (pathsToDst.isEmpty()) {
            log.debug("No ISLS from {} to {}", i.getSrcSwitch(), i.getDestSwitch());
        }
        boolean foundThisOne = false;
        for (Edge orig : pathsToDst) {
            if (i.getSrcSwitch().getSwitchId().equals(orig.getSrcSwitch().getSwitchId()) && i.getSrcPort() == orig.getSrcPort() && i.getDestSwitch().getSwitchId().equals(orig.getDestSwitch().getSwitchId()) && i.getDestPort() == orig.getDestPort()) {
                foundThisOne = true;
                // stop looking, we found the Edge
                break;
            }
        }
        if (!foundThisOne) {
            validPath = false;
            // found an Edge that doesn't exist, stop looking for others
            break;
        }
    }
    return validPath;
}
Also used : HashMap(java.util.HashMap) Deque(java.util.Deque) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Value(lombok.Value) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Edge(org.openkilda.pce.model.Edge) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) Node(org.openkilda.pce.model.Node) Map(java.util.Map) LinkedList(java.util.LinkedList) Collectors.toSet(java.util.stream.Collectors.toSet) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) LinkedHashSet(java.util.LinkedHashSet) PathWeight(org.openkilda.pce.model.PathWeight) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) WeightFunction(org.openkilda.pce.model.WeightFunction) Objects(java.util.Objects) FindOneDirectionPathResult(org.openkilda.pce.model.FindOneDirectionPathResult) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FindPathResult(org.openkilda.pce.model.FindPathResult) Comparator(java.util.Comparator) Node(org.openkilda.pce.model.Node) Edge(org.openkilda.pce.model.Edge)

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