Search in sources :

Example 1 with MeterState

use of org.onosproject.net.meter.MeterState in project onos by opennetworkinglab.

the class DistributedMeterStore method updateMeterState.

@Override
public Meter updateMeterState(Meter meter) {
    // Update meter if present (stats workflow)
    MeterKey key = MeterKey.key(meter.deviceId(), meter.meterCellId());
    Versioned<MeterData> value = meters.computeIfPresent(key, (k, v) -> {
        DefaultMeter m = (DefaultMeter) v.meter();
        MeterState meterState = m.state();
        if (meterState == MeterState.PENDING_ADD) {
            m.setState(meter.state());
        }
        m.setProcessedPackets(meter.packetsSeen());
        m.setProcessedBytes(meter.bytesSeen());
        m.setLife(meter.life());
        // TODO: Prune if drops to zero.
        m.setReferenceCount(meter.referenceCount());
        return new MeterData(m, null);
    });
    return value != null ? value.value().meter() : null;
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) DefaultMeter(org.onosproject.net.meter.DefaultMeter) MeterState(org.onosproject.net.meter.MeterState)

Example 2 with MeterState

use of org.onosproject.net.meter.MeterState in project onos by opennetworkinglab.

the class DistributedMeterStore method deleteMeter.

@Override
public CompletableFuture<MeterStoreResult> deleteMeter(Meter meter) {
    CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
    MeterKey key = MeterKey.key(meter.deviceId(), meter.meterCellId());
    futures.put(key, future);
    // that it has been removed from the dataplane.
    try {
        Versioned<MeterData> versionedData = meters.computeIfPresent(key, (k, v) -> {
            DefaultMeter m = (DefaultMeter) v.meter();
            MeterState meterState = m.state();
            if (meterState == MeterState.PENDING_REMOVE) {
                return v;
            }
            m.setState(meter.state());
            return new MeterData(m, v.reason().isPresent() ? v.reason().get() : null);
        });
        // If it does not exist in the system, completes immediately
        if (versionedData == null) {
            futures.remove(key);
            future.complete(MeterStoreResult.success());
        }
    } catch (StorageException e) {
        log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
        futures.remove(key);
        future.completeExceptionally(e);
    }
    return future;
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultMeter(org.onosproject.net.meter.DefaultMeter) MeterState(org.onosproject.net.meter.MeterState) StorageException(org.onosproject.store.service.StorageException)

Aggregations

DefaultMeter (org.onosproject.net.meter.DefaultMeter)2 MeterKey (org.onosproject.net.meter.MeterKey)2 MeterState (org.onosproject.net.meter.MeterState)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 MeterStoreResult (org.onosproject.net.meter.MeterStoreResult)1 StorageException (org.onosproject.store.service.StorageException)1