Search in sources :

Example 1 with UnsupportedSwitchOperationException

use of org.openkilda.floodlight.error.UnsupportedSwitchOperationException in project open-kilda by telstra.

the class RecordHandler method dumpMeters.

private void dumpMeters(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
    try {
        logger.debug("Get all meters for switch {}", switchId);
        ISwitchManager switchManager = context.getSwitchManager();
        List<OFMeterConfig> meterEntries = switchManager.dumpMeters(DatapathId.of(switchId.toLong()));
        List<MeterEntry> meters = meterEntries.stream().map(OfMeterConverter::toMeterEntry).collect(Collectors.toList());
        SwitchMeterEntries response = SwitchMeterEntries.builder().switchId(switchId).meterEntries(meters).build();
        sender.accept(response);
    } catch (UnsupportedSwitchOperationException e) {
        logger.info("Meters not supported: {}", switchId);
        sender.accept(new SwitchMeterUnsupported(switchId));
    } catch (SwitchNotFoundException e) {
        logger.info("Dumping switch meters is unsuccessful. Switch {} not found", switchId);
        ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(switchId.toString()).buildData();
        sender.accept(errorData);
    } catch (SwitchOperationException e) {
        logger.error("Unable to dump meters", e);
        ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("Unable to dump meters").buildData();
        sender.accept(errorData);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) MeterEntry(org.openkilda.messaging.info.meter.MeterEntry) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) SwitchMeterUnsupported(org.openkilda.messaging.info.meter.SwitchMeterUnsupported) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) FlowCommandErrorData(org.openkilda.messaging.error.rule.FlowCommandErrorData) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 2 with UnsupportedSwitchOperationException

use of org.openkilda.floodlight.error.UnsupportedSwitchOperationException in project open-kilda by telstra.

the class RecordHandler method dumpRuleManagerMeters.

