Search in sources :

Example 16 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class AbstractSerializerTest method eventPathInfoTest.

@Test
public void eventPathInfoTest() throws IOException, ClassNotFoundException {
    PathInfoData data = new PathInfoData();
    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 PathInfoData);
    PathInfoData resultData = (PathInfoData) resultInfo.getData();
    System.out.println(resultData);
    assertEquals(data, resultData);
    assertEquals(data.hashCode(), resultData.hashCode());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) Test(org.junit.Test)

Example 17 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData 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 18 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class FlowCacheTest method createFlow.

@Test
public void createFlow() throws Exception {
    ImmutablePair<PathInfoData, PathInfoData> path = computer.getPath(firstFlow, defaultStrategy);
    ImmutablePair<Flow, Flow> newFlow = flowCache.createFlow(firstFlow, path);
    Flow forward = newFlow.left;
    assertEquals(1 | ResourceCache.FORWARD_FLOW_COOKIE_MASK, forward.getCookie());
    assertEquals(2, forward.getTransitVlan());
    assertEquals(1, forward.getMeterId());
    assertEquals(path.getLeft(), forward.getFlowPath());
    Flow reverse = newFlow.right;
    assertEquals(1 | ResourceCache.REVERSE_FLOW_COOKIE_MASK, reverse.getCookie());
    assertEquals(3, reverse.getTransitVlan());
    assertEquals(1, reverse.getMeterId());
    assertEquals(path.getRight(), reverse.getFlowPath());
    assertEquals(1, flowCache.dumpFlows().size());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) Flow(org.openkilda.messaging.model.Flow) Test(org.junit.Test)

Example 19 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class FlowTopologyTest method pathFlowCommand.

private PathInfoData pathFlowCommand(final String flowId) throws IOException {
    System.out.println("TOPOLOGY: Path flow");
    PathInfoData payload = new PathInfoData(0L, Collections.singletonList(new PathNode("test-switch", 1, 0, null)));
    FlowPathResponse infoData = new FlowPathResponse(payload);
    InfoMessage infoMessage = new InfoMessage(infoData, 0, "path-flow", Destination.WFM);
    sendTopologyEngineMessage(infoMessage);
    return payload;
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowPathResponse(org.openkilda.messaging.info.flow.FlowPathResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) PathNode(org.openkilda.messaging.info.event.PathNode)

Example 20 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class FlowTopologyTest method getPathTopologyEngineBoltTest.

@Test
@Ignore
public void getPathTopologyEngineBoltTest() throws Exception {
    ConsumerRecord<String, String> nbRecord;
    String flowId = UUID.randomUUID().toString();
    PathInfoData payload = pathFlowCommand(flowId);
    nbRecord = nbConsumer.pollMessage();
    assertNotNull(nbRecord);
    assertNotNull(nbRecord.value());
    InfoMessage response = objectMapper.readValue(nbRecord.value(), InfoMessage.class);
    assertNotNull(response);
    FlowPathResponse responseData = (FlowPathResponse) response.getData();
    assertNotNull(responseData);
    assertEquals(payload, responseData.getPayload());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowPathResponse(org.openkilda.messaging.info.flow.FlowPathResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) Ignore(org.junit.Ignore) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Aggregations

PathInfoData (org.openkilda.messaging.info.event.PathInfoData)27 Flow (org.openkilda.messaging.model.Flow)13 Test (org.junit.Test)12 InfoMessage (org.openkilda.messaging.info.InfoMessage)8 PathNode (org.openkilda.messaging.info.event.PathNode)6 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)5 Values (org.apache.storm.tuple.Values)4 Driver (org.neo4j.driver.v1.Driver)4 MessageException (org.openkilda.messaging.error.MessageException)4 ImmutablePair (org.openkilda.messaging.model.ImmutablePair)4 UnroutablePathException (org.openkilda.pce.provider.UnroutablePathException)4 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)4 ArrayList (java.util.ArrayList)3 CommandMessage (org.openkilda.messaging.command.CommandMessage)3 FlowPathResponse (org.openkilda.messaging.info.flow.FlowPathResponse)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)2 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)2 FlowValidationException (org.openkilda.wfm.topology.flow.validation.FlowValidationException)2