use of org.openkilda.rulemanager.MeterSpeakerData in project open-kilda by telstra.
the class UniCastDiscoveryRuleGeneratorTest method shouldBuildCorrectRuleWithMeterForOf15.
@Test
public void shouldBuildCorrectRuleWithMeterForOf15() {
sw = buildSwitch("OF_15", Sets.newHashSet(METERS, PKTPS_FLAG));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(2, commands.size());
commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
assertEquals(1, flowCommandData.getDependsOn().size());
assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
Set<FieldMatch> match = flowCommandData.getMatch();
assertEquals(2, match.size());
checkMatch(match);
// Check flow command has correct instructions for OF 1.5
Instructions instructions = flowCommandData.getInstructions();
assertEquals(3, instructions.getApplyActions().size());
Action first = instructions.getApplyActions().get(0);
assertTrue(first instanceof MeterAction);
MeterAction meterAction = (MeterAction) first;
assertEquals(meterCommandData.getMeterId(), meterAction.getMeterId());
checkPortOutAction(instructions.getApplyActions().get(1));
checkSetFieldAction(instructions.getApplyActions().get(2));
assertNull(instructions.getWriteActions());
assertNull(instructions.getGoToMeter());
assertNull(instructions.getGoToTable());
// Check meter command
checkMeterCommand(meterCommandData);
}
use of org.openkilda.rulemanager.MeterSpeakerData in project open-kilda by telstra.
the class UniCastDiscoveryRuleGeneratorTest method shouldBuildCorrectRuleWithMeterInBytesForOf13.
@Test
public void shouldBuildCorrectRuleWithMeterInBytesForOf13() {
sw = buildSwitch("OF_13", Sets.newHashSet(METERS));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(2, commands.size());
commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
assertEquals(1, flowCommandData.getDependsOn().size());
assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
Set<FieldMatch> match = flowCommandData.getMatch();
assertEquals(2, match.size());
checkMatch(match);
checkInstructions(flowCommandData.getInstructions(), meterCommandData.getMeterId());
// Check meter command
assertEquals(createMeterIdForDefaultRule(VERIFICATION_UNICAST_RULE_COOKIE), meterCommandData.getMeterId());
long expectedRate = Meter.convertRateToKiloBits(config.getUnicastRateLimit(), config.getDiscoPacketSize());
assertEquals(expectedRate, meterCommandData.getRate());
long expectedBurst = Meter.convertBurstSizeToKiloBits(config.getSystemMeterBurstSizeInPackets(), config.getDiscoPacketSize());
assertEquals(expectedBurst, meterCommandData.getBurst());
assertEquals(3, meterCommandData.getFlags().size());
assertTrue(Sets.newHashSet(MeterFlag.BURST, MeterFlag.STATS, MeterFlag.KBPS).containsAll(meterCommandData.getFlags()));
}
use of org.openkilda.rulemanager.MeterSpeakerData 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);
}
}
use of org.openkilda.rulemanager.MeterSpeakerData 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.rulemanager.MeterSpeakerData 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