Search in sources :

Example 1 with MeterInfoEntry

use of org.openkilda.messaging.info.switches.MeterInfoEntry in project open-kilda by telstra.

the class SwitchSyncServiceImplTest method receiveMetersSyncError.

@Test
public void receiveMetersSyncError() {
    request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).removeExcess(true).build();
    missingRules = emptyList();
    excessMeters = singletonList(new MeterInfoEntry(EXCESS_COOKIE, EXCESS_COOKIE, FLOW_ID, 0L, 0L, new String[] {}, null, null));
    service.handleSwitchSync(KEY, request, makeValidationResult());
    verify(carrier).sendCommandToSpeaker(eq(KEY), any(CommandData.class));
    ErrorMessage errorMessage = getErrorMessage();
    service.handleTaskError(KEY, errorMessage);
    verify(carrier).cancelTimeoutCallback(eq(KEY));
    verify(carrier).response(eq(KEY), any(ErrorMessage.class));
    verifyNoMoreInteractions(commandBuilder);
    verifyNoMoreInteractions(carrier);
}
Also used : MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) Test(org.junit.Test)

Example 2 with MeterInfoEntry

use of org.openkilda.messaging.info.switches.MeterInfoEntry in project open-kilda by telstra.

the class ValidationServiceImpl method getExcessMeters.

private List<MeterInfoEntry> getExcessMeters(List<MeterInfoEntry> presented, List<MeterInfoEntry> expected) {
    List<MeterInfoEntry> excessMeters = new ArrayList<>();
    Set<Long> expectedMeterIds = expected.stream().map(MeterInfoEntry::getMeterId).collect(Collectors.toSet());
    for (MeterInfoEntry meterEntry : presented) {
        if (!expectedMeterIds.contains(meterEntry.getMeterId())) {
            excessMeters.add(meterEntry);
        }
    }
    return excessMeters;
}
Also used : MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) ArrayList(java.util.ArrayList)

Example 3 with MeterInfoEntry

use of org.openkilda.messaging.info.switches.MeterInfoEntry in project open-kilda by telstra.

the class ValidationServiceImpl method comparePresentedAndExpectedMeters.

private ValidateMetersResult comparePresentedAndExpectedMeters(boolean isESwitch, List<MeterInfoEntry> presentMeters, List<MeterInfoEntry> expectedMeters) {
    Map<Long, MeterInfoEntry> presentMeterMap = presentMeters.stream().collect(Collectors.toMap(MeterInfoEntry::getMeterId, Function.identity()));
    List<MeterInfoEntry> missingMeters = new ArrayList<>();
    List<MeterInfoEntry> misconfiguredMeters = new ArrayList<>();
    List<MeterInfoEntry> properMeters = new ArrayList<>();
    for (MeterInfoEntry expectedMeter : expectedMeters) {
        MeterInfoEntry presentedMeter = presentMeterMap.get(expectedMeter.getMeterId());
        if (presentedMeter == null) {
            missingMeters.add(expectedMeter);
            continue;
        }
        if (Meter.equalsRate(presentedMeter.getRate(), expectedMeter.getRate(), isESwitch) && Meter.equalsBurstSize(presentedMeter.getBurstSize(), expectedMeter.getBurstSize(), isESwitch) && flagsAreEqual(presentedMeter.getFlags(), expectedMeter.getFlags())) {
            properMeters.add(presentedMeter);
        } else {
            misconfiguredMeters.add(makeMisconfiguredMeterEntry(presentedMeter, expectedMeter, isESwitch));
        }
    }
    List<MeterInfoEntry> excessMeters = getExcessMeters(presentMeters, expectedMeters);
    excessMeters.sort(Comparator.comparing(MeterInfoEntry::getMeterId));
    missingMeters.sort(Comparator.comparing(MeterInfoEntry::getMeterId));
    misconfiguredMeters.sort(Comparator.comparing(MeterInfoEntry::getMeterId));
    properMeters.sort(Comparator.comparing(MeterInfoEntry::getMeterId));
    return new ValidateMetersResult(missingMeters, misconfiguredMeters, properMeters, excessMeters);
}
Also used : MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) ArrayList(java.util.ArrayList)

Example 4 with MeterInfoEntry

use of org.openkilda.messaging.info.switches.MeterInfoEntry in project open-kilda by telstra.

the class ValidationServiceImpl method validateMeters.

