Search in sources :

Example 1 with InvalidMeterIdException

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);
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFMeterFlags(org.projectfloodlight.openflow.protocol.OFMeterFlags) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException)

Example 2 with InvalidMeterIdException

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));
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) MeteredFlowGenerator(org.openkilda.floodlight.switchmanager.factory.generator.MeteredFlowGenerator) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException)

Example 3 with InvalidMeterIdException

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);
    }
}
Also used : ModifyMeterResponse(org.openkilda.messaging.info.switches.ModifyMeterResponse) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException) SwitchId(org.openkilda.model.SwitchId) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ErrorType(org.openkilda.messaging.error.ErrorType) ModifyDefaultMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) OfInstallException(org.openkilda.floodlight.error.OfInstallException)

Example 4 with InvalidMeterIdException

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.");
    }
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException)

Aggregations

InvalidMeterIdException (org.openkilda.floodlight.error.InvalidMeterIdException)4 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)3 OfInstallException (org.openkilda.floodlight.error.OfInstallException)1 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)1 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)1 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)1 MeteredFlowGenerator (org.openkilda.floodlight.switchmanager.factory.generator.MeteredFlowGenerator)1 ModifyDefaultMeterForSwitchManagerRequest (org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest)1 ErrorType (org.openkilda.messaging.error.ErrorType)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 ModifyMeterResponse (org.openkilda.messaging.info.switches.ModifyMeterResponse)1 SwitchId (org.openkilda.model.SwitchId)1 OFMeterFlags (org.projectfloodlight.openflow.protocol.OFMeterFlags)1 DatapathId (org.projectfloodlight.openflow.types.DatapathId)1