Search in sources :

Example 16 with Flow

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);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) Flow(org.openkilda.messaging.model.Flow) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 17 with Flow

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();
    }
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) ArrayList(java.util.ArrayList) DefaultParameters.topologyEndpoint(org.openkilda.DefaultParameters.topologyEndpoint) DefaultParameters.northboundEndpoint(org.openkilda.DefaultParameters.northboundEndpoint) UnroutablePathException(org.openkilda.pce.provider.UnroutablePathException) TopologyProcessingException(org.openkilda.topo.exceptions.TopologyProcessingException) IOException(java.io.IOException) HashSet(java.util.HashSet) Flow(org.openkilda.messaging.model.Flow)

Example 18 with Flow

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

Example 19 with Flow

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

Example 20 with Flow

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

Aggregations

Flow (org.openkilda.messaging.model.Flow)54 InfoMessage (org.openkilda.messaging.info.InfoMessage)23 Values (org.apache.storm.tuple.Values)14 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)14 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)13 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)13 Test (org.junit.Test)12 CommandMessage (org.openkilda.messaging.command.CommandMessage)8 ImmutablePair (org.openkilda.messaging.model.ImmutablePair)8 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)8 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)6 Then (cucumber.api.java.en.Then)5 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)5 UnroutablePathException (org.openkilda.pce.provider.UnroutablePathException)5 Driver (org.neo4j.driver.v1.Driver)4 MessageException (org.openkilda.messaging.error.MessageException)4 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)4 And (cucumber.api.java.en.And)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3