Search in sources :

Example 6 with MeterTableKey

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());
}
Also used : MeterTableKey(org.onosproject.net.meter.MeterTableKey) Test(org.junit.Test)

Example 7 with MeterTableKey

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());
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) MeterTableKey(org.onosproject.net.meter.MeterTableKey) DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DefaultMeter(org.onosproject.net.meter.DefaultMeter) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 8 with MeterTableKey

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();
}
Also used : MeterTableKey(org.onosproject.net.meter.MeterTableKey) MeterQuery(org.onosproject.net.behaviour.MeterQuery) DriverHandler(org.onosproject.net.driver.DriverHandler)

Example 9 with MeterTableKey

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);
}
Also used : MeterTableKey(org.onosproject.net.meter.MeterTableKey)

Example 10 with MeterTableKey

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;
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) DefaultMeter(org.onosproject.net.meter.DefaultMeter) Collections2(com.google.common.collect.Collections2) DriverService(org.onosproject.net.driver.DriverService) MeterStoreDelegate(org.onosproject.net.meter.MeterStoreDelegate) PiMeterId(org.onosproject.net.pi.model.PiMeterId) RandomUtils(org.apache.commons.lang.math.RandomUtils) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) StorageService(org.onosproject.store.service.StorageService) MeterCellId(org.onosproject.net.meter.MeterCellId) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) DefaultDistributedSet(org.onosproject.store.primitives.DefaultDistributedSet) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MeterFailReason(org.onosproject.net.meter.MeterFailReason) MeterQuery(org.onosproject.net.behaviour.MeterQuery) Band(org.onosproject.net.meter.Band) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) MeterEvent(org.onosproject.net.meter.MeterEvent) MeterScope(org.onosproject.net.meter.MeterScope) EventuallyConsistentMapEvent(org.onosproject.store.service.EventuallyConsistentMapEvent) MeterOperation(org.onosproject.net.meter.MeterOperation) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) AtomicCounterMap(org.onosproject.store.service.AtomicCounterMap) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Versioned(org.onosproject.store.service.Versioned) INDEX(org.onosproject.net.meter.MeterCellId.MeterCellType.INDEX) List(java.util.List) FIRST_FIT(org.onosproject.store.meter.impl.DistributedMeterStore.ReuseStrategy.FIRST_FIT) MeterKey(org.onosproject.net.meter.MeterKey) DeviceId(org.onosproject.net.DeviceId) MeterStore(org.onosproject.net.meter.MeterStore) Iterables(com.google.common.collect.Iterables) StorageException(org.onosproject.store.service.StorageException) MeterFeatures(org.onosproject.net.meter.MeterFeatures) MeterTableKey(org.onosproject.net.meter.MeterTableKey) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterId(org.onosproject.net.meter.MeterId) CompletableFuture(java.util.concurrent.CompletableFuture) KryoNamespace(org.onlab.util.KryoNamespace) DistributedPrimitive(org.onosproject.store.service.DistributedPrimitive) MapEventListener(org.onosproject.store.service.MapEventListener) ConcurrentMap(java.util.concurrent.ConcurrentMap) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) FAIL(org.onosproject.net.meter.MeterStoreResult.Type.FAIL) Activate(org.osgi.service.component.annotations.Activate) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) EventuallyConsistentMapListener(org.onosproject.store.service.EventuallyConsistentMapListener) Meter(org.onosproject.net.meter.Meter) Logger(org.slf4j.Logger) DefaultBand(org.onosproject.net.meter.DefaultBand) Maps(com.google.common.collect.Maps) MeterState(org.onosproject.net.meter.MeterState) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DriverHandler(org.onosproject.net.driver.DriverHandler) DistributedSet(org.onosproject.store.service.DistributedSet) TIMEOUT(org.onosproject.net.meter.MeterFailReason.TIMEOUT) DefaultMeterFeatures(org.onosproject.net.meter.DefaultMeterFeatures) MapEvent(org.onosproject.store.service.MapEvent) AbstractStore(org.onosproject.store.AbstractStore) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) PIPELINE_INDEPENDENT(org.onosproject.net.meter.MeterCellId.MeterCellType.PIPELINE_INDEPENDENT) MeterFeaturesFlag(org.onosproject.net.meter.MeterFeaturesFlag) Reference(org.osgi.service.component.annotations.Reference) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) MeterTableKey(org.onosproject.net.meter.MeterTableKey) StorageException(org.onosproject.store.service.StorageException)

Aggregations

MeterTableKey (org.onosproject.net.meter.MeterTableKey)11 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)4 StorageException (org.onosproject.store.service.StorageException)4 DefaultMeterFeatures (org.onosproject.net.meter.DefaultMeterFeatures)3 MeterFeatures (org.onosproject.net.meter.MeterFeatures)3 MeterKey (org.onosproject.net.meter.MeterKey)3 MeterStoreResult (org.onosproject.net.meter.MeterStoreResult)3 Test (org.junit.Test)2 MeterQuery (org.onosproject.net.behaviour.MeterQuery)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2 DefaultMeter (org.onosproject.net.meter.DefaultMeter)2 Meter (org.onosproject.net.meter.Meter)2 MeterCellId (org.onosproject.net.meter.MeterCellId)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Collections2 (com.google.common.collect.Collections2)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Collection (java.util.Collection)1