private void dumpRuleManagerMeters(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
    try {
        logger.debug("Get all meters for switch {}", switchId);
        ISwitchManager switchManager = context.getSwitchManager();
        DatapathId datapathId = DatapathId.of(switchId.toLong());
        List<OFMeterConfig> meterEntries = switchManager.dumpMeters(datapathId);
        IOFSwitch iofSwitch = switchManager.lookupSwitch(datapathId);
        boolean inaccurate = featureDetectorService.detectSwitch(iofSwitch).contains(SwitchFeature.INACCURATE_METER);
        List<MeterSpeakerData> meters = meterEntries.stream().map(entry -> org.openkilda.floodlight.converter.rulemanager.OfMeterConverter.INSTANCE.convertToMeterSpeakerData(entry, inaccurate)).collect(Collectors.toList());
        MeterDumpResponse response = MeterDumpResponse.builder().switchId(switchId).meterSpeakerData(meters).build();
        sender.accept(response);
    } catch (UnsupportedSwitchOperationException e) {
        logger.info("Meters not supported: {}", switchId);
        sender.accept(new SwitchMeterUnsupported(switchId));
    } catch (SwitchNotFoundException e) {
        logger.info("Dumping switch meters is unsuccessful. Switch {} not found", switchId);
        ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(switchId.toString()).buildData();
        sender.accept(errorData);
    } catch (SwitchOperationException e) {
        logger.error("Unable to dump meters", e);
        ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("Unable to dump meters").buildData();
        sender.accept(errorData);
    }
}
Also used : MirrorConfig(org.openkilda.model.MirrorConfig) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) GroupModifyCommand(org.openkilda.floodlight.command.group.GroupModifyCommand) SwitchMeterUnsupported(org.openkilda.messaging.info.meter.SwitchMeterUnsupported) OfFlowStatsMapper(org.openkilda.floodlight.converter.OfFlowStatsMapper) DeleteMeterRequest(org.openkilda.messaging.command.flow.DeleteMeterRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage) MULTITABLE_POST_INGRESS_DROP_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_POST_INGRESS_DROP_COOKIE) Map(java.util.Map) DeleteRulesAction(org.openkilda.messaging.command.switches.DeleteRulesAction) DumpPortDescriptionRequest(org.openkilda.messaging.command.switches.DumpPortDescriptionRequest) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) PortStatus(org.openkilda.model.PortStatus) SetupBfdSessionDispatcher(org.openkilda.floodlight.kafka.dispatcher.SetupBfdSessionDispatcher) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException) AliveResponse(org.openkilda.messaging.AliveResponse) MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE) MessageContext(org.openkilda.messaging.MessageContext) CookieType(org.openkilda.model.cookie.CookieBase.CookieType) GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) CommandProcessorService(org.openkilda.floodlight.service.CommandProcessorService) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) ROUND_TRIP_LATENCY_RULE_COOKIE(org.openkilda.model.cookie.Cookie.ROUND_TRIP_LATENCY_RULE_COOKIE) ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest) LLDP_INGRESS_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_INGRESS_COOKIE) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest) InstallIngressFlow(org.openkilda.messaging.command.flow.InstallIngressFlow) Command(org.openkilda.floodlight.command.Command) SwitchTrackingService(org.openkilda.floodlight.switchmanager.SwitchTrackingService) PortDescription(org.openkilda.messaging.info.switches.PortDescription) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) TransitFlowLoopSegmentInstallCommand(org.openkilda.floodlight.command.flow.transit.TransitFlowLoopSegmentInstallCommand) ModifyGroupResponse(org.openkilda.messaging.info.switches.ModifyGroupResponse) SpeakerCommand(org.openkilda.floodlight.command.SpeakerCommand) SwitchPortsDescription(org.openkilda.messaging.info.switches.SwitchPortsDescription) DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) GroupDumpResponse(org.openkilda.messaging.info.group.GroupDumpResponse) CorrelationContextClosable(org.openkilda.floodlight.utils.CorrelationContext.CorrelationContextClosable) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) ErrorType(org.openkilda.messaging.error.ErrorType) SERVER_42_ISL_RTT_OUTPUT_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_ISL_RTT_OUTPUT_COOKIE) MeterDumpResponse(org.openkilda.messaging.info.meter.MeterDumpResponse) IOException(java.io.IOException) FeatureDetectorService(org.openkilda.floodlight.service.FeatureDetectorService) InstallTransitLoopFlow(org.openkilda.messaging.command.flow.InstallTransitLoopFlow) PortStatusData(org.openkilda.messaging.info.stats.PortStatusData) InstallIslDefaultRulesCommand(org.openkilda.messaging.payload.switches.InstallIslDefaultRulesCommand) FlowSharedSegmentCookie(org.openkilda.model.cookie.FlowSharedSegmentCookie) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) InstallSharedFlow(org.openkilda.messaging.command.flow.InstallSharedFlow) PortConfigurationResponse(org.openkilda.messaging.info.switches.PortConfigurationResponse) DeleteGroupRequest(org.openkilda.messaging.command.switches.DeleteGroupRequest) GroupInstallCommand(org.openkilda.floodlight.command.group.GroupInstallCommand) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SpeakerCommandReport(org.openkilda.floodlight.command.SpeakerCommandReport) OneSwitchFlowInstallCommand(org.openkilda.floodlight.command.flow.ingress.OneSwitchFlowInstallCommand) DumpMetersForSwitchManagerRequest(org.openkilda.messaging.command.switches.DumpMetersForSwitchManagerRequest) ModifyDefaultMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest) FlowSegmentResponseFactory(org.openkilda.floodlight.command.flow.FlowSegmentResponseFactory) OfPortDescConverter(org.openkilda.floodlight.converter.OfPortDescConverter) PingRequestDispatcher(org.openkilda.floodlight.kafka.dispatcher.PingRequestDispatcher) SwitchFeature(org.openkilda.model.SwitchFeature) FlowSegmentSyncResponseFactory(org.openkilda.floodlight.command.flow.FlowSegmentSyncResponseFactory) DeleteGroupResponse(org.openkilda.messaging.info.switches.DeleteGroupResponse) LLDP_POST_INGRESS_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_POST_INGRESS_COOKIE) OneSwitchMirrorFlowInstallCommand(org.openkilda.floodlight.command.flow.ingress.OneSwitchMirrorFlowInstallCommand) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) RemoveIslDefaultRulesCommand(org.openkilda.messaging.payload.switches.RemoveIslDefaultRulesCommand) OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) InstallIngressMirrorFlow(org.openkilda.messaging.command.flow.InstallIngressMirrorFlow) ModifyGroupRequest(org.openkilda.messaging.command.switches.ModifyGroupRequest) InstallFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.InstallFlowForSwitchManagerRequest) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CommandContext(org.openkilda.floodlight.command.CommandContext) Objects(java.util.Objects) MacAddress(org.openkilda.model.MacAddress) MULTITABLE_EGRESS_PASS_THROUGH_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_EGRESS_PASS_THROUGH_COOKIE) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) ARP_POST_INGRESS_VXLAN_COOKIE(org.openkilda.model.cookie.Cookie.ARP_POST_INGRESS_VXLAN_COOKIE) DumpRulesForSwitchManagerRequest(org.openkilda.messaging.command.switches.DumpRulesForSwitchManagerRequest) ARP_INGRESS_COOKIE(org.openkilda.model.cookie.Cookie.ARP_INGRESS_COOKIE) SwitchPortStatusData(org.openkilda.messaging.info.stats.SwitchPortStatusData) MULTITABLE_TRANSIT_DROP_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_TRANSIT_DROP_COOKIE) SERVER_42_FLOW_RTT_TURNING_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_TURNING_COOKIE) RemoveFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.RemoveFlowForSwitchManagerRequest) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) DumpSwitchPortsDescriptionRequest(org.openkilda.messaging.command.switches.DumpSwitchPortsDescriptionRequest) CATCH_BFD_RULE_COOKIE(org.openkilda.model.cookie.Cookie.CATCH_BFD_RULE_COOKIE) HashSet(java.util.HashSet) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) ImmutableList(com.google.common.collect.ImmutableList) MULTITABLE_INGRESS_DROP_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_INGRESS_DROP_COOKIE) MAPPER(org.openkilda.messaging.Utils.MAPPER) BroadcastStatsRequestDispatcher(org.openkilda.floodlight.kafka.dispatcher.BroadcastStatsRequestDispatcher) ConnectModeResponse(org.openkilda.messaging.info.switches.ConnectModeResponse) SharedSegmentType(org.openkilda.model.cookie.FlowSharedSegmentCookie.SharedSegmentType) POST_INGRESS_TABLE_ID(org.openkilda.floodlight.switchmanager.SwitchManager.POST_INGRESS_TABLE_ID) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) Logger(org.slf4j.Logger) EgressFlowSegmentInstallCommand(org.openkilda.floodlight.command.flow.egress.EgressFlowSegmentInstallCommand) MeterModifyCommand(org.openkilda.floodlight.command.meter.MeterModifyCommand) LLDP_INPUT_PRE_DROP_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_INPUT_PRE_DROP_COOKIE) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) MeterId(org.openkilda.model.MeterId) OfInstallException(org.openkilda.floodlight.error.OfInstallException) CommandDispatcher(org.openkilda.floodlight.kafka.dispatcher.CommandDispatcher) FlowDumpResponse(org.openkilda.messaging.info.flow.FlowDumpResponse) GroupId(org.openkilda.model.GroupId) DROP_VERIFICATION_LOOP_RULE_COOKIE(org.openkilda.model.cookie.Cookie.DROP_VERIFICATION_LOOP_RULE_COOKIE) VERIFICATION_UNICAST_VXLAN_RULE_COOKIE(org.openkilda.model.cookie.Cookie.VERIFICATION_UNICAST_VXLAN_RULE_COOKIE) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) SERVER_42_FLOW_RTT_VXLAN_TURNING_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_VXLAN_TURNING_COOKIE) RemoveBfdSessionDispatcher(org.openkilda.floodlight.kafka.dispatcher.RemoveBfdSessionDispatcher) DeleteMeterResponse(org.openkilda.messaging.info.switches.DeleteMeterResponse) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) IngressMirrorFlowSegmentInstallCommand(org.openkilda.floodlight.command.flow.ingress.IngressMirrorFlowSegmentInstallCommand) BroadcastWrapper(org.openkilda.messaging.command.BroadcastWrapper) RulesContext(org.openkilda.floodlight.model.RulesContext) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) EgressMirrorFlowSegmentInstallCommand(org.openkilda.floodlight.command.flow.egress.EgressMirrorFlowSegmentInstallCommand) FlowTransitData(org.openkilda.floodlight.model.FlowTransitData) Set(java.util.Set) OfFlowConverter(org.openkilda.floodlight.converter.rulemanager.OfFlowConverter) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) CorrelationContext(org.openkilda.floodlight.utils.CorrelationContext) MeterModifyCommandRequest(org.openkilda.messaging.command.flow.MeterModifyCommandRequest) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) PortsCommandData(org.openkilda.messaging.command.discovery.PortsCommandData) Message(org.openkilda.messaging.Message) InstallServer42IngressFlow(org.openkilda.messaging.command.flow.InstallServer42IngressFlow) MeterEntry(org.openkilda.messaging.info.meter.MeterEntry) MessageData(org.openkilda.messaging.MessageData) RemoveIslDefaultRulesResult(org.openkilda.messaging.info.discovery.RemoveIslDefaultRulesResult) ArrayList(java.util.ArrayList) SpeakerDataResponse(org.openkilda.floodlight.api.response.SpeakerDataResponse) InstallIngressLoopFlow(org.openkilda.messaging.command.flow.InstallIngressLoopFlow) LLDP_TRANSIT_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_TRANSIT_COOKIE) GroupRemoveCommand(org.openkilda.floodlight.command.group.GroupRemoveCommand) DiscoverPathCommandData(org.openkilda.messaging.command.discovery.DiscoverPathCommandData) AliveRequest(org.openkilda.messaging.AliveRequest) FlowCommandErrorData(org.openkilda.messaging.error.rule.FlowCommandErrorData) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) PortColourCookie(org.openkilda.model.cookie.PortColourCookie) DROP_RULE_COOKIE(org.openkilda.model.cookie.Cookie.DROP_RULE_COOKIE) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) InstallRulesAction(org.openkilda.messaging.command.switches.InstallRulesAction) TRANSIT_TABLE_ID(org.openkilda.floodlight.switchmanager.SwitchManager.TRANSIT_TABLE_ID) InstallGroupRequest(org.openkilda.messaging.command.switches.InstallGroupRequest) InstallEgressMirrorFlow(org.openkilda.messaging.command.flow.InstallEgressMirrorFlow) VERIFICATION_UNICAST_RULE_COOKIE(org.openkilda.model.cookie.Cookie.VERIFICATION_UNICAST_RULE_COOKIE) FlowCommandException(org.openkilda.floodlight.error.FlowCommandException) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) InstallIslDefaultRulesResult(org.openkilda.messaging.info.discovery.InstallIslDefaultRulesResult) FlowRemoveResponse(org.openkilda.messaging.info.flow.FlowRemoveResponse) FlowSegmentWrapperCommand(org.openkilda.floodlight.command.flow.FlowSegmentWrapperCommand) VERIFICATION_BROADCAST_RULE_COOKIE(org.openkilda.model.cookie.Cookie.VERIFICATION_BROADCAST_RULE_COOKIE) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) IngressFlowLoopSegmentInstallCommand(org.openkilda.floodlight.command.flow.ingress.IngressFlowLoopSegmentInstallCommand) DumpMetersRequest(org.openkilda.messaging.command.switches.DumpMetersRequest) InstallServer42Flow(org.openkilda.messaging.command.flow.InstallServer42Flow) IngressFlowSegmentInstallCommand(org.openkilda.floodlight.command.flow.ingress.IngressFlowSegmentInstallCommand) ARP_POST_INGRESS_COOKIE(org.openkilda.model.cookie.Cookie.ARP_POST_INGRESS_COOKIE) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) LoggerFactory(org.slf4j.LoggerFactory) InstallTransitFlow(org.openkilda.messaging.command.flow.InstallTransitFlow) ARP_INPUT_PRE_DROP_COOKIE(org.openkilda.model.cookie.Cookie.ARP_INPUT_PRE_DROP_COOKIE) InstallOneSwitchMirrorFlow(org.openkilda.messaging.command.flow.InstallOneSwitchMirrorFlow) DumpGroupsForSwitchManagerRequest(org.openkilda.messaging.command.switches.DumpGroupsForSwitchManagerRequest) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE) ReinstallDefaultFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest) InstallGroupResponse(org.openkilda.messaging.info.switches.InstallGroupResponse) PortConfigurationRequest(org.openkilda.messaging.command.switches.PortConfigurationRequest) MeterConfig(org.openkilda.model.MeterConfig) ConnectModeRequest(org.openkilda.messaging.command.switches.ConnectModeRequest) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ModifyFlowMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyFlowMeterForSwitchManagerRequest) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) LLDP_POST_INGRESS_VXLAN_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_POST_INGRESS_VXLAN_COOKIE) ModifyMeterResponse(org.openkilda.messaging.info.switches.ModifyMeterResponse) FlowReinstallResponse(org.openkilda.messaging.info.flow.FlowReinstallResponse) IngressServer42FlowInstallCommand(org.openkilda.floodlight.command.flow.ingress.IngressServer42FlowInstallCommand) InfoData(org.openkilda.messaging.info.InfoData) OfGroupConverter(org.openkilda.floodlight.converter.rulemanager.OfGroupConverter) TransitFlowSegmentInstallCommand(org.openkilda.floodlight.command.flow.transit.TransitFlowSegmentInstallCommand) String.format(java.lang.String.format) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) InstallEgressFlow(org.openkilda.messaging.command.flow.InstallEgressFlow) DumpRulesRequest(org.openkilda.messaging.command.switches.DumpRulesRequest) List(java.util.List) INGRESS_TABLE_ID(org.openkilda.floodlight.switchmanager.SwitchManager.INGRESS_TABLE_ID) FlowSegmentMetadata(org.openkilda.floodlight.model.FlowSegmentMetadata) FlowInstallResponse(org.openkilda.messaging.info.flow.FlowInstallResponse) Optional(java.util.Optional) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) CommandData(org.openkilda.messaging.command.CommandData) DeleterMeterForSwitchManagerRequest(org.openkilda.messaging.command.switches.DeleterMeterForSwitchManagerRequest) Getter(lombok.Getter) ARP_POST_INGRESS_ONE_SWITCH_COOKIE(org.openkilda.model.cookie.Cookie.ARP_POST_INGRESS_ONE_SWITCH_COOKIE) Cookie(org.openkilda.model.cookie.Cookie) SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE) ARP_TRANSIT_COOKIE(org.openkilda.model.cookie.Cookie.ARP_TRANSIT_COOKIE) ErrorMessageBuilder.anError(org.openkilda.floodlight.kafka.ErrorMessageBuilder.anError) SERVER_42_ISL_RTT_TURNING_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_ISL_RTT_TURNING_COOKIE) OfMeterConverter(org.openkilda.floodlight.converter.OfMeterConverter) SwitchId(org.openkilda.model.SwitchId) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ErrorData(org.openkilda.messaging.error.ErrorData) LLDP_POST_INGRESS_ONE_SWITCH_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_POST_INGRESS_ONE_SWITCH_COOKIE) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) SwitchMeterUnsupported(org.openkilda.messaging.info.meter.SwitchMeterUnsupported) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) MeterDumpResponse(org.openkilda.messaging.info.meter.MeterDumpResponse) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) FlowCommandErrorData(org.openkilda.messaging.error.rule.FlowCommandErrorData) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 3 with UnsupportedSwitchOperationException

