Search in sources :

Example 1 with ModifyDefaultMeterForSwitchManagerRequest

use of org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest in project open-kilda by telstra.

the class SwitchSyncFsm method sendMetersCommands.

protected void sendMetersCommands(SwitchSyncState from, SwitchSyncState to, SwitchSyncEvent event, Object context) {
    if (excessMeters.isEmpty() && misconfiguredMeters.isEmpty()) {
        log.info("Nothing to do with meters (switch={}, key={})", switchId, key);
        fire(NEXT);
        return;
    }
    if (!excessMeters.isEmpty()) {
        log.info("Request to remove switch meters has been sent (switch={}, key={})", switchId, key);
        excessMetersPendingResponsesCount = excessMeters.size();
        for (Long meterId : excessMeters) {
            carrier.sendCommandToSpeaker(key, new DeleterMeterForSwitchManagerRequest(switchId, meterId));
        }
    }
    if (!misconfiguredMeters.isEmpty()) {
        log.info("Request to modify switch meters has been sent (switch={}, key={})", switchId, key);
        misconfiguredMetersPendingResponsesCount = misconfiguredMeters.size();
        for (ModifyDefaultMeterForSwitchManagerRequest request : misconfiguredMeters) {
            carrier.sendCommandToSpeaker(key, request);
        }
    }
}
Also used : ModifyDefaultMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest) DeleterMeterForSwitchManagerRequest(org.openkilda.messaging.command.switches.DeleterMeterForSwitchManagerRequest)

Example 2 with ModifyDefaultMeterForSwitchManagerRequest

use of org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest in project open-kilda by telstra.

the class RecordHandler method doModifyDefaultMeterForSwitchManager.

