Search in sources :

Example 11 with PathNode

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));
}
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)

Example 12 with PathNode

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());
}
Also used : Isl(org.openkilda.topology.domain.Isl) ArrayList(java.util.ArrayList) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 13 with PathNode

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());
}
Also used : Isl(org.openkilda.topology.domain.Isl) ArrayList(java.util.ArrayList) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 14 with PathNode

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);
}
Also used : Isl(org.openkilda.topology.domain.Isl) ArrayList(java.util.ArrayList) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 15 with PathNode

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);
}
Also used : IslInfoData(org.openkilda.messaging.info.event.IslInfoData) InfoData(org.openkilda.messaging.info.InfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode)

Aggregations

PathNode (org.openkilda.messaging.info.event.PathNode)26 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)14 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 Isl (org.openkilda.topology.domain.Isl)7 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)6 CommandMessage (org.openkilda.messaging.command.CommandMessage)5 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)4 HashSet (java.util.HashSet)3 InfoMessage (org.openkilda.messaging.info.InfoMessage)3 Then (cucumber.api.java.en.Then)2 Set (java.util.Set)2 Message (org.openkilda.messaging.Message)2 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)2 InfoData (org.openkilda.messaging.info.InfoData)2 ImmutablePair (org.openkilda.messaging.model.ImmutablePair)2 Switch (org.openkilda.topology.domain.Switch)2 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)2 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)1 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1