Search in sources :

Example 1 with Path

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());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) Driver(org.neo4j.driver.v1.Driver) Flow(org.openkilda.messaging.model.Flow)

Example 2 with Path

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());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) Driver(org.neo4j.driver.v1.Driver) Flow(org.openkilda.messaging.model.Flow)

Example 3 with Path

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());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) Driver(org.neo4j.driver.v1.Driver) Flow(org.openkilda.messaging.model.Flow)

Example 4 with Path

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());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) Driver(org.neo4j.driver.v1.Driver) Flow(org.openkilda.messaging.model.Flow)

Example 5 with Path

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));
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Statement(org.neo4j.driver.v1.Statement) PathNode(org.openkilda.messaging.info.event.PathNode) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Relationship(org.neo4j.driver.v1.types.Relationship) Record(org.neo4j.driver.v1.Record) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException) Session(org.neo4j.driver.v1.Session)

Aggregations

Driver (org.neo4j.driver.v1.Driver)5 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)5 Flow (org.openkilda.messaging.model.Flow)4 Record (org.neo4j.driver.v1.Record)2 Session (org.neo4j.driver.v1.Session)2 StatementResult (org.neo4j.driver.v1.StatementResult)2 Relationship (org.neo4j.driver.v1.types.Relationship)2 Test (org.junit.Test)1 Statement (org.neo4j.driver.v1.Statement)1 NoSuchRecordException (org.neo4j.driver.v1.exceptions.NoSuchRecordException)1 Node (org.neo4j.driver.v1.types.Node)1 Path (org.neo4j.driver.v1.types.Path)1 PathNode (org.openkilda.messaging.info.event.PathNode)1 ImmutablePair (org.openkilda.messaging.model.ImmutablePair)1