Search in sources :

Example 6 with SwitchRulesInstallRequest

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

the class RecordHandler method handleCommand.

@VisibleForTesting
void handleCommand(CommandMessage message) {
    logger.debug("Handling message: '{}'.", message);
    CommandData data = message.getData();
    if (data instanceof DiscoverIslCommandData) {
        doDiscoverIslCommand((DiscoverIslCommandData) data, message.getCorrelationId());
    } else if (data instanceof DiscoverPathCommandData) {
        doDiscoverPathCommand(data);
    } else if (data instanceof RemoveFlowForSwitchManagerRequest) {
        doDeleteFlowForSwitchManager(message);
    } else if (data instanceof ModifyFlowMeterForSwitchManagerRequest) {
        doModifyFlowMeterForSwitchManager(message);
    } else if (data instanceof ModifyDefaultMeterForSwitchManagerRequest) {
        doModifyDefaultMeterForSwitchManager(message);
    } else if (data instanceof ReinstallDefaultFlowForSwitchManagerRequest) {
        doReinstallDefaultFlowForSwitchManager(message);
    } else if (data instanceof NetworkCommandData) {
        doNetworkDump((NetworkCommandData) data);
    } else if (data instanceof SwitchRulesDeleteRequest) {
        doDeleteSwitchRules(message);
    } else if (data instanceof SwitchRulesInstallRequest) {
        doInstallSwitchRules(message);
    } else if (data instanceof DumpRulesForFlowHsRequest) {
        doDumpRulesForFlowHsRequest(message);
    } else if (data instanceof DumpRulesRequest) {
        doDumpRulesRequest(message);
    } else if (data instanceof DumpRulesForSwitchManagerRequest) {
        doDumpRulesForSwitchManagerRequest(message);
    } else if (data instanceof InstallFlowForSwitchManagerRequest) {
        doInstallFlowForSwitchManager(message);
    } else if (data instanceof DeleterMeterForSwitchManagerRequest) {
        doDeleteMeter(message, context.getKafkaSwitchManagerTopic());
    } else if (data instanceof DeleteMeterRequest) {
        doDeleteMeter(message, context.getKafkaNorthboundTopic());
    } else if (data instanceof PortConfigurationRequest) {
        doConfigurePort(message);
    } else if (data instanceof DumpSwitchPortsDescriptionRequest) {
        doDumpSwitchPortsDescriptionRequest(message);
    } else if (data instanceof DumpPortDescriptionRequest) {
        doDumpPortDescriptionRequest(message);
    } else if (data instanceof DumpMetersRequest) {
        doDumpMetersRequest(message);
    } else if (data instanceof DumpMetersForSwitchManagerRequest) {
        doDumpMetersForSwitchManagerRequest(message);
    } else if (data instanceof DumpMetersForFlowHsRequest) {
        doDumpMetersForFlowHsRequest(message);
    } else if (data instanceof MeterModifyCommandRequest) {
        doModifyMeterRequest(message);
    } else if (data instanceof AliveRequest) {
        doAliveRequest(message);
    } else if (data instanceof InstallIslDefaultRulesCommand) {
        doInstallIslDefaultRule(message);
    } else if (data instanceof RemoveIslDefaultRulesCommand) {
        doRemoveIslDefaultRule(message);
    } else if (data instanceof DumpGroupsForSwitchManagerRequest) {
        doDumpGroupsForSwitchManagerRequest(message);
    } else if (data instanceof DumpGroupsForFlowHsRequest) {
        doDumpGroupsForFlowHsRequest(message);
    } else if (data instanceof InstallGroupRequest) {
        doInstallGroupRequest(message);
    } else if (data instanceof ModifyGroupRequest) {
        doModifyGroupRequest(message);
    } else if (data instanceof DeleteGroupRequest) {
        doDeleteGroupRequest(message);
    } else if (data instanceof BroadcastWrapper) {
        handleBroadcastCommand(message, (BroadcastWrapper) data);
    } else {
        handlerNotFound(data);
    }
}
Also used : DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) RemoveFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.RemoveFlowForSwitchManagerRequest) InstallGroupRequest(org.openkilda.messaging.command.switches.InstallGroupRequest) DumpGroupsForSwitchManagerRequest(org.openkilda.messaging.command.switches.DumpGroupsForSwitchManagerRequest) InstallFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.InstallFlowForSwitchManagerRequest) InstallIslDefaultRulesCommand(org.openkilda.messaging.payload.switches.InstallIslDefaultRulesCommand) DumpMetersRequest(org.openkilda.messaging.command.switches.DumpMetersRequest) BroadcastWrapper(org.openkilda.messaging.command.BroadcastWrapper) DumpMetersForSwitchManagerRequest(org.openkilda.messaging.command.switches.DumpMetersForSwitchManagerRequest) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) DumpRulesRequest(org.openkilda.messaging.command.switches.DumpRulesRequest) ModifyDefaultMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest) DumpRulesForSwitchManagerRequest(org.openkilda.messaging.command.switches.DumpRulesForSwitchManagerRequest) ModifyGroupRequest(org.openkilda.messaging.command.switches.ModifyGroupRequest) DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) ReinstallDefaultFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) DumpPortDescriptionRequest(org.openkilda.messaging.command.switches.DumpPortDescriptionRequest) RemoveIslDefaultRulesCommand(org.openkilda.messaging.payload.switches.RemoveIslDefaultRulesCommand) ModifyFlowMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyFlowMeterForSwitchManagerRequest) DeleteGroupRequest(org.openkilda.messaging.command.switches.DeleteGroupRequest) PortConfigurationRequest(org.openkilda.messaging.command.switches.PortConfigurationRequest) DeleterMeterForSwitchManagerRequest(org.openkilda.messaging.command.switches.DeleterMeterForSwitchManagerRequest) DumpSwitchPortsDescriptionRequest(org.openkilda.messaging.command.switches.DumpSwitchPortsDescriptionRequest) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) MeterModifyCommandRequest(org.openkilda.messaging.command.flow.MeterModifyCommandRequest) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) PortsCommandData(org.openkilda.messaging.command.discovery.PortsCommandData) DiscoverPathCommandData(org.openkilda.messaging.command.discovery.DiscoverPathCommandData) CommandData(org.openkilda.messaging.command.CommandData) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) DeleteMeterRequest(org.openkilda.messaging.command.flow.DeleteMeterRequest) AliveRequest(org.openkilda.messaging.AliveRequest) DiscoverPathCommandData(org.openkilda.messaging.command.discovery.DiscoverPathCommandData) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with SwitchRulesInstallRequest

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