use of org.openkilda.floodlight.error.UnsupportedSwitchOperationException in project open-kilda by telstra.

the class RecordHandler method doModifyMeterRequest.

private void doModifyMeterRequest(CommandMessage message) {
    MeterModifyCommandRequest request = (MeterModifyCommandRequest) message.getData();
    final IKafkaProducerService producerService = getKafkaProducer();
    String replyToTopic = context.getKafkaNbWorkerTopic();
    SwitchId switchId = request.getSwitchId();
    DatapathId datapathId = DatapathId.of(switchId.toLong());
    long meterId = request.getMeterId();
    ISwitchManager switchManager = context.getSwitchManager();
    try {
        switchManager.modifyMeterForFlow(datapathId, meterId, request.getBandwidth());
        MeterEntry meterEntry = OfMeterConverter.toMeterEntry(switchManager.dumpMeterById(datapathId, meterId));
        SwitchMeterEntries response = SwitchMeterEntries.builder().switchId(switchId).meterEntries(ImmutableList.of(meterEntry)).build();
        InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), infoMessage);
    } catch (UnsupportedSwitchOperationException e) {
        String messageString = String.format("Not supported: %s", new SwitchId(e.getDpId().getLong()));
        logger.error(messageString, e);
        anError(ErrorType.PARAMETERS_INVALID).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    } catch (SwitchNotFoundException e) {
        logger.error("Update switch meters is unsuccessful. Switch {} not found", new SwitchId(e.getDpId().getLong()));
        anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(new SwitchId(e.getDpId().getLong()).toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    } catch (SwitchOperationException e) {
        String messageString = "Unable to update meter";
        logger.error(messageString, e);
        anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) SwitchId(org.openkilda.model.SwitchId) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) MeterEntry(org.openkilda.messaging.info.meter.MeterEntry) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) MeterModifyCommandRequest(org.openkilda.messaging.command.flow.MeterModifyCommandRequest)

