use of org.openkilda.floodlight.error.InvalidMeterIdException in project open-kilda by telstra.
the class SwitchManager method modifyMeterForFlow.
/**
* {@inheritDoc}
*/
@Override
public void modifyMeterForFlow(DatapathId dpid, long meterId, long bandwidth) throws SwitchOperationException {
if (!MeterId.isMeterIdOfFlowRule(meterId)) {
throw new InvalidMeterIdException(dpid, format("Could not modify meter '%d' on switch '%s'. Meter Id is invalid. Valid meter id range is " + "[%d, %d]", meterId, dpid, MeterId.MIN_FLOW_METER_ID, MeterId.MAX_FLOW_METER_ID));
}
IOFSwitch sw = lookupSwitch(dpid);
verifySwitchSupportsMeters(sw);
long burstSize = Meter.calculateBurstSize(bandwidth, config.getFlowMeterMinBurstSizeInKbits(), config.getFlowMeterBurstCoefficient(), sw.getSwitchDescription().getManufacturerDescription(), sw.getSwitchDescription().getSoftwareDescription());
Set<OFMeterFlags> flags = Arrays.stream(Meter.getMeterKbpsFlags()).map(OFMeterFlags::valueOf).collect(Collectors.toSet());
modifyMeter(sw, bandwidth, burstSize, meterId, flags);
}
use of org.openkilda.floodlight.error.InvalidMeterIdException in project open-kilda by telstra.
the class SwitchManager method modifyDefaultMeter.
@Override
public void modifyDefaultMeter(DatapathId dpid, long meterId) throws SwitchNotFoundException, InvalidMeterIdException, UnsupportedSwitchOperationException, OfInstallException {
if (!DEFAULT_METERS.contains(meterId)) {
throw new InvalidMeterIdException(dpid, format("Could not modify meter '%d' onto switch '%s' because meter is invalid. " + "Valid default meter IDs are: %s", meterId, dpid, DEFAULT_METERS));
}
IOFSwitch sw = lookupSwitch(dpid);
verifySwitchSupportsMeters(sw);
MeteredFlowGenerator generator = getGeneratorByMeterId(meterId).orElseThrow(() -> new InvalidMeterIdException(dpid, format("Couldn't modify meter %d on switch %s. Meter ID is unknown.", meterId, dpid)));
logger.info("Modifying meter {} on Switch {}", meterId, dpid);
pushFlow(sw, "--ModifyMeter--", generator.generateMeterModify(sw));
}
use of org.openkilda.floodlight.error.InvalidMeterIdException in project open-kilda by telstra.
the class RecordHandler method doModifyDefaultMeterForSwitchManager.
private void doModifyDefaultMeterForSwitchManager(CommandMessage message) {
ModifyDefaultMeterForSwitchManagerRequest request = (ModifyDefaultMeterForSwitchManagerRequest) message.getData();
IKafkaProducerService producerService = getKafkaProducer();
String replyToTopic = context.getKafkaSwitchManagerTopic();
long meterId = request.getMeterId();
SwitchId switchId = request.getSwitchId();
DatapathId dpid = DatapathId.of(switchId.toLong());
try {
context.getSwitchManager().modifyDefaultMeter(dpid, request.getMeterId());
InfoMessage response = new InfoMessage(new ModifyMeterResponse(switchId, request.getMeterId()), System.currentTimeMillis(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
} catch (UnsupportedSwitchOperationException e) {
logger.warn(format("Skip meter %d modification on switch %s because switch doesn't support meters", meterId, switchId), e);
} catch (InvalidMeterIdException | OfInstallException | SwitchNotFoundException e) {
logger.error("Failed to modify meter {} for switch: '{}'", request.getSwitchId(), meterId, e);
ErrorType errorType;
if (e instanceof InvalidMeterIdException) {
errorType = ErrorType.DATA_INVALID;
} else if (e instanceof SwitchNotFoundException) {
errorType = ErrorType.NOT_FOUND;
} else {
errorType = ErrorType.INTERNAL_ERROR;
}
anError(errorType).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
use of org.openkilda.floodlight.error.InvalidMeterIdException in project open-kilda by telstra.
the class SwitchManager method deleteMeter.
/**
* {@inheritDoc}
*/
@Override
public void deleteMeter(final DatapathId dpid, final long meterId) throws SwitchOperationException {
if (meterId > 0L) {
IOFSwitch sw = lookupSwitch(dpid);
verifySwitchSupportsMeters(sw);
buildAndDeleteMeter(sw, dpid, meterId);
// to ensure that we have completed meter deletion, because we might have remove/create meter in a row
sendBarrierRequest(sw);
} else {
throw new InvalidMeterIdException(dpid, "Meter id must be positive.");
}
}
Aggregations