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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations