use of org.projectfloodlight.openflow.protocol.OFMeterConfig 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);
}
}
use of org.projectfloodlight.openflow.protocol.OFMeterConfig 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.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.
the class MeterVerifyCommand method handleMeterStats.
private MeterSchema handleMeterStats(List<OFMeterConfigStatsReply> meterStatResponses) {
Optional<OFMeterConfig> target = Optional.empty();
for (OFMeterConfigStatsReply meterConfigReply : meterStatResponses) {
target = findMeter(meterConfigReply);
if (target.isPresent()) {
break;
}
}
if (!target.isPresent()) {
throw maskCallbackException(new SwitchMissingMeterException(getSw().getId(), meterConfig.getId()));
}
boolean isInaccurate = getSwitchFeatures().contains(SwitchFeature.INACCURATE_METER);
MeterSchema schema = MeterSchemaMapper.INSTANCE.map(getSw().getId(), target.get(), isInaccurate);
validateMeterConfig(schema, isInaccurate);
return schema;
}
use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.
the class SwitchManagerTest method mockGetMetersRequest.
private void mockGetMetersRequest(List<Long> meterIds, boolean supportsPkts, long rate, long burstSize) throws Exception {
List<OFMeterConfig> meterConfigs = new ArrayList<>(meterIds.size());
for (Long meterId : meterIds) {
OFMeterBandDrop bandDrop = mock(OFMeterBandDrop.class);
expect(bandDrop.getRate()).andStubReturn(rate);
expect(bandDrop.getBurstSize()).andStubReturn(burstSize);
OFMeterConfig meterConfig = mock(OFMeterConfig.class);
expect(meterConfig.getEntries()).andStubReturn(Collections.singletonList(bandDrop));
expect(meterConfig.getMeterId()).andStubReturn(meterId);
Set<OFMeterFlags> flags = ImmutableSet.of(OFMeterFlags.STATS, OFMeterFlags.BURST, supportsPkts ? OFMeterFlags.PKTPS : OFMeterFlags.KBPS);
expect(meterConfig.getFlags()).andStubReturn(flags);
replay(bandDrop, meterConfig);
meterConfigs.add(meterConfig);
}
OFMeterConfigStatsReply statsReply = mock(OFMeterConfigStatsReply.class);
expect(statsReply.getEntries()).andStubReturn(meterConfigs);
ListenableFuture<List<OFMeterConfigStatsReply>> ofStatsFuture = mock(ListenableFuture.class);
expect(ofStatsFuture.get(anyLong(), anyObject())).andStubReturn(Collections.singletonList(statsReply));
replay(statsReply, ofStatsFuture);
expect(iofSwitch.writeStatsRequest(isA(OFMeterConfigStatsRequest.class))).andStubReturn(ofStatsFuture);
}
use of org.projectfloodlight.openflow.protocol.OFMeterConfig in project open-kilda by telstra.
the class SwitchManagerTest method dumpMetersTimeoutException.
@Test
public void dumpMetersTimeoutException() throws SwitchOperationException, InterruptedException, ExecutionException, TimeoutException {
ListenableFuture<List<OFMeterConfigStatsReply>> ofStatsFuture = createMock(ListenableFuture.class);
expect(ofStatsFuture.get(anyLong(), anyObject())).andThrow(new TimeoutException());
expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
expect(switchDescription.getManufacturerDescription()).andStubReturn("");
expect(iofSwitch.getSwitchDescription()).andStubReturn(switchDescription);
expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
expect(iofSwitch.writeStatsRequest(isA(OFMeterConfigStatsRequest.class))).andStubReturn(ofStatsFuture);
replay(ofSwitchService, iofSwitch, switchDescription, ofStatsFuture);
List<OFMeterConfig> meters = switchManager.dumpMeters(dpid);
assertNotNull(meters);
assertTrue(meters.isEmpty());
}
Aggregations