use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.
the class NeoDriver method getPath.
/**
* {@inheritDoc}
*/
@Override
public ImmutablePair<PathInfoData, PathInfoData> getPath(Flow flow, Strategy strategy) throws UnroutablePathException {
long latency = 0L;
List<PathNode> forwardNodes = new LinkedList<>();
List<PathNode> reverseNodes = new LinkedList<>();
if (!flow.isOneSwitchFlow()) {
Statement statement = getPathQuery(flow, strategy);
logger.debug("QUERY: {}", statement.toString());
try (Session session = driver.session()) {
StatementResult result = session.run(statement);
try {
Record record = result.next();
LinkedList<Relationship> isls = new LinkedList<>();
record.get(0).asPath().relationships().forEach(isls::add);
int seqId = 0;
for (Relationship isl : isls) {
latency += isl.get("latency").asLong();
forwardNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, isl.get("latency").asLong()));
seqId++;
forwardNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, 0L));
seqId++;
}
seqId = 0;
Collections.reverse(isls);
for (Relationship isl : isls) {
reverseNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, isl.get("latency").asLong()));
seqId++;
reverseNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, 0L));
seqId++;
}
} catch (NoSuchRecordException e) {
throw new UnroutablePathException(flow);
}
}
} else {
logger.info("No path computation for one-switch flow");
}
return new ImmutablePair<>(new PathInfoData(latency, forwardNodes), new PathInfoData(latency, reverseNodes));
}
use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.
the class IslServiceImplTest method updateLinkLatency.
@Test
public void updateLinkLatency() 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());
forwardIsl = new IslInfoData(200L, list, 10000000L);
islService.discoverLink(forwardIsl);
isl = islService.getLink(forwardIsl);
assertNotNull(isl);
assertEquals(200L, isl.getLatency());
}
use of org.openkilda.messaging.info.event.PathNode 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.PathNode 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.PathNode 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);
}
Aggregations