use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testStoreMeterInUserDefinedIndexMode.
/**
* Test store meter in user defined index mode.
*/
@Test
public void testStoreMeterInUserDefinedIndexMode() {
initMeterStore(true);
Meter meterOne = DefaultMeter.builder().forDevice(did3).fromApp(APP_ID).withCellId(cid4).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(b1)).build();
((DefaultMeter) meterOne).setState(MeterState.PENDING_ADD);
meterStore.addOrUpdateMeter(meterOne);
MeterKey meterKey = MeterKey.key(did3, cid4);
assertThat(1, is(meterStore.getAllMeters().size()));
assertThat(1, is(meterStore.getAllMeters(did3).size()));
assertThat(m4, is(meterStore.getMeter(meterKey)));
}
use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testPurgeMeters.
/**
* Test purge meter.
*/
@Test
public void testPurgeMeters() {
testStoreMeter();
meterStore.purgeMeters(did1);
MeterKey keyOne = MeterKey.key(did1, mid1);
assertThat(0, is(meterStore.getAllMeters().size()));
assertThat(0, is(meterStore.getAllMeters(did1).size()));
assertNull(meterStore.getMeter(keyOne));
}
use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testNoDeleteMeter.
/**
* Test no delete meter.
*/
@Test
public void testNoDeleteMeter() {
initMeterStore(false);
MeterCellId idOne = meterStore.allocateMeterId(did1, MeterScope.globalScope());
MeterKey keyOne = MeterKey.key(did1, idOne);
Meter meterOne = DefaultMeter.builder().forDevice(did1).fromApp(APP_ID).withId(mid1).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(b1)).build();
((DefaultMeter) meterOne).setState(MeterState.PENDING_REMOVE);
meterStore.deleteMeter(meterOne);
assertThat(0, is(meterStore.getAllMeters().size()));
assertThat(0, is(meterStore.getAllMeters(did1).size()));
assertNull(meterStore.getMeter(keyOne));
}
use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class SimpleVirtualMeterStore method storeMeter.
@Override
public CompletableFuture<MeterStoreResult> storeMeter(NetworkId networkId, Meter meter) {
ConcurrentMap<MeterKey, MeterData> meters = getMetersByNetwork(networkId);
ConcurrentMap<MeterKey, CompletableFuture<MeterStoreResult>> futures = getFuturesByNetwork(networkId);
CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
futures.put(key, future);
MeterData data = new MeterData(meter, null, local);
try {
meters.put(key, data);
} catch (StorageException e) {
future.completeExceptionally(e);
}
return future;
}
use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class SimpleVirtualMeterStore method deleteMeter.
@Override
public CompletableFuture<MeterStoreResult> deleteMeter(NetworkId networkId, Meter meter) {
ConcurrentMap<MeterKey, MeterData> meters = getMetersByNetwork(networkId);
ConcurrentMap<MeterKey, CompletableFuture<MeterStoreResult>> futures = getFuturesByNetwork(networkId);
CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
futures.put(key, future);
MeterData data = new MeterData(meter, null, local);
// that it has been removed from the dataplane.
try {
if (meters.computeIfPresent(key, (k, v) -> data) == null) {
future.complete(MeterStoreResult.success());
}
} catch (StorageException e) {
future.completeExceptionally(e);
}
return future;
}
Aggregations