use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.
the class IslServiceImplTest method discoverIsl.
@Test
public void discoverIsl() throws Exception {
PathNode srcNode = new PathNode(srcSwitchId, 1, 0);
PathNode dstNode = new PathNode(dstSwitchId, 1, 1);
List<PathNode> list = new ArrayList<>();
list.add(srcNode);
list.add(dstNode);
IslInfoData forwardIsl = new IslInfoData(100L, list, 10000000L);
islService.discoverLink(forwardIsl);
Isl isl = islService.getLink(forwardIsl);
assertNotNull(isl);
assertEquals(100L, isl.getLatency());
}
use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.
the class IslServiceImplTest method dropIsl.
@Test
public void dropIsl() throws Exception {
PathNode srcNode = new PathNode(srcSwitchId, 1, 0);
PathNode dstNode = new PathNode(dstSwitchId, 1, 1);
List<PathNode> list = new ArrayList<>();
list.add(srcNode);
list.add(dstNode);
IslInfoData forwardIsl = new IslInfoData(100L, list, 10000000L);
islService.discoverLink(forwardIsl);
Isl isl = islService.getLink(forwardIsl);
assertNotNull(isl);
assertEquals(100L, isl.getLatency());
islService.dropLink(forwardIsl);
isl = islService.getLink(forwardIsl);
assertNull(isl);
}
use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.
the class OFEMessageUtils method createIslFail.
public static String createIslFail(String switchId, String portId) throws IOException {
PathNode node = new PathNode(switchId, Integer.parseInt(portId), 0, 0L);
InfoData data = new IslInfoData(0L, Collections.singletonList(node), 0L, IslChangeType.FAILED, 0L);
InfoMessage message = new InfoMessage(data, System.currentTimeMillis(), UUID.randomUUID().toString());
return MAPPER.writeValueAsString(message);
}
use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.
the class OFELinkBolt method doWork.
@Override
protected void doWork(Tuple tuple) {
if (CtrlAction.boltHandlerEntrance(this, tuple))
return;
//
// (crimi) - commenting out the filter code until we re-evaluate the design. Also, this code
// should probably be embedded in "handleIslEvent"
// /*
// * Check whether ISL Filter needs to be engaged.
// */
// String source = tuple.getSourceComponent();
// if (source.equals(OFEventWFMTopology.SPOUT_ID_INPUT)) {
// PopulateIslFilterAction action = new PopulateIslFilterAction(this, tuple, islFilter);
// action.run();
// return;
// }
String json = tuple.getString(0);
try {
BaseMessage bm = MAPPER.readValue(json, BaseMessage.class);
watchDog.reset();
if (bm instanceof InfoMessage) {
InfoData data = ((InfoMessage) bm).getData();
if (data instanceof NetworkInfoData) {
handleNetworkDump(tuple, (NetworkInfoData) data);
isReceivedCacheInfo = true;
} else if (!isReceivedCacheInfo) {
logger.debug("Bolt is not initialized mark tuple as fail");
} else if (data instanceof SwitchInfoData) {
handleSwitchEvent(tuple, (SwitchInfoData) data);
passToTopologyEngine(tuple);
} else if (data instanceof PortInfoData) {
handlePortEvent(tuple, (PortInfoData) data);
passToTopologyEngine(tuple);
} else if (data instanceof IslInfoData) {
handleIslEvent(tuple, (IslInfoData) data);
} else {
logger.warn("Unknown InfoData type={}", data);
}
} else if (bm instanceof HeartBeat) {
logger.debug("Got speaker's heart beat");
}
} catch (IOException e) {
// All messages should be derived from BaseMessage .. so an exception here
// means that we found something that isn't. If this criteria changes, then
// change the logger level.
logger.error("Unknown Message type={}", json);
} finally {
// We mark as fail all tuples while bolt is not initialized
if (isReceivedCacheInfo) {
collector.ack(tuple);
} else {
collector.fail(tuple);
}
}
}
use of org.openkilda.messaging.info.event.IslInfoData 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;
}
Aggregations