use of org.onosproject.net.meter.MeterTableKey in project onos by opennetworkinglab.
the class DistributedMeterStoreTest method testFreeIdInUserMode.
/**
* Test free of meter ids in user defined index mode.
*/
@Test
public void testFreeIdInUserMode() {
initMeterStore(true);
meterStore.freeMeterId(did1, mid1);
MeterTableKey globalKey = MeterTableKey.key(did1, MeterScope.globalScope());
assertNotNull(meterStore.availableMeterIds.get(globalKey));
assertTrue(meterStore.availableMeterIds.get(globalKey).isEmpty());
}
use of org.onosproject.net.meter.MeterTableKey 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.MeterTableKey in project onos by opennetworkinglab.
the class DistributedMeterStore method queryMaxMeters.
// queryMaxMeters is implemented in MeterQuery behaviour implementations.
private long queryMaxMeters(DeviceId device) {
DriverHandler handler = driverService.createHandler(device);
if (handler == null || !handler.hasBehaviour(MeterQuery.class)) {
return 0L;
}
// FIXME architecturally this is not right, we should fallback to this
// behavior in the providers. Once we do that we can remove this code.
MeterQuery query = handler.behaviour(MeterQuery.class);
// This results to be necessary because the available ids sets are created
// in the meter features map listener if the device does not provide the meter
// feature this is the only chance to create this set.
String setName = AVAILABLEMETERIDSTORE + "-" + device + "global";
MeterTableKey meterTableKey = MeterTableKey.key(device, MeterScope.globalScope());
insertAvailableKeySet(meterTableKey, setName);
return query.getMaxMeters();
}
use of org.onosproject.net.meter.MeterTableKey in project onos by opennetworkinglab.
the class DistributedMeterStore method freeMeterId.
@Override
public void freeMeterId(DeviceId deviceId, MeterId meterId) {
MeterTableKey meterTableKey = MeterTableKey.key(deviceId, MeterScope.globalScope());
freeMeterId(meterTableKey, meterId);
}
use of org.onosproject.net.meter.MeterTableKey in project onos by opennetworkinglab.
the class DistributedMeterStore method deleteMeterFeatures.
@Override
public MeterStoreResult deleteMeterFeatures(DeviceId deviceId) {
MeterStoreResult result = MeterStoreResult.success();
try {
Set<MeterTableKey> keys = metersFeatures.keySet().stream().filter(key -> key.deviceId().equals(deviceId)).collect(Collectors.toUnmodifiableSet());
keys.forEach(k -> metersFeatures.remove(k));
} catch (StorageException e) {
log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
result = MeterStoreResult.fail(TIMEOUT);
}
return result;
}
Aggregations