Search in sources :

Example 11 with Meter

use of org.onosproject.net.meter.Meter 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 12 with Meter

use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.

the class DistributedMeterStoreTest method testInvalidCellId.

/**
 * Test invalid allocation of a cell id.
 */
@Test(expected = IllegalArgumentException.class)
public void testInvalidCellId() {
    initMeterStore(true);
    // MF defines an end index equals to 10
    Meter meterBad = DefaultMeter.builder().forDevice(did3).fromApp(APP_ID).withCellId(invalidCid).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(b1)).build();
    ((DefaultMeter) meterBad).setState(MeterState.PENDING_ADD);
    meterStore.addOrUpdateMeter(meterBad);
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DefaultMeter(org.onosproject.net.meter.DefaultMeter) Test(org.junit.Test)

Example 13 with Meter

use of org.onosproject.net.meter.Meter 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)

Example 14 with Meter

use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.

the class CorsaPipelineV3 method processMeterTable.

protected void processMeterTable(boolean install) {
    // Green meter : Pass all traffic
    Band dropBand = DefaultBand.builder().ofType(Band.Type.DROP).withRate(0xFFFFFFFF).build();
    MeterRequest.Builder ops = DefaultMeterRequest.builder().forDevice(deviceId).withBands(Collections.singletonList(dropBand)).fromApp(appId);
    Meter meter = meterService.submit(install ? ops.add() : ops.remove());
    defaultMeterId = meter.id();
}
Also used : Meter(org.onosproject.net.meter.Meter) Band(org.onosproject.net.meter.Band) DefaultBand(org.onosproject.net.meter.DefaultBand) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest)

Example 15 with Meter

use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.

the class MeterManager method submit.

@Override
public Meter submit(MeterRequest request) {
    checkNotNull(request, "request cannot be null.");
    MeterCellId cellId;
    if (request.index().isPresent()) {
        checkArgument(userDefinedIndex, "Index cannot be provided when userDefinedIndex mode is disabled");
        // User provides index
        if (request.scope().isGlobal()) {
            cellId = MeterId.meterId(request.index().get());
        } else {
            cellId = PiMeterCellId.ofIndirect(PiMeterId.of(request.scope().id()), request.index().get());
        }
    } else {
        checkArgument(!userDefinedIndex, "Index cannot be allocated when userDefinedIndex mode is enabled");
        // Allocate an id
        cellId = allocateMeterId(request.deviceId(), request.scope());
    }
    Meter.Builder mBuilder = DefaultMeter.builder().forDevice(request.deviceId()).fromApp(request.appId()).withBands(request.bands()).withCellId(cellId).withUnit(request.unit());
    if (request.isBurst()) {
        mBuilder.burst();
    }
    if (request.annotations() != null && !request.annotations().keys().isEmpty()) {
        mBuilder.withAnnotations(request.annotations());
    }
    DefaultMeter m = (DefaultMeter) mBuilder.build();
    // Meter installation logic (happy ending case)
    // PENDING -> stats -> ADDED -> future completes
    m.setState(MeterState.PENDING_ADD);
    store.addOrUpdateMeter(m).whenComplete((result, error) -> onComplete.accept(request, result, error));
    return m;
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DefaultMeter(org.onosproject.net.meter.DefaultMeter) MeterCellId(org.onosproject.net.meter.MeterCellId) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId)

Aggregations

Meter (org.onosproject.net.meter.Meter)45 DefaultMeter (org.onosproject.net.meter.DefaultMeter)32 Test (org.junit.Test)21 DeviceId (org.onosproject.net.DeviceId)12 MeterService (org.onosproject.net.meter.MeterService)8 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)8 MeterCellId (org.onosproject.net.meter.MeterCellId)7 MeterKey (org.onosproject.net.meter.MeterKey)7 Produces (javax.ws.rs.Produces)6 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Band (org.onosproject.net.meter.Band)5 DefaultBand (org.onosproject.net.meter.DefaultBand)4 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)4 MeterOperation (org.onosproject.net.meter.MeterOperation)4 MeterRequest (org.onosproject.net.meter.MeterRequest)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Maps (com.google.common.collect.Maps)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3