private void doModifyDefaultMeterForSwitchManager(CommandMessage message) {
    ModifyDefaultMeterForSwitchManagerRequest request = (ModifyDefaultMeterForSwitchManagerRequest) message.getData();
    IKafkaProducerService producerService = getKafkaProducer();
    String replyToTopic = context.getKafkaSwitchManagerTopic();
    long meterId = request.getMeterId();
    SwitchId switchId = request.getSwitchId();
    DatapathId dpid = DatapathId.of(switchId.toLong());
    try {
        context.getSwitchManager().modifyDefaultMeter(dpid, request.getMeterId());
        InfoMessage response = new InfoMessage(new ModifyMeterResponse(switchId, request.getMeterId()), System.currentTimeMillis(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
    } catch (UnsupportedSwitchOperationException e) {
        logger.warn(format("Skip meter %d modification on switch %s because switch doesn't support meters", meterId, switchId), e);
    } catch (InvalidMeterIdException | OfInstallException | SwitchNotFoundException e) {
        logger.error("Failed to modify meter {} for switch: '{}'", request.getSwitchId(), meterId, e);
        ErrorType errorType;
        if (e instanceof InvalidMeterIdException) {
            errorType = ErrorType.DATA_INVALID;
        } else if (e instanceof SwitchNotFoundException) {
            errorType = ErrorType.NOT_FOUND;
        } else {
            errorType = ErrorType.INTERNAL_ERROR;
        }
        anError(errorType).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : ModifyMeterResponse(org.openkilda.messaging.info.switches.ModifyMeterResponse) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException) SwitchId(org.openkilda.model.SwitchId) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ErrorType(org.openkilda.messaging.error.ErrorType) ModifyDefaultMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) OfInstallException(org.openkilda.floodlight.error.OfInstallException)

Example 3 with ModifyDefaultMeterForSwitchManagerRequest

use of org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest 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 4 with ModifyDefaultMeterForSwitchManagerRequest

use of org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest in project open-kilda by telstra.

the class CommandBuilderImpl method buildCommandsToModifyMisconfiguredMeters.

@Override
public List<ModifyDefaultMeterForSwitchManagerRequest> buildCommandsToModifyMisconfiguredMeters(SwitchId switchId, List<Long> misconfiguredDefaultMeters, List<MeterInfoEntry> misconfiguredFlowMeters) {
    List<ModifyDefaultMeterForSwitchManagerRequest> commands = misconfiguredDefaultMeters.stream().map(meterId -> new ModifyDefaultMeterForSwitchManagerRequest(switchId, meterId)).collect(Collectors.toList());
    for (MeterInfoEntry meter : misconfiguredFlowMeters) {
        long rate = Optional.ofNullable(meter.getExpected().getRate()).orElse(meter.getRate());
        commands.add(new ModifyFlowMeterForSwitchManagerRequest(switchId, meter.getMeterId(), rate));
    }
    return commands;
}
Also used : ModifyDefaultMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest) MirrorConfig(org.openkilda.model.MirrorConfig) NoArgGenerator(com.fasterxml.uuid.NoArgGenerator) EncapsulationResources(org.openkilda.wfm.share.flow.resources.EncapsulationResources) InstallServer42Flow(org.openkilda.messaging.command.flow.InstallServer42Flow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowPath(org.openkilda.model.FlowPath) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) FlowResourcesConfig(org.openkilda.wfm.share.flow.resources.FlowResourcesConfig) SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE) NumberUtils(org.apache.commons.lang.math.NumberUtils) LogicalPortInfoEntry(org.openkilda.messaging.info.switches.LogicalPortInfoEntry) ReinstallDefaultFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest) Flow(org.openkilda.model.Flow) MirrorGroup(org.openkilda.model.MirrorGroup) Map(java.util.Map) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) ModifyFlowMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyFlowMeterForSwitchManagerRequest) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteLogicalPortRequest(org.openkilda.messaging.command.grpc.DeleteLogicalPortRequest) SwitchProperties(org.openkilda.model.SwitchProperties) IpSocketAddress(org.openkilda.model.IpSocketAddress) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) NonNull(lombok.NonNull) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Set(java.util.Set) CookieType(org.openkilda.model.cookie.CookieBase.CookieType) InstallServer42FlowBuilder(org.openkilda.messaging.command.flow.InstallServer42Flow.InstallServer42FlowBuilder) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) FlowInstructions(org.openkilda.messaging.info.rule.FlowInstructions) Optional(java.util.Optional) FlowCommandFactory(org.openkilda.wfm.share.flow.service.FlowCommandFactory) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) PathSegment(org.openkilda.model.PathSegment) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) CreateLogicalPortRequest(org.openkilda.messaging.command.grpc.CreateLogicalPortRequest) Cookie(org.openkilda.model.cookie.Cookie) LogicalPortMapper(org.openkilda.wfm.topology.switchmanager.mappers.LogicalPortMapper) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) PersistenceManager(org.openkilda.persistence.PersistenceManager) CommandBuilder(org.openkilda.wfm.topology.switchmanager.service.CommandBuilder) PathId(org.openkilda.model.PathId) SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE) SharedSegmentType(org.openkilda.model.cookie.FlowSharedSegmentCookie.SharedSegmentType) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) Switch(org.openkilda.model.Switch) GroupInstallContext(org.openkilda.wfm.topology.switchmanager.model.GroupInstallContext) SERVER_42_ISL_RTT_OUTPUT_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_ISL_RTT_OUTPUT_COOKIE) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) PortColourCookie(org.openkilda.model.cookie.PortColourCookie) FlowSharedSegmentCookie(org.openkilda.model.cookie.FlowSharedSegmentCookie) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) MirrorGroupRepository(org.openkilda.persistence.repositories.MirrorGroupRepository) InstallSharedFlow(org.openkilda.messaging.command.flow.InstallSharedFlow) SwitchId(org.openkilda.model.SwitchId) MirrorConfigData(org.openkilda.model.MirrorConfig.MirrorConfigData) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) Generators(com.fasterxml.uuid.Generators) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FlowMatchField(org.openkilda.messaging.info.rule.FlowMatchField) GroupId(org.openkilda.model.GroupId) Collections(java.util.Collections) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) ModifyDefaultMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest) ModifyFlowMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyFlowMeterForSwitchManagerRequest)

Aggregations

ModifyDefaultMeterForSwitchManagerRequest (org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ModifyFlowMeterForSwitchManagerRequest (org.openkilda.messaging.command.flow.ModifyFlowMeterForSwitchManagerRequest)2 ReinstallDefaultFlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest)2 SwitchId (org.openkilda.model.SwitchId)2 Generators (com.fasterxml.uuid.Generators)1 NoArgGenerator (com.fasterxml.uuid.NoArgGenerator)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 NonNull (lombok.NonNull)1 Slf4j (lombok.extern.slf4j.Slf4j)1 NumberUtils (org.apache.commons.lang.math.NumberUtils)1