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