Search in sources :

Example 11 with PiMeterCellId

use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.

the class P4RuntimeMeterProgrammable method processMeterOp.

private boolean processMeterOp(MeterOperation meterOp) {
    PiMeterCellConfig piMeterCellConfig;
    final PiMeterCellHandle handle = PiMeterCellHandle.of(deviceId, (PiMeterCellId) meterOp.meter().meterCellId());
    boolean result = true;
    WRITE_LOCKS.get(deviceId).lock();
    try {
        switch(meterOp.type()) {
            case ADD:
            case MODIFY:
                // Create a config for modify operation
                try {
                    piMeterCellConfig = translator.translate(meterOp.meter(), pipeconf);
                } catch (PiTranslationException e) {
                    log.warn("Unable translate meter, aborting meter operation {}: {}", meterOp.type(), e.getMessage());
                    log.debug("exception", e);
                    return false;
                }
                translator.learn(handle, new PiTranslatedEntity<>(meterOp.meter(), piMeterCellConfig, handle));
                break;
            case REMOVE:
                // Create a empty config for reset operation
                PiMeterCellId piMeterCellId = (PiMeterCellId) meterOp.meter().meterCellId();
                piMeterCellConfig = PiMeterCellConfig.reset(piMeterCellId);
                translator.forget(handle);
                break;
            default:
                log.warn("Meter Operation type {} not supported", meterOp.type());
                return false;
        }
        WriteRequest request = client.write(p4DeviceId, pipeconf).entity(piMeterCellConfig, UpdateType.MODIFY);
        if (!request.pendingUpdates().isEmpty()) {
            result = request.submitSync().isSuccess();
        }
    } finally {
        WRITE_LOCKS.get(deviceId).unlock();
    }
    return result;
}
Also used : PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) PiMeterCellConfig(org.onosproject.net.pi.runtime.PiMeterCellConfig) WriteRequest(org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest) PiTranslationException(org.onosproject.net.pi.service.PiTranslationException) PiMeterCellHandle(org.onosproject.net.pi.runtime.PiMeterCellHandle)

Aggregations

PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)11 MeterTableKey (org.onosproject.net.meter.MeterTableKey)4 PiMeterId (org.onosproject.net.pi.model.PiMeterId)4 MeterId (org.onosproject.net.meter.MeterId)2 MeterScope (org.onosproject.net.meter.MeterScope)2 PiMeterCellConfig (org.onosproject.net.pi.runtime.PiMeterCellConfig)2 PiMeterCellHandle (org.onosproject.net.pi.runtime.PiMeterCellHandle)2 WriteRequest (org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest)2 P4RuntimeOuterClass (p4.v1.P4RuntimeOuterClass)2 HashSet (java.util.HashSet)1 UpfMeter (org.onosproject.net.behaviour.upf.UpfMeter)1 Band (org.onosproject.net.meter.Band)1 DefaultBand (org.onosproject.net.meter.DefaultBand)1 DefaultMeter (org.onosproject.net.meter.DefaultMeter)1 DefaultMeterFeatures (org.onosproject.net.meter.DefaultMeterFeatures)1 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)1 Meter (org.onosproject.net.meter.Meter)1 MeterCellId (org.onosproject.net.meter.MeterCellId)1 MeterFeatures (org.onosproject.net.meter.MeterFeatures)1 MeterKey (org.onosproject.net.meter.MeterKey)1