Search in sources :

Example 41 with InfoMessage

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

the class RecordHandlerTest method networkDumpTest.

/**
 * Simple TDD test that was used to develop warming mechanism for OFELinkBolt. We create
 * command and put it to KafkaMessageCollector then mock ISwitchManager::getAllSwitchMap and
 * verify that output message comes to producer.
 */
@Test
public void networkDumpTest() {
    // Cook mock data for ISwitchManager::getAllSwitchMap
    // Two switches with two ports on each
    // switches for ISwitchManager::getAllSwitchMap
    OFSwitch iofSwitch1 = mock(OFSwitch.class);
    OFSwitch iofSwitch2 = mock(OFSwitch.class);
    Map<DatapathId, IOFSwitch> switches = ImmutableMap.of(DatapathId.of(1), iofSwitch1, DatapathId.of(2), iofSwitch2);
    for (DatapathId swId : switches.keySet()) {
        IOFSwitch sw = switches.get(swId);
        expect(sw.isActive()).andReturn(true).anyTimes();
        expect(sw.getId()).andReturn(swId).anyTimes();
    }
    expect(switchManager.getAllSwitchMap()).andReturn(switches);
    // ports for OFSwitch::getEnabledPorts
    OFPortDesc ofPortDesc1 = mock(OFPortDesc.class);
    OFPortDesc ofPortDesc2 = mock(OFPortDesc.class);
    OFPortDesc ofPortDesc3 = mock(OFPortDesc.class);
    OFPortDesc ofPortDesc4 = mock(OFPortDesc.class);
    expect(ofPortDesc1.getPortNo()).andReturn(OFPort.ofInt(1));
    expect(ofPortDesc2.getPortNo()).andReturn(OFPort.ofInt(2));
    expect(ofPortDesc3.getPortNo()).andReturn(OFPort.ofInt(3));
    expect(ofPortDesc4.getPortNo()).andReturn(OFPort.ofInt(4));
    expect(iofSwitch1.getEnabledPorts()).andReturn(ImmutableList.of(ofPortDesc1, ofPortDesc2));
    expect(iofSwitch2.getEnabledPorts()).andReturn(ImmutableList.of(ofPortDesc3, ofPortDesc4));
    // Logic in SwitchEventCollector.buildSwitchInfoData is too complicated and requires a lot
    // of mocking code so I replaced it with mock on kafkaMessageCollector.buildSwitchInfoData
    handler.overrideSwitchInfoData(DatapathId.of(1), new SwitchInfoData("sw1", SwitchState.ADDED, "127.0.0.1", "localhost", "test switch", "kilda"));
    handler.overrideSwitchInfoData(DatapathId.of(2), new SwitchInfoData("sw2", SwitchState.ADDED, "127.0.0.1", "localhost", "test switch", "kilda"));
    // setup hook for verify that we create new message for producer
    producer.postMessage(eq(OUTPUT_DISCO_TOPIC), anyObject(InfoMessage.class));
    replayAll();
    // Create CommandMessage with NetworkCommandData for trigger network dump
    CommandMessage command = new CommandMessage(new NetworkCommandData(), System.currentTimeMillis(), Utils.SYSTEM_CORRELATION_ID, Destination.CONTROLLER);
    // KafkaMessageCollector contains a complicated run logic with couple nested private
    // classes, threading and that is very painful for writing clear looking test code so I
    // created the simple method in KafkaMessageCollector for simplifying test logic.
    handler.handleMessage(command);
    verify(producer);
// TODO: verify content of InfoMessage in producer.postMessage
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) InfoMessage(org.openkilda.messaging.info.InfoMessage) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFSwitch(net.floodlightcontroller.core.internal.OFSwitch) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) CommandMessage(org.openkilda.messaging.command.CommandMessage) Test(org.junit.Test)

Example 42 with InfoMessage

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

the class SpeakerBolt method makePortMessage.

protected String makePortMessage(ISwitchImpl sw, int portNum, PortChangeType type) throws IOException {
    PortInfoData data = new PortInfoData(sw.getDpid().toString(), portNum, type);
    InfoMessage message = new InfoMessage(data, Instant.now().toEpochMilli(), UUID.randomUUID().toString(), null);
    return Utils.MAPPER.writeValueAsString(message);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage)

Example 43 with InfoMessage

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

the class SpeakerBolt method discoverIslPartTwo.

protected void discoverIslPartTwo(Tuple tuple, IslInfoData data) throws Exception {
    /*
         * Second part of the discover process.
         *
         * 1.  Grabs a message that has been sent from the first part and thus we know that the source port is
         *     and active ISL.
         * 2.  Check the status of the destination port, in Path[1], and if activeISL then emit to Kafka
         */
    ISwitchImpl sw = getSwitch(data.getPath().get(1).getSwitchId());
    if (!sw.isActive()) {
        return;
    }
    IPortImpl port = sw.getPort(data.getPath().get(1).getPortNo());
    if (port.isActiveIsl()) {
        long now = Instant.now().toEpochMilli();
        InfoMessage infoMessage = new InfoMessage(data, now, "system", null);
        logger.debug("checking isl on: {}", data.toString());
        collector.emit(SimulatorTopology.KAFKA_BOLT_STREAM, tuple, new Values("INFO", Utils.MAPPER.writeValueAsString(infoMessage)));
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values)

Example 44 with InfoMessage

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

the class IPortImpl method makePorChangetMessage.

public InfoMessage makePorChangetMessage() throws IOException {
    PortChangeType type = isActive ? PortChangeType.UP : PortChangeType.DOWN;
    PortInfoData data = new PortInfoData(sw.getDpid().toString(), number, type);
    return new InfoMessage(data, Instant.now().toEpochMilli(), UUID.randomUUID().toString(), null);
}
Also used : PortChangeType(org.openkilda.messaging.info.event.PortChangeType) InfoMessage(org.openkilda.messaging.info.InfoMessage) PortInfoData(org.openkilda.messaging.info.event.PortInfoData)

Example 45 with InfoMessage

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

the class OFEMessageUtils method createIslFail.

public static String createIslFail(String switchId, String portId) throws IOException {
    PathNode node = new PathNode(switchId, Integer.parseInt(portId), 0, 0L);
    InfoData data = new IslInfoData(0L, Collections.singletonList(node), 0L, IslChangeType.FAILED, 0L);
    InfoMessage message = new InfoMessage(data, System.currentTimeMillis(), UUID.randomUUID().toString());
    return MAPPER.writeValueAsString(message);
}
Also used : IslInfoData(org.openkilda.messaging.info.event.IslInfoData) InfoData(org.openkilda.messaging.info.InfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode)

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