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;
}
use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.
the class AbstractSerializerTest method eventIslInfoTest.
@Test
public void eventIslInfoTest() throws IOException, ClassNotFoundException {
PathNode payload = new PathNode(SWITCH_ID, INPUT_PORT, 0);
IslInfoData data = new IslInfoData(0L, Collections.singletonList(payload), 1000000L, IslChangeType.DISCOVERED, 900000L);
assertEquals(SWITCH_ID + "_" + String.valueOf(INPUT_PORT), data.getId());
System.out.println(data);
InfoMessage info = new InfoMessage(data, System.currentTimeMillis(), CORRELATION_ID, DESTINATION);
serialize(info);
Message message = (Message) deserialize();
assertTrue(message instanceof InfoMessage);
InfoMessage resultInfo = (InfoMessage) message;
assertTrue(resultInfo.getData() instanceof IslInfoData);
IslInfoData resultData = (IslInfoData) resultInfo.getData();
System.out.println(resultData);
assertEquals(data, resultData);
assertEquals(data.hashCode(), resultData.hashCode());
assertEquals(payload.hashCode(), resultData.getPath().get(0).hashCode());
}
use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.
the class FlowCacheTest method buildNetworkTopology.
private void buildNetworkTopology(NetworkCache networkCache) {
networkCache.createSwitch(NetworkTopologyConstants.sw1);
networkCache.createSwitch(NetworkTopologyConstants.sw2);
networkCache.createSwitch(NetworkTopologyConstants.sw3);
networkCache.createSwitch(NetworkTopologyConstants.sw4);
networkCache.createSwitch(NetworkTopologyConstants.sw5);
networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl12));
networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl21));
networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl24));
networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl42));
networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl52));
networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl25));
networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl53));
networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl35));
networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl54));
networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl45));
}
Aggregations