use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.
the class OFELinkBolt method handleIslEvent.
private void handleIslEvent(Tuple tuple, IslInfoData discoveredIsl) {
PathNode node = discoveredIsl.getPath().get(0);
String switchID = node.getSwitchId();
String portID = "" + node.getPortNo();
IslChangeType state = discoveredIsl.getState();
boolean stateChanged = false;
/*
* TODO: would be good to merge more of this behavior / business logic within DiscoveryManager
* The reason is so that we consolidate behavior related to Network Topology Discovery into
* one place.
*/
if (IslChangeType.DISCOVERED.equals(state)) {
stateChanged = discovery.handleDiscovered(switchID, portID);
// sure we can test the other side as well.
if (stateChanged && discoveredIsl.getPath().size() > 1) {
String dstSwitch = discoveredIsl.getPath().get(0).getSwitchId();
String dstPort = "" + discoveredIsl.getPath().get(0).getPortNo();
if (!discovery.checkForIsl(dstSwitch, dstPort)) {
// Only call PortUp if we aren't checking for ISL. Otherwise, we could end up in an
// infinite cycle of always sending a Port UP when one side is discovered.
discovery.handlePortUp(dstSwitch, dstPort);
}
}
} else if (IslChangeType.FAILED.equals(state)) {
stateChanged = discovery.handleFailed(switchID, portID);
} else {
// TODO: Should this be a warning? Evaluate whether any other state needs to be handled
logger.warn("ISL Event: ignoring state: {}", state);
}
if (stateChanged) {
// If the state changed, notify the TE.
logger.info("DISCO: ISL Event: switch={} port={} state={}", switchID, portID, state);
passToTopologyEngine(tuple);
}
}
use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.
the class FlowTopologyTest method pathFlowCommand.
private PathInfoData pathFlowCommand(final String flowId) throws IOException {
System.out.println("TOPOLOGY: Path flow");
PathInfoData payload = new PathInfoData(0L, Collections.singletonList(new PathNode("test-switch", 1, 0, null)));
FlowPathResponse infoData = new FlowPathResponse(payload);
InfoMessage infoMessage = new InfoMessage(infoData, 0, "path-flow", Destination.WFM);
sendTopologyEngineMessage(infoMessage);
return payload;
}
use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.
the class PathComputerMock method path.
private PathInfoData path(SwitchInfoData srcSwitch, SwitchInfoData dstSwitch, int bandwidth) {
System.out.println("Get Path By Switch Instances " + bandwidth + ": " + srcSwitch + " - " + dstSwitch);
LinkedList<IslInfoData> islInfoDataLinkedList = new LinkedList<>();
List<PathNode> nodes = new ArrayList<>();
PathInfoData path = new PathInfoData(0L, nodes);
if (srcSwitch.equals(dstSwitch)) {
return path;
}
Set<SwitchInfoData> nodesToProcess = new HashSet<>(network.nodes());
Set<SwitchInfoData> nodesWereProcess = new HashSet<>();
Map<SwitchInfoData, ImmutablePair<SwitchInfoData, IslInfoData>> predecessors = new HashMap<>();
Map<SwitchInfoData, Long> distances = network.nodes().stream().collect(Collectors.toMap(k -> k, v -> Long.MAX_VALUE));
distances.put(srcSwitch, 0L);
while (!nodesToProcess.isEmpty()) {
SwitchInfoData source = nodesToProcess.stream().min(Comparator.comparingLong(distances::get)).orElseThrow(() -> new CacheException(ErrorType.NOT_FOUND, "Can not find path", "Error: No nodes to process left"));
nodesToProcess.remove(source);
nodesWereProcess.add(source);
for (SwitchInfoData target : network.successors(source)) {
if (!nodesWereProcess.contains(target)) {
IslInfoData edge = network.edgesConnecting(source, target).stream().filter(isl -> isl.getAvailableBandwidth() >= bandwidth).findFirst().orElseThrow(() -> new CacheException(ErrorType.NOT_FOUND, "Can not find path", "Error: No enough bandwidth"));
Long distance = distances.get(source) + getWeight(edge);
if (distances.get(target) >= distance) {
distances.put(target, distance);
nodesToProcess.add(target);
predecessors.put(target, new ImmutablePair<>(source, edge));
}
}
}
}
ImmutablePair<SwitchInfoData, IslInfoData> nextHop = predecessors.get(dstSwitch);
if (nextHop == null) {
return null;
}
islInfoDataLinkedList.add(nextHop.getRight());
while (predecessors.get(nextHop.getLeft()) != null) {
nextHop = predecessors.get(nextHop.getLeft());
islInfoDataLinkedList.add(nextHop.getRight());
}
Collections.reverse(islInfoDataLinkedList);
int i = 0;
for (IslInfoData isl : islInfoDataLinkedList) {
collect(isl, path, i);
i += 2;
}
updatePathBandwidth(path, bandwidth, islInfoDataLinkedList);
return path;
}
use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.
the class PathComputerMock method collect.
private void collect(IslInfoData isl, PathInfoData path, int seqId) {
PathNode source = new PathNode(isl.getPath().get(0));
source.setSeqId(seqId);
source.setSegLatency(isl.getLatency());
path.getPath().add(source);
PathNode destination = new PathNode(isl.getPath().get(1));
destination.setSeqId(seqId + 1);
path.getPath().add(destination);
path.setLatency(path.getLatency() + isl.getLatency());
}
use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.
the class IslServiceImpl method getLink.
/**
* {@inheritDoc}
*/
@Override
public Isl getLink(final IslInfoData data) {
logger.debug("Isl get: isl={}", data);
PathNode sourceNode = data.getPath().get(0);
PathNode destinationNode = data.getPath().get(1);
Isl isl = islRepository.findIsl(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo());
logger.debug("Isl relationship found: {}", isl);
return isl;
}
Aggregations