use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class SimpleVirtualMeterStore method updateMeter.
@Override
public CompletableFuture<MeterStoreResult> updateMeter(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 {
if (meters.computeIfPresent(key, (k, v) -> data) == null) {
future.complete(MeterStoreResult.fail(MeterFailReason.INVALID_METER));
}
} catch (StorageException e) {
future.completeExceptionally(e);
}
return future;
}
use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testDeleteMeterInUserDefinedIndexMode.
/**
* Test delete meter in user defined index mode.
*/
@Test
public void testDeleteMeterInUserDefinedIndexMode() {
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);
((DefaultMeter) meterOne).setState(MeterState.PENDING_REMOVE);
MeterKey meterKey = MeterKey.key(did3, cid4);
meterStore.deleteMeter(meterOne);
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> meterStore.purgeMeter(meterOne));
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
assertThat(0, is(meterStore.getAllMeters().size()));
assertThat(0, is(meterStore.getAllMeters(did3).size()));
assertNull(meterStore.getMeter(meterKey));
MeterTableKey globalKey = MeterTableKey.key(did1, MeterScope.globalScope());
assertNotNull(meterStore.availableMeterIds.get(globalKey));
assertTrue(meterStore.availableMeterIds.get(globalKey).isEmpty());
}
use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testPurgeMetersDeviceAndApp.
/**
* Test purge meter given device and application.
*/
@Test
public void testPurgeMetersDeviceAndApp() {
initMeterStore(false);
((DefaultMeter) m1).setState(MeterState.PENDING_ADD);
((DefaultMeter) m2).setState(MeterState.PENDING_ADD);
((DefaultMeter) m3).setState(MeterState.PENDING_ADD);
meterStore.addOrUpdateMeter(m1);
meterStore.addOrUpdateMeter(m2);
meterStore.addOrUpdateMeter(m3);
assertThat(3, is(meterStore.getAllMeters().size()));
meterStore.purgeMeters(did1, APP_ID_2);
MeterKey keyTwo = MeterKey.key(did1, mid2);
assertThat(2, is(meterStore.getAllMeters().size()));
assertThat(1, is(meterStore.getAllMeters(did1).size()));
assertThat(1, is(meterStore.getAllMeters(did2).size()));
assertNull(meterStore.getMeter(keyTwo));
}
use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testStoreMeter.
/**
* Test store meter.
*/
@Test
public void testStoreMeter() {
initMeterStore(false);
MeterCellId idOne = meterStore.allocateMeterId(did1, MeterScope.globalScope());
assertThat(mid1, is(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_ADD);
meterStore.addOrUpdateMeter(meterOne);
MeterKey meterKey = MeterKey.key(did1, mid1);
assertThat(1, is(meterStore.getAllMeters().size()));
assertThat(1, is(meterStore.getAllMeters(did1).size()));
assertThat(m1, is(meterStore.getMeter(meterKey)));
}
use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testDeleteMeter.
/**
* Test delete meter.
*/
@Test
public void testDeleteMeter() {
initMeterStore(false);
MeterCellId idOne = meterStore.allocateMeterId(did1, MeterScope.globalScope());
assertThat(mid1, is(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_ADD);
meterStore.addOrUpdateMeter(meterOne);
((DefaultMeter) meterOne).setState(MeterState.PENDING_REMOVE);
MeterKey meterKey = MeterKey.key(did1, mid1);
meterStore.deleteMeter(meterOne);
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> meterStore.purgeMeter(meterOne));
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
assertThat(0, is(meterStore.getAllMeters().size()));
assertThat(0, is(meterStore.getAllMeters(did1).size()));
assertNull(meterStore.getMeter(meterKey));
assertThat(mid1, is(meterStore.allocateMeterId(did1, MeterScope.globalScope())));
}
Aggregations