the class RecordHandler method doInstallSwitchRules.

private void doInstallSwitchRules(final CommandMessage message) {
    SwitchRulesInstallRequest request = (SwitchRulesInstallRequest) message.getData();
    logger.info("Installing rules on '{}' switch: action={}", request.getSwitchId(), request.getInstallRulesAction());
    final IKafkaProducerService producerService = getKafkaProducer();
    final String replyToTopic = context.getKafkaSwitchManagerTopic();
    DatapathId dpid = DatapathId.of(request.getSwitchId().toLong());
    ISwitchManager switchManager = context.getSwitchManager();
    InstallRulesAction installAction = request.getInstallRulesAction();
    List<Long> installedRules = new ArrayList<>();
    try {
        if (installAction == InstallRulesAction.INSTALL_DROP) {
            installedRules.add(switchManager.installDropFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_BROADCAST) {
            installedRules.add(switchManager.installVerificationRule(dpid, true));
        } else if (installAction == InstallRulesAction.INSTALL_UNICAST) {
            // TODO: this isn't always added (ie if OF1.2). Is there a better response?
            installedRules.add(switchManager.installVerificationRule(dpid, false));
        } else if (installAction == InstallRulesAction.INSTALL_DROP_VERIFICATION_LOOP) {
            installedRules.add(switchManager.installDropLoopRule(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_BFD_CATCH) {
            // TODO: this isn't installed as well. Refactor this section
            installedRules.add(switchManager.installBfdCatchFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ROUND_TRIP_LATENCY) {
            // TODO: this isn't installed as well. Refactor this section
            installedRules.add(switchManager.installRoundTripLatencyFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_UNICAST_VXLAN) {
            installedRules.add(switchManager.installUnicastVerificationRuleVxlan(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_MULTITABLE_PRE_INGRESS_PASS_THROUGH) {
            installedRules.add(switchManager.installPreIngressTablePassThroughDefaultRule(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_MULTITABLE_INGRESS_DROP) {
            installedRules.add(switchManager.installDropFlowForTable(dpid, INGRESS_TABLE_ID, MULTITABLE_INGRESS_DROP_COOKIE));
        } else if (installAction == InstallRulesAction.INSTALL_MULTITABLE_POST_INGRESS_DROP) {
            installedRules.add(switchManager.installDropFlowForTable(dpid, POST_INGRESS_TABLE_ID, MULTITABLE_POST_INGRESS_DROP_COOKIE));
        } else if (installAction == InstallRulesAction.INSTALL_MULTITABLE_EGRESS_PASS_THROUGH) {
            installedRules.add(switchManager.installEgressTablePassThroughDefaultRule(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_MULTITABLE_TRANSIT_DROP) {
            installedRules.add(switchManager.installDropFlowForTable(dpid, TRANSIT_TABLE_ID, MULTITABLE_TRANSIT_DROP_COOKIE));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_INPUT_PRE_DROP) {
            installedRules.add(switchManager.installLldpInputPreDropFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_INGRESS) {
            installedRules.add(switchManager.installLldpIngressFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_POST_INGRESS) {
            installedRules.add(switchManager.installLldpPostIngressFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_POST_INGRESS_VXLAN) {
            installedRules.add(switchManager.installLldpPostIngressVxlanFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_POST_INGRESS_ONE_SWITCH) {
            installedRules.add(switchManager.installLldpPostIngressOneSwitchFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_TRANSIT) {
            installedRules.add(switchManager.installLldpTransitFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_INPUT_PRE_DROP) {
            installedRules.add(switchManager.installArpInputPreDropFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_INGRESS) {
            installedRules.add(switchManager.installArpIngressFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_POST_INGRESS) {
            installedRules.add(switchManager.installArpPostIngressFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_POST_INGRESS_VXLAN) {
            installedRules.add(switchManager.installArpPostIngressVxlanFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_POST_INGRESS_ONE_SWITCH) {
            installedRules.add(switchManager.installArpPostIngressOneSwitchFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_TRANSIT) {
            installedRules.add(switchManager.installArpTransitFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_OUTPUT_VLAN || installAction == InstallRulesAction.INSTALL_SERVER_42_FLOW_RTT_OUTPUT_VLAN) {
            validateServer42Fields(request, installAction);
            installedRules.add(switchManager.installServer42FlowRttOutputVlanFlow(dpid, request.getServer42Port(), request.getServer42Vlan(), request.getServer42MacAddress()));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_OUTPUT_VXLAN || installAction == InstallRulesAction.INSTALL_SERVER_42_FLOW_RTT_OUTPUT_VXLAN) {
            validateServer42Fields(request, installAction);
            installedRules.add(switchManager.installServer42FlowRttOutputVxlanFlow(dpid, request.getServer42Port(), request.getServer42Vlan(), request.getServer42MacAddress()));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_TURNING || installAction == InstallRulesAction.INSTALL_SERVER_42_FLOW_RTT_TURNING) {
            installedRules.add(switchManager.installServer42FlowRttTurningFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_FLOW_RTT_VXLAN_TURNING) {
            installedRules.add(switchManager.installServer42FlowRttVxlanTurningFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_ISL_RTT_OUTPUT) {
            validateServer42Fields(request, installAction);
            installedRules.add(switchManager.installServer42IslRttOutputFlow(dpid, request.getServer42Port(), request.getServer42Vlan(), request.getServer42MacAddress()));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_ISL_RTT_TURNING) {
            installedRules.add(switchManager.installServer42IslRttTurningFlow(dpid));
        } else {
            installedRules.addAll(switchManager.installDefaultRules(dpid));
            if (request.isMultiTable()) {
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_INGRESS_DROP_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_POST_INGRESS_DROP_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_EGRESS_PASS_THROUGH_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_TRANSIT_DROP_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_VXLAN_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_ONE_SWITCH_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_VXLAN_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_ONE_SWITCH_COOKIE));
                for (int port : request.getIslPorts()) {
                    installedRules.addAll(switchManager.installMultitableEndpointIslRules(dpid, port));
                }
                for (int port : request.getFlowPorts()) {
                    installedRules.add(switchManager.installIntermediateIngressRule(dpid, port));
                }
                for (Integer port : request.getFlowLldpPorts()) {
                    installedRules.add(switchManager.installLldpInputCustomerFlow(dpid, port));
                }
                for (Integer port : request.getFlowArpPorts()) {
                    installedRules.add(switchManager.installArpInputCustomerFlow(dpid, port));
                }
                if (request.isSwitchLldp()) {
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_INPUT_PRE_DROP_COOKIE));
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_TRANSIT_COOKIE));
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_INGRESS_COOKIE));
                }
                if (request.isSwitchArp()) {
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_INPUT_PRE_DROP_COOKIE));
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_TRANSIT_COOKIE));
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_INGRESS_COOKIE));
                }
            }
            Integer server42Port = request.getServer42Port();
            Integer server42Vlan = request.getServer42Vlan();
            MacAddress server42MacAddress = request.getServer42MacAddress();
            if (request.isServer42FlowRttFeatureToggle()) {
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), SERVER_42_FLOW_RTT_TURNING_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), SERVER_42_FLOW_RTT_VXLAN_TURNING_COOKIE));
                if (request.isServer42FlowRttSwitchProperty() && server42Port != null && server42Vlan != null && server42MacAddress != null) {
                    installedRules.add(switchManager.installServer42FlowRttOutputVlanFlow(dpid, server42Port, server42Vlan, server42MacAddress));
                    installedRules.add(switchManager.installServer42FlowRttOutputVxlanFlow(dpid, server42Port, server42Vlan, server42MacAddress));
                    for (Integer port : request.getServer42FlowRttPorts()) {
                        installedRules.add(switchManager.installServer42FlowRttInputFlow(dpid, server42Port, port, server42MacAddress));
                    }
                }
            }
            if (request.isServer42IslRttEnabled()) {
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), SERVER_42_ISL_RTT_TURNING_COOKIE));
                installedRules.add(switchManager.installServer42IslRttOutputFlow(dpid, request.getServer42Port(), request.getServer42Vlan(), request.getServer42MacAddress()));
                for (Integer port : request.getIslPorts()) {
                    installedRules.add(switchManager.installServer42IslRttInputFlow(dpid, server42Port, port));
                }
            }
        }
        SwitchRulesResponse response = new SwitchRulesResponse(installedRules.stream().filter(Objects::nonNull).collect(Collectors.toList()));
        InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, record.key(), infoMessage);
    } catch (SwitchOperationException e) {
        logger.error("Failed to install rules on switch '{}'", request.getSwitchId(), e);
        anError(ErrorType.CREATION_FAILURE).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).withKey(record.key()).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) InstallRulesAction(org.openkilda.messaging.command.switches.InstallRulesAction) ArrayList(java.util.ArrayList) DatapathId(org.projectfloodlight.openflow.types.DatapathId) MacAddress(org.openkilda.model.MacAddress) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) Objects(java.util.Objects)

Example 8 with SwitchRulesInstallRequest

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

the class SwitchServiceImpl method installRules.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<List<Long>> installRules(SwitchId switchId, InstallRulesAction installAction) {
    final String correlationId = RequestCorrelationId.getId();
    logger.info("Install switch rules request received: switch={}, action={}", switchId, installAction);
    SwitchRulesInstallRequest data = new SwitchRulesInstallRequest(switchId, installAction);
    CommandMessage request = new CommandMessage(data, System.currentTimeMillis(), correlationId);
    return messagingChannel.sendAndGet(switchManagerTopic, request).thenApply(SwitchRulesResponse.class::cast).thenApply(SwitchRulesResponse::getRuleIds);
}
Also used : SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

SwitchRulesInstallRequest (org.openkilda.messaging.command.switches.SwitchRulesInstallRequest)8 SwitchRulesResponse (org.openkilda.messaging.info.switches.SwitchRulesResponse)5 CommandMessage (org.openkilda.messaging.command.CommandMessage)4 SwitchRulesDeleteRequest (org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest)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 InstallRulesAction (org.openkilda.messaging.command.switches.InstallRulesAction)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 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1