Search in sources :

Example 16 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class RecordHandler method doReinstallDefaultFlowForSwitchManager.

/**
 * Reinstall default flow.
 *
 * @param message command message for flow deletion
 */
private void doReinstallDefaultFlowForSwitchManager(CommandMessage message) {
    ReinstallDefaultFlowForSwitchManagerRequest request = (ReinstallDefaultFlowForSwitchManagerRequest) message.getData();
    IKafkaProducerService producerService = getKafkaProducer();
    String replyToTopic = context.getKafkaSwitchManagerTopic();
    long cookie = request.getCookie();
    if (!Cookie.isDefaultRule(cookie)) {
        logger.warn("Failed to reinstall default switch rule for switch: '{}'. Rule {} is not default.", request.getSwitchId(), Long.toHexString(cookie));
        anError(ErrorType.DATA_INVALID).withMessage(format("Failed to reinstall default switch rule for switch %s. Rule %s is not default", request.getSwitchId(), Long.toHexString(cookie))).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
    SwitchId switchId = request.getSwitchId();
    DatapathId dpid = DatapathId.of(switchId.toLong());
    try {
        RemoveFlow command = RemoveFlow.builder().flowId("REMOVE_DEFAULT_FLOW").cookie(cookie).switchId(switchId).build();
        Set<Long> removedFlows = new HashSet<>(processDeleteFlow(command, dpid));
        for (Long removedFlow : removedFlows) {
            Long installedFlow;
            if (request instanceof ReinstallServer42FlowForSwitchManagerRequest) {
                installedFlow = processInstallServer42Rule((ReinstallServer42FlowForSwitchManagerRequest) request);
            } else {
                installedFlow = processInstallDefaultFlowByCookie(switchId, removedFlow);
            }
            InfoMessage response = new InfoMessage(new FlowReinstallResponse(removedFlow, installedFlow), System.currentTimeMillis(), message.getCorrelationId());
            producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
        }
    } catch (SwitchOperationException e) {
        logger.error("Failed to reinstall switch rule for switch: '{}'", request.getSwitchId(), e);
        anError(ErrorType.INTERNAL_ERROR).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ReinstallDefaultFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest) FlowReinstallResponse(org.openkilda.messaging.info.flow.FlowReinstallResponse) SwitchId(org.openkilda.model.SwitchId) DatapathId(org.projectfloodlight.openflow.types.DatapathId) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest) HashSet(java.util.HashSet)

Example 17 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class RecordHandler method doModifyMeterRequest.

private void doModifyMeterRequest(CommandMessage message) {
    MeterModifyCommandRequest request = (MeterModifyCommandRequest) message.getData();
    final IKafkaProducerService producerService = getKafkaProducer();
    String replyToTopic = context.getKafkaNbWorkerTopic();
    SwitchId switchId = request.getSwitchId();
    DatapathId datapathId = DatapathId.of(switchId.toLong());
    long meterId = request.getMeterId();
    ISwitchManager switchManager = context.getSwitchManager();
    try {
        switchManager.modifyMeterForFlow(datapathId, meterId, request.getBandwidth());
        MeterEntry meterEntry = OfMeterConverter.toMeterEntry(switchManager.dumpMeterById(datapathId, meterId));
        SwitchMeterEntries response = SwitchMeterEntries.builder().switchId(switchId).meterEntries(ImmutableList.of(meterEntry)).build();
        InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), infoMessage);
    } catch (UnsupportedSwitchOperationException e) {
        String messageString = String.format("Not supported: %s", new SwitchId(e.getDpId().getLong()));
        logger.error(messageString, e);
        anError(ErrorType.PARAMETERS_INVALID).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    } catch (SwitchNotFoundException e) {
        logger.error("Update switch meters is unsuccessful. Switch {} not found", new SwitchId(e.getDpId().getLong()));
        anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(new SwitchId(e.getDpId().getLong()).toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    } catch (SwitchOperationException e) {
        String messageString = "Unable to update meter";
        logger.error(messageString, e);
        anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) SwitchId(org.openkilda.model.SwitchId) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) MeterEntry(org.openkilda.messaging.info.meter.MeterEntry) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) MeterModifyCommandRequest(org.openkilda.messaging.command.flow.MeterModifyCommandRequest)

Example 18 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class RecordHandler method doDeleteFlowForSwitchManager.

/**
 * Removes flow.
 *
 * @param message command message for flow deletion
 */
