use of org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult in project open-kilda by telstra.
the class ValidationServiceImplTest method validateMetersProperMeters.
@Test
public void validateMetersProperMeters() {
ValidationService validationService = new ValidationServiceImpl(persistenceManager().build());
MeterSpeakerData meter = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(10000).burst(10500).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
ValidateMetersResult response = validationService.validateMeters(SWITCH_ID_B, singletonList(meter), singletonList(meter));
assertTrue(response.getMissingMeters().isEmpty());
assertTrue(response.getMisconfiguredMeters().isEmpty());
assertFalse(response.getProperMeters().isEmpty());
assertEquals(meter.getMeterId().getValue(), response.getProperMeters().get(0).getMeterId().longValue());
assertMeter(response.getProperMeters().get(0), 32, 10000, 10500, new String[] { "KBPS", "BURST", "STATS" });
assertTrue(response.getExcessMeters().isEmpty());
}
use of org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult in project open-kilda by telstra.
the class SwitchValidateServiceImplTest method setUp.
@Before
public void setUp() {
RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
SwitchRepository switchRepository = Mockito.mock(SwitchRepository.class);
when(switchRepository.findById(eq(SWITCH_ID))).thenReturn(Optional.of(SWITCH_1));
when(switchRepository.findById(eq(SWITCH_ID_MISSING))).thenReturn(Optional.empty());
LagLogicalPortRepository lagLogicalPortRepository = Mockito.mock(LagLogicalPortRepository.class);
when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
when(repositoryFactory.createSwitchRepository()).thenReturn(switchRepository);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
service = new SwitchValidateServiceImpl(carrier, persistenceManager, validationService, ruleManager);
request = SwitchValidateRequest.builder().switchId(SWITCH_ID).processMeters(true).build();
flowSpeakerData = FlowSpeakerData.builder().ofVersion(OfVersion.OF_13).cookie(new Cookie(1L)).table(OfTable.INPUT).priority(10).match(emptySet()).instructions(Instructions.builder().build()).flags(emptySet()).build();
meterSpeakerData = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(10000).burst(10500).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
when(validationService.validateRules(any(), any(), any())).thenReturn(new ValidateRulesResult(newHashSet(flowSpeakerData.getCookie().getValue()), emptySet(), emptySet(), emptySet()));
when(validationService.validateMeters(any(), any(), any())).thenReturn(new ValidateMetersResult(emptyList(), emptyList(), emptyList(), emptyList()));
}
use of org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult 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.wfm.topology.switchmanager.model.ValidateMetersResult 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.wfm.topology.switchmanager.model.ValidateMetersResult in project open-kilda by telstra.
the class ValidationServiceImplTest method validateMetersProperMetersESwitch.
@Test
public void validateMetersProperMetersESwitch() {
ValidationService validationService = new ValidationServiceImpl(persistenceManager().build());
long rateESwitch = FLOW_E_BANDWIDTH + (long) (FLOW_E_BANDWIDTH * 0.01) - 1;
long burstSize = (long) (FLOW_E_BANDWIDTH * 1.05);
long burstSizeESwitch = burstSize + (long) (burstSize * 0.01) - 1;
MeterSpeakerData meter = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(rateESwitch).burst(burstSizeESwitch).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
ValidateMetersResult response = validationService.validateMeters(SWITCH_ID_E, singletonList(meter), singletonList(meter));
assertTrue(response.getMissingMeters().isEmpty());
assertTrue(response.getMisconfiguredMeters().isEmpty());
assertFalse(response.getProperMeters().isEmpty());
assertEquals(32L, (long) response.getProperMeters().get(0).getMeterId());
assertMeter(response.getProperMeters().get(0), 32, rateESwitch, burstSizeESwitch, new String[] { "KBPS", "BURST", "STATS" });
assertTrue(response.getExcessMeters().isEmpty());
}
Aggregations