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;
}
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;
}
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());
});
}
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()));
}
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);
}
Aggregations