Search in sources :

Example 36 with CommandMessage

use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.

the class FlowServiceImpl method _deleteFlowRespone.

/**
 * Blocking primitive .. waits for the response .. and then converts to FlowPayload.
 * @return the deleted flow.
 */
private FlowPayload _deleteFlowRespone(final String correlationId, CommandMessage request) {
    Message message = (Message) messageConsumer.poll(correlationId);
    FlowResponse response = (FlowResponse) validateInfoMessage(request, message, correlationId);
    return Converter.buildFlowPayloadByFlow(response.getPayload());
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse)

Example 37 with CommandMessage

use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.

the class SwitchServiceImpl method syncRules.

@Override
public SyncRulesOutput syncRules(String switchId, String correlationId) {
    SyncRulesRequest request = new SyncRulesRequest(switchId);
    CommandWithReplyToMessage commandMessage = new CommandWithReplyToMessage(request, System.currentTimeMillis(), correlationId, Destination.TOPOLOGY_ENGINE, northboundTopic);
    messageProducer.send(topoEngTopic, commandMessage);
    Message message = messageConsumer.poll(correlationId);
    SyncRulesResponse response = (SyncRulesResponse) validateInfoMessage(commandMessage, message, correlationId);
    return switchMapper.toSuncRulesOutput(response);
}
Also used : SyncRulesResponse(org.openkilda.messaging.info.switches.SyncRulesResponse) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) SyncRulesRequest(org.openkilda.messaging.command.switches.SyncRulesRequest)

Example 38 with CommandMessage

use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.

the class SwitchServiceImpl method installRules.

@Override
public List<Long> installRules(String switchId, InstallRulesAction installAction, String correlationId) {
    LOGGER.debug("Install switch rules request received");
    SwitchRulesInstallRequest data = new SwitchRulesInstallRequest(switchId, installAction);
    CommandMessage request = new CommandWithReplyToMessage(data, System.currentTimeMillis(), correlationId, Destination.CONTROLLER, northboundTopic);
    messageProducer.send(floodlightTopic, request);
    Message message = messageConsumer.poll(correlationId);
    SwitchRulesResponse response = (SwitchRulesResponse) validateInfoMessage(request, message, correlationId);
    return response.getRuleIds();
}
Also used : Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 39 with CommandMessage

use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.

the class RecordHandler method doNetworkDump.

/**
 * Create network dump for OFELinkBolt
 *
 * @param message NetworkCommandData
 */
private void doNetworkDump(final CommandMessage message) {
    logger.info("Create network dump");
    NetworkCommandData command = (NetworkCommandData) message.getData();
    Map<DatapathId, IOFSwitch> allSwitchMap = context.getSwitchManager().getAllSwitchMap();
    Set<SwitchInfoData> switchesInfoData = allSwitchMap.values().stream().map(this::buildSwitchInfoData).collect(Collectors.toSet());
    Set<PortInfoData> portsInfoData = allSwitchMap.values().stream().flatMap(sw -> sw.getEnabledPorts().stream().map(port -> new PortInfoData(sw.getId().toString(), port.getPortNo().getPortNumber(), null, PortChangeType.UP)).collect(Collectors.toSet()).stream()).collect(Collectors.toSet());
    NetworkInfoData dump = new NetworkInfoData(command.getRequester(), switchesInfoData, portsInfoData, Collections.emptySet(), Collections.emptySet());
    InfoMessage infoMessage = new InfoMessage(dump, System.currentTimeMillis(), message.getCorrelationId());
    context.getKafkaProducer().postMessage(OUTPUT_DISCO_TOPIC, infoMessage);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) OFFlowStatsConverter(org.openkilda.floodlight.converter.OFFlowStatsConverter) LoggerFactory(org.slf4j.LoggerFactory) InstallTransitFlow(org.openkilda.messaging.command.flow.InstallTransitFlow) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) SwitchOperationException(org.openkilda.floodlight.switchmanager.SwitchOperationException) CommandMessage(org.openkilda.messaging.command.CommandMessage) PortChangeType(org.openkilda.messaging.info.event.PortChangeType) Arrays.asList(java.util.Arrays.asList) DeleteRulesAction(org.openkilda.messaging.command.switches.DeleteRulesAction) ConnectModeRequest(org.openkilda.messaging.command.switches.ConnectModeRequest) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) OutputVlanType(org.openkilda.messaging.payload.flow.OutputVlanType) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) InstallMissedFlowsRequest(org.openkilda.messaging.command.switches.InstallMissedFlowsRequest) IOFSwitchConverter(org.openkilda.floodlight.converter.IOFSwitchConverter) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) Collectors(java.util.stream.Collectors) InstallEgressFlow(org.openkilda.messaging.command.flow.InstallEgressFlow) OFPort(org.projectfloodlight.openflow.types.OFPort) DumpRulesRequest(org.openkilda.messaging.command.switches.DumpRulesRequest) Topic(org.openkilda.messaging.Topic) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) MeterPool(org.openkilda.floodlight.switchmanager.MeterPool) InstallIngressFlow(org.openkilda.messaging.command.flow.InstallIngressFlow) CommandData(org.openkilda.messaging.command.CommandData) java.util(java.util) SwitchState(org.openkilda.messaging.info.event.SwitchState) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) MAPPER(org.openkilda.messaging.Utils.MAPPER) ConnectModeResponse(org.openkilda.messaging.info.switches.ConnectModeResponse) Logger(org.slf4j.Logger) DiscoverPathCommandData(org.openkilda.messaging.command.discovery.DiscoverPathCommandData) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) ErrorType(org.openkilda.messaging.error.ErrorType) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) InstallRulesAction(org.openkilda.messaging.command.switches.InstallRulesAction) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) Destination(org.openkilda.messaging.Destination) DatapathId(org.projectfloodlight.openflow.types.DatapathId) ErrorData(org.openkilda.messaging.error.ErrorData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) DatapathId(org.projectfloodlight.openflow.types.DatapathId) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 40 with CommandMessage

use of org.openkilda.messaging.command.CommandMessage 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)

Aggregations

CommandMessage (org.openkilda.messaging.command.CommandMessage)70 Message (org.openkilda.messaging.Message)36 InfoMessage (org.openkilda.messaging.info.InfoMessage)32 Test (org.junit.Test)19 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)18 Values (org.apache.storm.tuple.Values)11 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)11 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)8 Flow (org.openkilda.messaging.model.Flow)8 IOException (java.io.IOException)7 CommandData (org.openkilda.messaging.command.CommandData)7 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)7 HashSet (java.util.HashSet)6 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)6 CommandWithReplyToMessage (org.openkilda.messaging.command.CommandWithReplyToMessage)5 NetworkCommandData (org.openkilda.messaging.command.discovery.NetworkCommandData)5 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)5 FlowDeleteRequest (org.openkilda.messaging.command.flow.FlowDeleteRequest)4 FlowPathRequest (org.openkilda.messaging.command.flow.FlowPathRequest)4 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)4