Search in sources :

Example 31 with Edge

use of org.openkilda.pce.model.Edge 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)

Example 32 with Edge

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

the class AvailableNetworkTest method shouldFillAffinityWeights.

@Test
public void shouldFillAffinityWeights() {
    AvailableNetwork network = new AvailableNetwork();
    addLink(network, SRC_SWITCH, DST_SWITCH, 7, 60, 10, 3);
    addLink(network, SRC_SWITCH, DST_SWITCH, 8, 61, 10, 3);
    addLink(network, SRC_SWITCH, DST_SWITCH, 9, 62, 10, 3);
    network.processAffinitySegments(singletonList(buildPathSegment(SRC_SWITCH, DST_SWITCH, 7, 60, 0)));
    Node srcSwitch = network.getSwitch(SRC_SWITCH);
    for (Edge edge : srcSwitch.getOutgoingLinks()) {
        if (edge.getSrcPort() == 7) {
            assertEquals(0, edge.getAffinityGroupUseCounter());
            continue;
        }
        assertEquals(1, edge.getAffinityGroupUseCounter());
    }
}
Also used : Node(org.openkilda.pce.model.Node) Edge(org.openkilda.pce.model.Edge) Test(org.junit.Test)

Example 33 with Edge

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

the class AvailableNetworkTest method shouldNotUpdateWeightsWhenTransitSegmentsNotInPop.

@Test
public void shouldNotUpdateWeightsWhenTransitSegmentsNotInPop() {
    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, null);
    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, null);
    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, 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 34 with Edge

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

the class AvailableNetworkTest method shouldFillDiversityWeightsIngress.

@Test
public void shouldFillDiversityWeightsIngress() {
    AvailableNetwork network = new AvailableNetwork();
    addLink(network, SRC_SWITCH, DST_SWITCH, 7, 60, 10, 3);
    network.processDiversitySegments(singletonList(buildPathSegment(SRC_SWITCH, DST_SWITCH, 7, 60, 0)), DUMMY_FLOW);
    Node srcSwitch = network.getSwitch(SRC_SWITCH);
    Edge edge = srcSwitch.getOutgoingLinks().iterator().next();
    assertEquals(1, edge.getDiversityGroupUseCounter());
    assertEquals(1, edge.getDestSwitch().getDiversityGroupUseCounter());
}
Also used : Node(org.openkilda.pce.model.Node) Edge(org.openkilda.pce.model.Edge) Test(org.junit.Test)

Example 35 with Edge

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

the class AvailableNetworkTest method shouldSetEqualCostForPairedLinks.

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

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