Search in sources :

Example 1 with SwitchRulesDeleteRequest

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

the class SwitchServiceImpl method deleteRules.

@Override
public CompletableFuture<List<Long>> deleteRules(SwitchId switchId, DeleteRulesAction deleteAction) {
    final String correlationId = RequestCorrelationId.getId();
    logger.info("Delete switch rules request received: switch={}, deleteAction={}", switchId, deleteAction);
    SwitchRulesDeleteRequest data = new SwitchRulesDeleteRequest(switchId, deleteAction, null);
    CommandMessage request = new CommandMessage(data, System.currentTimeMillis(), correlationId);
    return messagingChannel.sendAndGet(switchManagerTopic, request).thenApply(SwitchRulesResponse.class::cast).thenApply(SwitchRulesResponse::getRuleIds);
}
Also used : SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 2 with SwitchRulesDeleteRequest

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

the class SwitchServiceImpl method deleteRules.

@Override
public CompletableFuture<List<Long>> deleteRules(SwitchId switchId, DeleteRulesCriteria criteria) {
    final String correlationId = RequestCorrelationId.getId();
    logger.info("Delete switch rules request received: switch={}, criteria={}", switchId, criteria);
    SwitchRulesDeleteRequest data = new SwitchRulesDeleteRequest(switchId, null, criteria);
    CommandMessage request = new CommandMessage(data, System.currentTimeMillis(), correlationId);
    return messagingChannel.sendAndGet(switchManagerTopic, request).thenApply(SwitchRulesResponse.class::cast).thenApply(SwitchRulesResponse::getRuleIds);
}
Also used : SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 3 with SwitchRulesDeleteRequest

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

the class SwitchManagerHub method onRequest.

@Override
protected void onRequest(Tuple input) throws PipelineException {
    if (!active) {
        log.info("Switch Manager Topology is inactive");
        return;
    }
    String key = input.getStringByField(MessageKafkaTranslator.FIELD_ID_KEY);
    CommandMessage message = pullValue(input, MessageKafkaTranslator.FIELD_ID_PAYLOAD, CommandMessage.class);
    CommandData data = message.getData();
    if (data instanceof SwitchValidateRequest) {
        validateService.handleSwitchValidateRequest(key, (SwitchValidateRequest) data);
    } else if (data instanceof SwitchRulesDeleteRequest) {
        switchRuleService.deleteRules(key, (SwitchRulesDeleteRequest) data);
    } else if (data instanceof SwitchRulesInstallRequest) {
        switchRuleService.installRules(key, (SwitchRulesInstallRequest) data);
    } else if (data instanceof CreateLagPortRequest) {
        createLagPortService.handleCreateLagRequest(key, (CreateLagPortRequest) data);
    } else if (data instanceof DeleteLagPortRequest) {
        deleteLagPortService.handleDeleteLagRequest(key, (DeleteLagPortRequest) data);
    } else {
        log.warn("Receive unexpected CommandMessage for key {}: {}", key, data);
    }
}
Also used : SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) CreateLagPortRequest(org.openkilda.messaging.swmanager.request.CreateLagPortRequest) DeleteLagPortRequest(org.openkilda.messaging.swmanager.request.DeleteLagPortRequest) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) SwitchValidateRequest(org.openkilda.messaging.command.switches.SwitchValidateRequest) CommandData(org.openkilda.messaging.command.CommandData) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 4 with SwitchRulesDeleteRequest

use of org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest 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 5 with SwitchRulesDeleteRequest

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

the class SwitchServiceImpl method deleteRules.

@Override
public List<Long> deleteRules(String switchId, DeleteRulesAction deleteAction, Long cookie, String correlationId) {
    LOGGER.debug("Delete switch rules request received");
    // TODO: remove  messageConsumer.clear() as a part of NB cleanup (clear isn't required)
    messageConsumer.clear();
    SwitchRulesDeleteRequest data = new SwitchRulesDeleteRequest(switchId, deleteAction, cookie);
    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) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

SwitchRulesDeleteRequest (org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest)8 SwitchRulesResponse (org.openkilda.messaging.info.switches.SwitchRulesResponse)6 CommandMessage (org.openkilda.messaging.command.CommandMessage)4 SwitchRulesInstallRequest (org.openkilda.messaging.command.switches.SwitchRulesInstallRequest)3 InfoMessage (org.openkilda.messaging.info.InfoMessage)3 ArrayList (java.util.ArrayList)2 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)2 CommandData (org.openkilda.messaging.command.CommandData)2 DeleteRulesAction (org.openkilda.messaging.command.switches.DeleteRulesAction)2 ErrorData (org.openkilda.messaging.error.ErrorData)2 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2 DatapathId (org.projectfloodlight.openflow.types.DatapathId)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1