Search in sources :

Example 36 with InfoMessage

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

the class BasicService method validateInfoMessage.

/**
 * Validates info message.
 *
 * @param correlationId     request correlation id
 * @param requestMessage    request command message
 * @param responseMessage   response info message
 * @return parsed response InfoData
 */
default InfoData validateInfoMessage(final Message requestMessage, final Message responseMessage, final String correlationId) {
    InfoData data;
    if (responseMessage != null) {
        if (responseMessage instanceof ErrorMessage) {
            ErrorData error = ((ErrorMessage) responseMessage).getData();
            logger.error("Response message is error: {}={}, command={}, error={}", CORRELATION_ID, correlationId, requestMessage, error);
            throw new MessageException((ErrorMessage) responseMessage);
        } else if (responseMessage instanceof InfoMessage) {
            InfoMessage info = (InfoMessage) responseMessage;
            data = info.getData();
            if (data == null) {
                String errorMessage = "Response message data is empty";
                logger.error("{}: {}={}, command={}, info={}", errorMessage, CORRELATION_ID, correlationId, requestMessage, info);
                throw new MessageException(responseMessage.getCorrelationId(), responseMessage.getTimestamp(), INTERNAL_ERROR, errorMessage, requestMessage.toString());
            }
        } else {
            String errorMessage = "Response message type is unexpected";
            logger.error("{}: {}:{}, command={}, message={}", errorMessage, CORRELATION_ID, correlationId, requestMessage, responseMessage);
            throw new MessageException(responseMessage.getCorrelationId(), responseMessage.getTimestamp(), INTERNAL_ERROR, errorMessage, requestMessage.toString());
        }
    } else {
        String errorMessage = "Response message is empty";
        logger.error("{}: {}={}, command={}", errorMessage, CORRELATION_ID, correlationId, requestMessage);
        throw new MessageException(DEFAULT_CORRELATION_ID, System.currentTimeMillis(), INTERNAL_ERROR, errorMessage, requestMessage.toString());
    }
    return data;
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) InfoData(org.openkilda.messaging.info.InfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 37 with InfoMessage

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

the class RecordHandler method doConnectMode.

private void doConnectMode(final CommandMessage message, String replyToTopic, Destination replyDestination) {
    ConnectModeRequest request = (ConnectModeRequest) message.getData();
    if (request.getMode() != null)
        logger.debug("Setting CONNECT MODE to '{}'", request.getMode());
    else
        logger.debug("Getting CONNECT MODE");
    ISwitchManager switchManager = context.getSwitchManager();
    ConnectModeRequest.Mode result = switchManager.connectMode(request.getMode());
    logger.debug("CONNECT MODE is now '{}'", result);
    ConnectModeResponse response = new ConnectModeResponse(result);
    InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
    context.getKafkaProducer().postMessage(replyToTopic, infoMessage);
}
Also used : ConnectModeRequest(org.openkilda.messaging.command.switches.ConnectModeRequest) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) InfoMessage(org.openkilda.messaging.info.InfoMessage) ConnectModeResponse(org.openkilda.messaging.info.switches.ConnectModeResponse)

Example 38 with InfoMessage

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

the class RecordHandler method doInstallSwitchRules.

private void doInstallSwitchRules(final CommandMessage message, String replyToTopic, Destination replyDestination) {
    SwitchRulesInstallRequest request = (SwitchRulesInstallRequest) message.getData();
    logger.debug("Installing rules on '{}' switch: action={}", request.getSwitchId(), request.getInstallRulesAction());
    DatapathId dpid = DatapathId.of(request.getSwitchId());
    ISwitchManager switchManager = context.getSwitchManager();
    InstallRulesAction installAction = request.getInstallRulesAction();
    List<Long> installedRules = new ArrayList<>();
    try {
        if (installAction == InstallRulesAction.INSTALL_DROP) {
            switchManager.installDropFlow(dpid);
            installedRules.add(ISwitchManager.DROP_RULE_COOKIE);
        } else if (installAction == InstallRulesAction.INSTALL_BROADCAST) {
            switchManager.installVerificationRule(dpid, true);
            installedRules.add(ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE);
        } else if (installAction == InstallRulesAction.INSTALL_UNICAST) {
            // TODO: this isn't always added (ie if OF1.2). Is there a better response?
            switchManager.installVerificationRule(dpid, false);
            installedRules.add(ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE);
        } else {
            switchManager.installDefaultRules(dpid);
            installedRules.addAll(asList(ISwitchManager.DROP_RULE_COOKIE, ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE, ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE));
        }
        SwitchRulesResponse response = new SwitchRulesResponse(installedRules);
        InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
        context.getKafkaProducer().postMessage(replyToTopic, infoMessage);
    } catch (SwitchOperationException e) {
        ErrorData errorData = new ErrorData(ErrorType.CREATION_FAILURE, e.getMessage(), request.getSwitchId());
        ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
        context.getKafkaProducer().postMessage(replyToTopic, error);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.switchmanager.SwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) InstallRulesAction(org.openkilda.messaging.command.switches.InstallRulesAction) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) DatapathId(org.projectfloodlight.openflow.types.DatapathId) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 39 with InfoMessage

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

