Search in sources :

Example 71 with InfoMessage

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

the class FlowTopologyTest method installFlowTopologyEngineSpeakerBoltTest.

@Test
public void installFlowTopologyEngineSpeakerBoltTest() throws Exception {
    /*
         * This test will verify the state transitions of a flow, through the status mechanism.
         * It achieves this by doing the following:
         *      - CreateFlow .. clear both cache and northbound consumers
         *      - GetStatus .. confirm STATE = FlowState.ALLOCATED
         *      - baseInstallFlowCommand .. read speaker .. validate data/responsedata
         *      - GetStatus .. confirm STATE = FlowState.IN_PROGRESS
         *      - baseInstallRuleCommand ..
         *      - GetStatus .. confirm STATE = FlowState.UP
         */
    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());
    statusFlow(flowId);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    InfoMessage infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
    assertNotNull(infoMessage);
    FlowStatusResponse infoData = (FlowStatusResponse) infoMessage.getData();
    assertNotNull(infoData);
    FlowIdStatusPayload flowNbPayload = infoData.getPayload();
    assertNotNull(flowNbPayload);
    assertEquals(flowId, flowNbPayload.getId());
    assertEquals(FlowState.ALLOCATED, flowNbPayload.getStatus());
    InstallOneSwitchFlow data = baseInstallFlowCommand(flowId);
    record = ofsConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    CommandMessage response = objectMapper.readValue(record.value(), CommandMessage.class);
    assertNotNull(response);
    InstallOneSwitchFlow responseData = (InstallOneSwitchFlow) response.getData();
    Long transactionId = responseData.getTransactionId();
    responseData.setTransactionId(0L);
    assertEquals(data, responseData);
    responseData.setTransactionId(transactionId);
    statusFlow(flowId);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
    assertNotNull(infoMessage);
    infoData = (FlowStatusResponse) infoMessage.getData();
    assertNotNull(infoData);
    flowNbPayload = infoData.getPayload();
    assertNotNull(flowNbPayload);
    assertEquals(flowId, flowNbPayload.getId());
    assertEquals(FlowState.IN_PROGRESS, flowNbPayload.getStatus());
    response.setDestination(Destination.WFM_TRANSACTION);
    baseInstallRuleCommand(response);
    statusFlow(flowId);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
    assertNotNull(infoMessage);
    infoData = (FlowStatusResponse) infoMessage.getData();
    assertNotNull(infoData);
    flowNbPayload = infoData.getPayload();
    assertNotNull(flowNbPayload);
    assertEquals(flowId, flowNbPayload.getId());
    assertEquals(FlowState.UP, flowNbPayload.getStatus());
}
Also used : FlowStatusResponse(org.openkilda.messaging.info.flow.FlowStatusResponse) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) InfoMessage(org.openkilda.messaging.info.InfoMessage) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) CommandMessage(org.openkilda.messaging.command.CommandMessage) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 72 with InfoMessage

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

the class FlowTopologyTest method dumpFlowsTest.

@Test
public void dumpFlowsTest() 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());
    dumpFlows(null);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    InfoMessage infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
    FlowsResponse infoData = (FlowsResponse) infoMessage.getData();
    assertNotNull(infoData);
    assertNotNull(infoData.getPayload());
    assertFalse(infoData.getPayload().isEmpty());
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowsResponse(org.openkilda.messaging.info.flow.FlowsResponse) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 73 with InfoMessage

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

the class FlowTopologyTest method createFlowCommandBoltTest.

@Test
public void createFlowCommandBoltTest() throws Exception {
    ConsumerRecord<String, String> record;
    String flowId = UUID.randomUUID().toString();
    createFlow(flowId);
    record = cacheConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    InfoMessage message = objectMapper.readValue(record.value(), InfoMessage.class);
    ImmutablePair<Flow, Flow> flow = getFlowPayload(message);
    assertNotNull(flow);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    InfoMessage infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
    FlowResponse response = (FlowResponse) infoMessage.getData();
    assertNotNull(response);
}
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 74 with InfoMessage

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

the class FlowTopologyTest method dumpFlowCommand.

private List<Flow> dumpFlowCommand(final String flowId) throws IOException {
    System.out.println("TOPOLOGY: Get flows");
    Flow flow = new Flow(flowId, 10000, false, "", "test-switch", 1, 2, "test-switch", 1, 2);
    List<Flow> payload = Collections.singletonList(flow);
    FlowsResponse infoData = new FlowsResponse(payload);
    InfoMessage infoMessage = new InfoMessage(infoData, 0, "dump-flows", Destination.WFM);
    sendTopologyEngineMessage(infoMessage);
    return payload;
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowsResponse(org.openkilda.messaging.info.flow.FlowsResponse) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) Flow(org.openkilda.messaging.model.Flow) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow)

Example 75 with InfoMessage

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

the class StatsTopologyTest method flowStatsTest.

@Test
public void flowStatsTest() throws Exception {
    List<FlowStatsEntry> entries = Collections.singletonList(new FlowStatsEntry((short) 1, cookie, 1500L, 3000L));
    final List<FlowStatsReply> stats = Collections.singletonList(new FlowStatsReply(3, entries));
    InfoMessage message = new InfoMessage(new FlowStatsData(switchId, stats), timestamp, CORRELATION_ID, Destination.WFM_STATS);
    // mock kafka spout
    MockedSources sources = new MockedSources();
    sources.addMockData(StatsComponentType.STATS_OFS_KAFKA_SPOUT.toString(), new Values(MAPPER.writeValueAsString(message)));
    completeTopologyParam.setMockedSources(sources);
    // execute topology
    Testing.withTrackedCluster(clusterParam, (cluster) -> {
        StatsTopology topology = new TestingTargetTopology(new TestingKafkaBolt());
        StormTopology stormTopology = topology.createTopology();
        Map result = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
        // verify results which were sent to Kafka bolt
        ArrayList<FixedTuple> tuples = (ArrayList<FixedTuple>) result.get(StatsComponentType.FLOW_STATS_METRIC_GEN.name());
        assertThat(tuples.size(), is(6));
        tuples.stream().map(this::readFromJson).forEach(datapoint -> {
            if (datapoint.getMetric().equals("pen.flow.packets")) {
                assertThat(datapoint.getTags().get("direction"), is("forward"));
            }
            assertThat(datapoint.getTags().get("flowid"), is(flowId));
            assertThat(datapoint.getTime(), is(timestamp));
        });
    });
}
Also used : StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) TestingKafkaBolt(org.openkilda.wfm.topology.TestingKafkaBolt) FixedTuple(org.apache.storm.testing.FixedTuple) FlowStatsReply(org.openkilda.messaging.info.stats.FlowStatsReply) MockedSources(org.apache.storm.testing.MockedSources) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) InfoMessage(org.openkilda.messaging.info.InfoMessage) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) Test(org.junit.Test)

Aggregations

InfoMessage (org.openkilda.messaging.info.InfoMessage)87 Test (org.junit.Test)34 Values (org.apache.storm.tuple.Values)27 CommandMessage (org.openkilda.messaging.command.CommandMessage)21 Flow (org.openkilda.messaging.model.Flow)21 Message (org.openkilda.messaging.Message)20 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)19 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)19 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)13 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)12 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)12 IOException (java.io.IOException)9 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)9 ErrorData (org.openkilda.messaging.error.ErrorData)8 InfoData (org.openkilda.messaging.info.InfoData)8 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)8 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)8 FlowStatusResponse (org.openkilda.messaging.info.flow.FlowStatusResponse)8 NetworkInfoData (org.openkilda.messaging.info.discovery.NetworkInfoData)7 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)7