Search in sources :

Example 11 with MeterKey

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

the class DistributedMeterStore method addOrUpdateMeter.

@Override
public CompletableFuture<MeterStoreResult> addOrUpdateMeter(Meter meter) {
    checkArgument(validIndex(meter), "Meter index is not valid");
    CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
    MeterKey key = MeterKey.key(meter.deviceId(), meter.meterCellId());
    MeterData data = new MeterData(meter, null);
    futures.put(key, future);
    try {
        meters.compute(key, (k, v) -> data);
    } 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) StorageException(org.onosproject.store.service.StorageException)

Example 12 with MeterKey

use of org.onosproject.net.meter.MeterKey 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)

Example 13 with MeterKey

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

the class SimpleVirtualMeterStore method updateMeterState.

@Override
public void updateMeterState(NetworkId networkId, Meter meter) {
    ConcurrentMap<MeterKey, MeterData> meters = getMetersByNetwork(networkId);
    MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
    meters.computeIfPresent(key, (k, v) -> {
        DefaultMeter m = (DefaultMeter) v.meter();
        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, v.origin());
    });
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) DefaultMeter(org.onosproject.net.meter.DefaultMeter)

Example 14 with MeterKey

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

the class SimpleVirtualMeterStore method failedMeter.

@Override
public void failedMeter(NetworkId networkId, MeterOperation op, MeterFailReason reason) {
    ConcurrentMap<MeterKey, MeterData> meters = getMetersByNetwork(networkId);
    MeterKey key = MeterKey.key(op.meter().deviceId(), op.meter().id());
    meters.computeIfPresent(key, (k, v) -> new MeterData(v.meter(), reason, v.origin()));
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey)

Example 15 with MeterKey

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

the class SimpleVirtualMeterStore method deleteMeterNow.

@Override
public void deleteMeterNow(NetworkId networkId, Meter m) {
    ConcurrentMap<MeterKey, MeterData> meters = getMetersByNetwork(networkId);
    ConcurrentMap<MeterKey, CompletableFuture<MeterStoreResult>> futures = getFuturesByNetwork(networkId);
    MeterKey key = MeterKey.key(m.deviceId(), m.id());
    futures.remove(key);
    meters.remove(key);
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) CompletableFuture(java.util.concurrent.CompletableFuture)

Aggregations

MeterKey (org.onosproject.net.meter.MeterKey)20 DefaultMeter (org.onosproject.net.meter.DefaultMeter)11 Test (org.junit.Test)7 Meter (org.onosproject.net.meter.Meter)7 CompletableFuture (java.util.concurrent.CompletableFuture)6 StorageException (org.onosproject.store.service.StorageException)6 MeterStoreResult (org.onosproject.net.meter.MeterStoreResult)5 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)5 MeterCellId (org.onosproject.net.meter.MeterCellId)4 DeviceId (org.onosproject.net.DeviceId)3 Collections2 (com.google.common.collect.Collections2)2 Maps (com.google.common.collect.Maps)2 Collection (java.util.Collection)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 ClusterService (org.onosproject.cluster.ClusterService)2 NodeId (org.onosproject.cluster.NodeId)2 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)2 VirtualNetworkMeterStore (org.onosproject.incubator.net.virtual.VirtualNetworkMeterStore)2