Search in sources :

Example 6 with ReinstallDefaultFlowForSwitchManagerRequest

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

Aggregations

ReinstallDefaultFlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest)6 InstallFlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.InstallFlowForSwitchManagerRequest)3 ReinstallServer42FlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest)3 RemoveFlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.RemoveFlowForSwitchManagerRequest)3 DeleteMeterRequest (org.openkilda.messaging.command.flow.DeleteMeterRequest)2 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)2 DumpMetersForFlowHsRequest (org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest)2 DumpMetersForSwitchManagerRequest (org.openkilda.messaging.command.switches.DumpMetersForSwitchManagerRequest)2 DumpMetersRequest (org.openkilda.messaging.command.switches.DumpMetersRequest)2 DumpPortDescriptionRequest (org.openkilda.messaging.command.switches.DumpPortDescriptionRequest)2 DumpRulesForFlowHsRequest (org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest)2 DumpRulesForSwitchManagerRequest (org.openkilda.messaging.command.switches.DumpRulesForSwitchManagerRequest)2 DumpRulesRequest (org.openkilda.messaging.command.switches.DumpRulesRequest)2 DumpSwitchPortsDescriptionRequest (org.openkilda.messaging.command.switches.DumpSwitchPortsDescriptionRequest)2 PortConfigurationRequest (org.openkilda.messaging.command.switches.PortConfigurationRequest)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Tuple (org.apache.storm.tuple.Tuple)1 Test (org.junit.Test)1