@Override
public ValidateMetersResult validateMeters(SwitchId switchId, List<MeterSpeakerData> presentMeters, List<MeterSpeakerData> expectedMeterSpeakerData) {
    log.debug("Validating meters on switch {}", switchId);
    Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
    boolean isESwitch = Switch.isNoviflowESwitch(sw.getOfDescriptionManufacturer(), sw.getOfDescriptionHardware());
    List<MeterInfoEntry> actualMeters = presentMeters.stream().map(meter -> convertMeter(switchId, meter)).collect(toList());
    List<MeterInfoEntry> expectedMeters = expectedMeterSpeakerData.stream().map(meter -> convertMeter(switchId, meter)).collect(toList());
    ValidateMetersResult result = comparePresentedAndExpectedMeters(isESwitch, actualMeters, expectedMeters);
    if (!result.getMissingMeters().isEmpty() && log.isErrorEnabled()) {
        log.error("On switch {} the following meters are missed: {}", switchId, metersIntoLogRepresentation(result.getMissingMeters()));
    }
    if (!result.getExcessMeters().isEmpty() && log.isWarnEnabled()) {
        log.warn("On switch {} the following meters are excessive: {}", switchId, metersIntoLogRepresentation(result.getExcessMeters()));
    }
    if (!result.getMisconfiguredMeters().isEmpty() && log.isWarnEnabled()) {
        for (MeterInfoEntry meter : result.getMisconfiguredMeters()) {
            log.warn("On switch {} meter {} is misconfigured: {}", switchId, meter.getMeterId(), getMisconfiguredMeterDifferenceAsString(meter.getExpected(), meter.getActual()));
        }
    }
    return result;
}
Also used : Arrays(java.util.Arrays) FlowPath(org.openkilda.model.FlowPath) ValidationService(org.openkilda.wfm.topology.switchmanager.service.ValidationService) LogicalPortInfoEntry(org.openkilda.messaging.info.switches.LogicalPortInfoEntry) Map(java.util.Map) FlowMeterRepository(org.openkilda.persistence.repositories.FlowMeterRepository) ValidateLogicalPortsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateLogicalPortsResult) ImmutableSet(com.google.common.collect.ImmutableSet) LogicalPortMisconfiguredInfoEntry(org.openkilda.messaging.info.switches.LogicalPortMisconfiguredInfoEntry) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) MeterEntryConverter(org.openkilda.wfm.topology.switchmanager.mappers.MeterEntryConverter) Collection(java.util.Collection) Set(java.util.Set) GroupEntryConverter(org.openkilda.wfm.topology.switchmanager.mappers.GroupEntryConverter) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) Meter(org.openkilda.model.Meter) GroupInfoEntry(org.openkilda.messaging.info.switches.GroupInfoEntry) MeterMisconfiguredInfoEntry(org.openkilda.messaging.info.switches.MeterMisconfiguredInfoEntry) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) FlowMeter(org.openkilda.model.FlowMeter) LogicalPort(org.openkilda.messaging.model.grpc.LogicalPort) BucketEntry(org.openkilda.messaging.info.switches.GroupInfoEntry.BucketEntry) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) ImmutableList(com.google.common.collect.ImmutableList) Cookie(org.openkilda.model.cookie.Cookie) LogicalPortMapper(org.openkilda.wfm.topology.switchmanager.mappers.LogicalPortMapper) PersistenceManager(org.openkilda.persistence.PersistenceManager) ValidateGroupsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateGroupsResult) LogicalPortType(org.openkilda.messaging.info.switches.LogicalPortType) Switch(org.openkilda.model.Switch) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Collectors.toList(java.util.stream.Collectors.toList) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchId(org.openkilda.model.SwitchId) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) LagLogicalPortRepository(org.openkilda.persistence.repositories.LagLogicalPortRepository) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) Switch(org.openkilda.model.Switch) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException)

Example 5 with MeterInfoEntry

use of org.openkilda.messaging.info.switches.MeterInfoEntry 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

MeterInfoEntry (org.openkilda.messaging.info.switches.MeterInfoEntry)9 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ValidateMetersResult (org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult)4 FlowPath (org.openkilda.model.FlowPath)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 String.format (java.lang.String.format)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 CommandData (org.openkilda.messaging.command.CommandData)2 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)2 SwitchValidateRequest (org.openkilda.messaging.command.switches.SwitchValidateRequest)2 ValidationResult (org.openkilda.wfm.topology.switchmanager.model.ValidationResult)2 Generators (com.fasterxml.uuid.Generators)1 NoArgGenerator (com.fasterxml.uuid.NoArgGenerator)1