Example 4 with UnsupportedSwitchOperationException

use of org.openkilda.floodlight.error.UnsupportedSwitchOperationException 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 5 with UnsupportedSwitchOperationException

use of org.openkilda.floodlight.error.UnsupportedSwitchOperationException in project open-kilda by telstra.

the class MetersResource method getMeters.

// FIXME(surabujin): is it used anywhere?
/**
 * Gets meters.
 * @return the map of meters.
 */
@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 {
        List<OFMeterConfig> meters = switchManager.dumpMeters(DatapathId.of(switchId));
        if (meters != null) {
            logger.debug("Meters from switch {} received: {}", switchId, meters.size());
            for (OFMeterConfig entry : meters) {
                response.put(entry.getMeterId(), entry);
            }
        }
    } catch (UnsupportedSwitchOperationException ex) {
        String messageString = "Not supported";
        logger.error("{}: {}", messageString, switchId, ex);
        MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, ex.getMessage());
        response.putAll(MAPPER.convertValue(responseMessage, Map.class));
        getResponse().setStatus(Status.SERVER_ERROR_NOT_IMPLEMENTED);
    } catch (IllegalArgumentException | SwitchOperationException exception) {
        String messageString = "No such switch";
        logger.error("{}: {}", messageString, switchId, exception);
        MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
        response.putAll(MAPPER.convertValue(responseMessage, Map.class));
        getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
    }
    return response;
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) HashMap(java.util.HashMap) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) MessageError(org.openkilda.messaging.error.MessageError) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) Get(org.restlet.resource.Get)

Aggregations

UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)7 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)4 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)4 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)4 MeterEntry (org.openkilda.messaging.info.meter.MeterEntry)3 SwitchMeterEntries (org.openkilda.messaging.info.meter.SwitchMeterEntries)3 OFMeterConfig (org.projectfloodlight.openflow.protocol.OFMeterConfig)3 Test (org.junit.Test)2 EffectiveIds (org.openkilda.floodlight.model.EffectiveIds)2 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)2 ErrorData (org.openkilda.messaging.error.ErrorData)2 FlowCommandErrorData (org.openkilda.messaging.error.rule.FlowCommandErrorData)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 SwitchMeterUnsupported (org.openkilda.messaging.info.meter.SwitchMeterUnsupported)2 SwitchId (org.openkilda.model.SwitchId)2 DatapathId (org.projectfloodlight.openflow.types.DatapathId)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1