Search in sources :

Example 1 with MeterKey

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

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

Example 3 with MeterKey

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));
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DefaultMeter(org.onosproject.net.meter.DefaultMeter) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterCellId(org.onosproject.net.meter.MeterCellId) Test(org.junit.Test)

Example 4 with MeterKey

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;
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) CompletableFuture(java.util.concurrent.CompletableFuture) StorageException(org.onosproject.store.service.StorageException)

Example 5 with MeterKey

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;
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) StorageException(org.onosproject.store.service.StorageException) DefaultMeter(org.onosproject.net.meter.DefaultMeter) MeterFeatures(org.onosproject.net.meter.MeterFeatures) CompletableFuture(java.util.concurrent.CompletableFuture) Collections2(com.google.common.collect.Collections2) MeterStoreDelegate(org.onosproject.net.meter.MeterStoreDelegate) ConcurrentMap(java.util.concurrent.ConcurrentMap) Component(org.osgi.service.component.annotations.Component) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) MeterFailReason(org.onosproject.net.meter.MeterFailReason) NodeId(org.onosproject.cluster.NodeId) Meter(org.onosproject.net.meter.Meter) MeterEvent(org.onosproject.net.meter.MeterEvent) Logger(org.slf4j.Logger) MeterFeaturesKey(org.onosproject.net.meter.MeterFeaturesKey) MeterOperation(org.onosproject.net.meter.MeterOperation) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Maps(com.google.common.collect.Maps) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) VirtualNetworkMeterStore(org.onosproject.incubator.net.virtual.VirtualNetworkMeterStore) TIMEOUT(org.onosproject.net.meter.MeterFailReason.TIMEOUT) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MeterKey(org.onosproject.net.meter.MeterKey) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) CompletableFuture(java.util.concurrent.CompletableFuture) StorageException(org.onosproject.store.service.StorageException)

Aggregations

MeterKey (org.onosproject.net.meter.MeterKey)20 DefaultMeter (org.onosproject.net.meter.DefaultMeter)11 Test (org.junit.Test)7 Meter (org.onosproject.net.meter.Meter)7 CompletableFuture (java.util.concurrent.CompletableFuture)6 StorageException (org.onosproject.store.service.StorageException)6 MeterStoreResult (org.onosproject.net.meter.MeterStoreResult)5 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)5 MeterCellId (org.onosproject.net.meter.MeterCellId)4 DeviceId (org.onosproject.net.DeviceId)3 Collections2 (com.google.common.collect.Collections2)2 Maps (com.google.common.collect.Maps)2 Collection (java.util.Collection)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 ClusterService (org.onosproject.cluster.ClusterService)2 NodeId (org.onosproject.cluster.NodeId)2 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)2 VirtualNetworkMeterStore (org.onosproject.incubator.net.virtual.VirtualNetworkMeterStore)2