Search in sources :

Example 6 with SwitchOperationException

use of org.openkilda.floodlight.switchmanager.SwitchOperationException 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 7 with SwitchOperationException

use of org.openkilda.floodlight.switchmanager.SwitchOperationException 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 8 with SwitchOperationException

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

the class RecordHandler method doProcessEgressFlow.

/**
 * Processes egress flow install message.
 *
 * @param message command message for flow installation
 */
private void doProcessEgressFlow(final CommandMessage message, String replyToTopic, Destination replyDestination) throws FlowCommandException {
    InstallEgressFlow command = (InstallEgressFlow) message.getData();
    try {
        installEgressFlow(command);
        message.setDestination(replyDestination);
        context.getKafkaProducer().postMessage(replyToTopic, message);
    } catch (SwitchOperationException e) {
        throw new FlowCommandException(command.getId(), ErrorType.CREATION_FAILURE, e);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.switchmanager.SwitchOperationException) InstallEgressFlow(org.openkilda.messaging.command.flow.InstallEgressFlow)

Example 9 with SwitchOperationException

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

the class MetersResource method getMeters.

// FIXME(surabujin): is it used anywhere?
@Get("json")
@SuppressWarnings("unchecked")
public Map<Long, Object> getMeters() {
    Map<Long, Object> response = new HashMap<>();
    String switchId = (String) this.getRequestAttributes().get("switch_id");
    logger.debug("Get meters for switch: {}", switchId);
    ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
    try {
        OFMeterConfigStatsReply replay = switchManager.dumpMeters(DatapathId.of(switchId));
        logger.debug("Meters from switch {} received: {}", switchId, replay);
        if (replay != null) {
            for (OFMeterConfig entry : replay.getEntries()) {
                response.put(entry.getMeterId(), entry);
            }
        }
    } catch (IllegalArgumentException | SwitchOperationException exception) {
        String messageString = "No such switch";
        logger.error("{}: {}", messageString, switchId, exception);
        MessageError responseMessage = new MessageError(DEFAULT_CORRELATION_ID, System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
        response.putAll(MAPPER.convertValue(responseMessage, Map.class));
    }
    return response;
}
Also used : SwitchOperationException(org.openkilda.floodlight.switchmanager.SwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) OFMeterConfigStatsReply(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply) HashMap(java.util.HashMap) MessageError(org.openkilda.messaging.error.MessageError) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) Get(org.restlet.resource.Get)

Aggregations

SwitchOperationException (org.openkilda.floodlight.switchmanager.SwitchOperationException)9 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)4 DatapathId (org.projectfloodlight.openflow.types.DatapathId)3 InstallEgressFlow (org.openkilda.messaging.command.flow.InstallEgressFlow)2 InstallIngressFlow (org.openkilda.messaging.command.flow.InstallIngressFlow)2 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)2 InstallTransitFlow (org.openkilda.messaging.command.flow.InstallTransitFlow)2 ErrorData (org.openkilda.messaging.error.ErrorData)2 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 SwitchRulesResponse (org.openkilda.messaging.info.switches.SwitchRulesResponse)2 HashMap (java.util.HashMap)1 BaseInstallFlow (org.openkilda.messaging.command.flow.BaseInstallFlow)1 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)1 DeleteRulesAction (org.openkilda.messaging.command.switches.DeleteRulesAction)1 InstallMissedFlowsRequest (org.openkilda.messaging.command.switches.InstallMissedFlowsRequest)1 InstallRulesAction (org.openkilda.messaging.command.switches.InstallRulesAction)1 SwitchRulesDeleteRequest (org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest)1 SwitchRulesInstallRequest (org.openkilda.messaging.command.switches.SwitchRulesInstallRequest)1 MessageError (org.openkilda.messaging.error.MessageError)1