use of org.openkilda.messaging.model.Flow in project open-kilda by telstra.
the class FlowTopologyTest method updateFlowCommandBoltTest.
@Test
public void updateFlowCommandBoltTest() throws Exception {
String flowId = UUID.randomUUID().toString();
ConsumerRecord<String, String> record;
createFlow(flowId);
record = cacheConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
updateFlow(flowId);
record = cacheConsumer.pollMessage();
assertNotNull(record);
InfoMessage message = objectMapper.readValue(record.value(), InfoMessage.class);
assertNotNull(message);
ImmutablePair<Flow, Flow> flow = getFlowPayload(message);
assertNotNull(flow);
Flow flowTePayload = flow.getLeft();
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
InfoMessage infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
FlowResponse payload = (FlowResponse) infoMessage.getData();
assertNotNull(payload);
Flow flowNbPayload = payload.getPayload();
assertEquals(flowNbPayload, flowTePayload);
}
use of org.openkilda.messaging.model.Flow in project open-kilda by telstra.
the class FlowUtils method cleanupFlows.
/**
* Cleanups all flows.
*/
public static void cleanupFlows() {
try {
Set<String> flows = new HashSet<>();
// TODO: This method started with getting counts and compariing, but that shouldn't be
// the responsibility of this method given its name - cleanupFlows.
// So, the TODO is to determine whether this code exists elsewhere in tests,
// and if not, move it somewhere after, or part of, create test.
// Get the flows through the NB API
List<FlowPayload> nbFlows = getFlowDump();
System.out.println(format("=====> Cleanup Flows, nbflow count = %d", nbFlows.size()));
nbFlows.forEach(flow -> flows.add(flow.getId()));
// Get the flows through the TE Rest API ... loop until the math works out.
List<Flow> tpeFlows = new ArrayList<>();
for (int i = 0; i < 10; ++i) {
tpeFlows = dumpFlows();
if (tpeFlows.size() == nbFlows.size() * 2) {
tpeFlows.forEach(flow -> flows.add(flow.getFlowId()));
break;
}
TimeUnit.SECONDS.sleep(2);
}
System.out.println(format("=====> Cleanup Flows, tpeFlows count = %d", tpeFlows.size()));
// Delete all the flows
flows.forEach(FlowUtils::deleteFlow);
// Wait for them to become zero
int nb_count = -1;
int ter_count = -1;
for (int i = 0; i < 10; ++i) {
TimeUnit.SECONDS.sleep(2);
nb_count = dumpFlows().size();
ter_count = getFlowDump().size();
if (nb_count == 0 && ter_count == 0) {
break;
}
}
assertEquals(0, nb_count);
assertEquals(0, ter_count);
// (crimi) - it is unclear why we are doing a count validation here .. it makes sense to do this
// in the creation. But on cleanup, we just want things to be zero.
// assertEquals(nbFlows.size() * 2, tpeFlows.size());
// assertEquals(nbFlows.size(), flows.size());
} catch (Exception exception) {
System.out.println(format("Error during flow deletion: %s", exception.getMessage()));
exception.printStackTrace();
}
}
use of org.openkilda.messaging.model.Flow 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.openkilda.messaging.model.Flow 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.openkilda.messaging.model.Flow 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());
}
Aggregations