private void doDeleteFlowForSwitchManager(final CommandMessage message) {
    RemoveFlowForSwitchManagerRequest request = (RemoveFlowForSwitchManagerRequest) message.getData();
    IKafkaProducerService producerService = getKafkaProducer();
    String replyToTopic = context.getKafkaSwitchManagerTopic();
    DatapathId dpid = DatapathId.of(request.getSwitchId().toLong());
    try {
        processDeleteFlow(request.getFlowCommand(), dpid);
        InfoMessage response = new InfoMessage(new FlowRemoveResponse(), System.currentTimeMillis(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
    } catch (SwitchOperationException e) {
        logger.error("Failed to process switch rule deletion for switch: '{}'", request.getSwitchId(), e);
        anError(ErrorType.DELETION_FAILURE).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) RemoveFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.RemoveFlowForSwitchManagerRequest) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) DatapathId(org.projectfloodlight.openflow.types.DatapathId) FlowRemoveResponse(org.openkilda.messaging.info.flow.FlowRemoveResponse)

Example 19 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class RecordHandler method doInstallIslDefaultRule.

private void doInstallIslDefaultRule(CommandMessage message) {
    InstallIslDefaultRulesCommand toSetup = (InstallIslDefaultRulesCommand) message.getData();
    InstallIslDefaultRulesResult result = new InstallIslDefaultRulesResult(toSetup.getSrcSwitch(), toSetup.getSrcPort(), toSetup.getDstSwitch(), toSetup.getDstPort(), true);
    DatapathId dpid = DatapathId.of(toSetup.getSrcSwitch().toLong());
    try {
        if (toSetup.isMultitableMode()) {
            context.getSwitchManager().installMultitableEndpointIslRules(dpid, toSetup.getSrcPort());
        }
        if (toSetup.isServer42IslRtt()) {
            context.getSwitchManager().installServer42IslRttInputFlow(dpid, toSetup.getServer42Port(), toSetup.getSrcPort());
        }
    } catch (SwitchOperationException e) {
        logger.error("Failed to install isl rules for switch: '{}'", toSetup.getSrcSwitch(), e);
        result.setSuccess(false);
    }
    getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), record.key(), new InfoMessage(result, System.currentTimeMillis(), message.getCorrelationId(), context.getRegion()));
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) InfoMessage(org.openkilda.messaging.info.InfoMessage) InstallIslDefaultRulesCommand(org.openkilda.messaging.payload.switches.InstallIslDefaultRulesCommand) DatapathId(org.projectfloodlight.openflow.types.DatapathId) InstallIslDefaultRulesResult(org.openkilda.messaging.info.discovery.InstallIslDefaultRulesResult)

Example 20 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class RecordHandler method doConfigurePort.

private void doConfigurePort(final CommandMessage message) {
    PortConfigurationRequest request = (PortConfigurationRequest) message.getData();
    logger.info("Port configuration request. Switch '{}', Port '{}'", request.getSwitchId(), request.getPortNumber());
    final IKafkaProducerService producerService = getKafkaProducer();
    final String replyToTopic = context.getKafkaNorthboundTopic();
    try {
        ISwitchManager switchManager = context.getSwitchManager();
        DatapathId dpId = DatapathId.of(request.getSwitchId().toLong());
        switchManager.configurePort(dpId, request.getPortNumber(), request.getAdminDown());
        InfoMessage infoMessage = new InfoMessage(new PortConfigurationResponse(request.getSwitchId(), request.getPortNumber()), message.getTimestamp(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, infoMessage);
    } catch (SwitchOperationException e) {
        logger.error("Port configuration request failed. " + e.getMessage(), e);
        anError(ErrorType.DATA_INVALID).withMessage(e.getMessage()).withDescription("Port configuration request failed").withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : PortConfigurationRequest(org.openkilda.messaging.command.switches.PortConfigurationRequest) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) DatapathId(org.projectfloodlight.openflow.types.DatapathId) PortConfigurationResponse(org.openkilda.messaging.info.switches.PortConfigurationResponse)

Aggregations

SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)28 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)25 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)13 InfoMessage (org.openkilda.messaging.info.InfoMessage)13 DatapathId (org.projectfloodlight.openflow.types.DatapathId)13 ErrorData (org.openkilda.messaging.error.ErrorData)9 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)8 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)8 SwitchId (org.openkilda.model.SwitchId)8 ArrayList (java.util.ArrayList)7 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)7 OFMeterConfig (org.projectfloodlight.openflow.protocol.OFMeterConfig)7 HashSet (java.util.HashSet)6 DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)6 OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 Objects (java.util.Objects)5 String.format (java.lang.String.format)4