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