use of org.neo4j.driver.v1.types.Path in project open-kilda by telstra.
the class PathComputerTest method testGetPathByCostActive.
@Test
public void testGetPathByCostActive() throws UnroutablePathException {
/*
* simple happy path test .. everything has cost
*/
createDiamond("active", 10, 20);
Driver driver = GraphDatabase.driver("bolt://localhost:7878", AuthTokens.basic("neo4j", "password"));
NeoDriver nd = new NeoDriver(driver);
Flow f = new Flow();
f.setSourceSwitch("00:01");
f.setDestinationSwitch("00:04");
f.setBandwidth(100);
ImmutablePair<PathInfoData, PathInfoData> path = nd.getPath(f, PathComputer.Strategy.COST);
// System.out.println("path = " + path);
Assert.assertNotNull(path);
Assert.assertEquals(4, path.left.getPath().size());
// chooses path B
Assert.assertEquals("00:02", path.left.getPath().get(1).getSwitchId());
}
use of org.neo4j.driver.v1.types.Path in project open-kilda by telstra.
the class PathComputerTest method testGetPathByCostNoCost.
@Test
public void testGetPathByCostNoCost() throws UnroutablePathException {
/*
* simple happy path test .. but pathB has no cost .. but still cheaper than pathC (test the default)
*/
createDiamond("active", -1, 2000);
Driver driver = GraphDatabase.driver("bolt://localhost:7878", AuthTokens.basic("neo4j", "password"));
NeoDriver nd = new NeoDriver(driver);
Flow f = new Flow();
f.setSourceSwitch("00:01");
f.setDestinationSwitch("00:04");
f.setBandwidth(100);
ImmutablePair<PathInfoData, PathInfoData> path = nd.getPath(f, PathComputer.Strategy.COST);
// System.out.println("path = " + path);
Assert.assertNotNull(path);
Assert.assertEquals(4, path.left.getPath().size());
// ====> Should choose B .. because default cost (700) cheaper than 2000
// chooses path B
Assert.assertEquals("00:02", path.left.getPath().get(1).getSwitchId());
}
use of org.neo4j.driver.v1.types.Path in project open-kilda by telstra.
the class PathComputerTest method testGetPathByCostInactive.
@Test
public void testGetPathByCostInactive() throws UnroutablePathException {
/*
* simple happy path test .. but lowest path is inactive
*/
createDiamond("inactive", 10, 20);
Driver driver = GraphDatabase.driver("bolt://localhost:7878", AuthTokens.basic("neo4j", "password"));
NeoDriver nd = new NeoDriver(driver);
Flow f = new Flow();
f.setSourceSwitch("00:01");
f.setDestinationSwitch("00:04");
f.setBandwidth(100);
ImmutablePair<PathInfoData, PathInfoData> path = nd.getPath(f, PathComputer.Strategy.COST);
// System.out.println("path = " + path);
Assert.assertNotNull(path);
Assert.assertEquals(4, path.left.getPath().size());
// ====> only difference is it should now have C as first hop .. since B is inactive
// chooses path B
Assert.assertEquals("00:03", path.left.getPath().get(1).getSwitchId());
}
use of org.neo4j.driver.v1.types.Path in project open-kilda by telstra.
the class PathComputerTest method testGetPathByCostInactiveOnTriangleTopo.
@Test
public void testGetPathByCostInactiveOnTriangleTopo() throws UnroutablePathException {
/*
* simple happy path test .. but lowest path is inactive
*/
createTriangleTopo("inactive", 10, 20);
Driver driver = GraphDatabase.driver("bolt://localhost:7878", AuthTokens.basic("neo4j", "password"));
NeoDriver nd = new NeoDriver(driver);
Flow f = new Flow();
f.setSourceSwitch("00:01");
f.setDestinationSwitch("00:02");
f.setBandwidth(100);
ImmutablePair<PathInfoData, PathInfoData> path = nd.getPath(f, PathComputer.Strategy.COST);
// System.out.println("path = " + path);
Assert.assertNotNull(path);
Assert.assertEquals(4, path.left.getPath().size());
// ====> only difference is it should now have C as first hop .. since B is inactive
// chooses path B
Assert.assertEquals("00:03", path.left.getPath().get(1).getSwitchId());
}
use of org.neo4j.driver.v1.types.Path 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));
}
Aggregations