the class RecordHandler method doDeleteSwitchRules.

private void doDeleteSwitchRules(final CommandMessage message, String replyToTopic, Destination replyDestination) {
    SwitchRulesDeleteRequest request = (SwitchRulesDeleteRequest) message.getData();
    logger.debug("Deleting rules from '{}' switch: action={}", request.getSwitchId(), request.getDeleteRulesAction());
    DatapathId dpid = DatapathId.of(request.getSwitchId());
    ISwitchManager switchManager = context.getSwitchManager();
    DeleteRulesAction deleteAction = request.getDeleteRulesAction();
    List<Long> removedRules = new ArrayList<>();
    try {
        /*
             * This first part .. we are either deleting one rule, or all non-default rules (the else)
             */
        List<Long> toRemove = new ArrayList<>();
        if (deleteAction == DeleteRulesAction.ONE) {
            toRemove.add(request.getOneCookie());
        } else if (deleteAction == DeleteRulesAction.REMOVE_DROP) {
            toRemove.add(ISwitchManager.DROP_RULE_COOKIE);
        } else if (deleteAction == DeleteRulesAction.REMOVE_BROADCAST) {
            toRemove.add(ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE);
        } else if (deleteAction == DeleteRulesAction.REMOVE_UNICAST) {
            toRemove.add(ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE);
        } else if (deleteAction == DeleteRulesAction.REMOVE_DEFAULTS || deleteAction == DeleteRulesAction.REMOVE_ADD) {
            toRemove.add(ISwitchManager.DROP_RULE_COOKIE);
            toRemove.add(ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE);
            toRemove.add(ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE);
        }
        // toRemove is > 0 only if we are trying to delete base rule(s).
        if (toRemove.size() > 0) {
            removedRules.addAll(switchManager.deleteRuleWithCookie(dpid, toRemove));
            if (deleteAction == DeleteRulesAction.REMOVE_ADD) {
                switchManager.installDefaultRules(dpid);
            }
        } else {
            removedRules.addAll(switchManager.deleteAllNonDefaultRules(dpid));
            /*
                 * The Second part - only for a subset of actions.
                 */
            if (deleteAction == DeleteRulesAction.DROP) {
                List<Long> removedDefaultRules = switchManager.deleteDefaultRules(dpid);
                // Return removedDefaultRules as a part of the result list.
                removedRules.addAll(removedDefaultRules);
            } else if (deleteAction == DeleteRulesAction.DROP_ADD) {
                switchManager.deleteDefaultRules(dpid);
                switchManager.installDefaultRules(dpid);
            } else if (deleteAction == DeleteRulesAction.OVERWRITE) {
                switchManager.installDefaultRules(dpid);
            }
        }
        SwitchRulesResponse response = new SwitchRulesResponse(removedRules);
        InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
        context.getKafkaProducer().postMessage(replyToTopic, infoMessage);
    } catch (SwitchOperationException e) {
        ErrorData errorData = new ErrorData(ErrorType.DELETION_FAILURE, e.getMessage(), request.getSwitchId());
        ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
        context.getKafkaProducer().postMessage(replyToTopic, error);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.switchmanager.SwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) DeleteRulesAction(org.openkilda.messaging.command.switches.DeleteRulesAction) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) DatapathId(org.projectfloodlight.openflow.types.DatapathId) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 40 with InfoMessage

use of org.openkilda.messaging.info.InfoMessage 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)

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