Search in sources :

Example 1 with DefaultMeter

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

the class VirtualNetworkMeterManager method withdraw.

@Override
public void withdraw(MeterRequest request, MeterCellId meterCellId) {
    Meter.Builder mBuilder = DefaultMeter.builder().forDevice(request.deviceId()).fromApp(request.appId()).withBands(request.bands()).withCellId(meterCellId).withUnit(request.unit());
    if (request.isBurst()) {
        mBuilder.burst();
    }
    DefaultMeter m = (DefaultMeter) mBuilder.build();
    m.setState(MeterState.PENDING_REMOVE);
    store.deleteMeter(networkId(), m).whenComplete((result, error) -> onComplete.accept(request, result, error));
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DefaultMeter(org.onosproject.net.meter.DefaultMeter)

Example 2 with DefaultMeter

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

Example 3 with DefaultMeter

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

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

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

the class DistributedMeterStoreTest method testGetMetersImmutability.

/**
 * Test getMeters API immutability.
 */
@Test
public void testGetMetersImmutability() {
    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);
    Collection<Meter> meters = meterStore.getAllMeters();
    Collection<Meter> metersDevice = meterStore.getAllMeters(did1);
    assertThat(1, is(meters.size()));
    assertThat(1, is(metersDevice.size()));
    MeterCellId idTwo = meterStore.allocateMeterId(did1, MeterScope.globalScope());
    assertThat(mid2, is(idTwo));
    Meter meterTwo = DefaultMeter.builder().forDevice(did1).fromApp(APP_ID).withId(mid2).withUnit(Meter.Unit.KB_PER_SEC).withBands(Collections.singletonList(b1)).build();
    ((DefaultMeter) meterTwo).setState(MeterState.PENDING_ADD);
    meterStore.addOrUpdateMeter(meterTwo);
    assertThat(1, is(meters.size()));
    assertThat(1, is(metersDevice.size()));
    meters = meterStore.getAllMeters();
    metersDevice = meterStore.getAllMeters(did1);
    assertThat(2, is(meters.size()));
    assertThat(2, is(metersDevice.size()));
}
Also used : 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)

Aggregations

DefaultMeter (org.onosproject.net.meter.DefaultMeter)17 Meter (org.onosproject.net.meter.Meter)13 MeterKey (org.onosproject.net.meter.MeterKey)9 Test (org.junit.Test)8 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)6 MeterCellId (org.onosproject.net.meter.MeterCellId)5 ExecutionException (java.util.concurrent.ExecutionException)2 MeterState (org.onosproject.net.meter.MeterState)2 PiMeterCellConfig (org.onosproject.net.pi.runtime.PiMeterCellConfig)2 HashSet (java.util.HashSet)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 MeterId (org.onosproject.net.meter.MeterId)1 MeterStoreResult (org.onosproject.net.meter.MeterStoreResult)1 MeterTableKey (org.onosproject.net.meter.MeterTableKey)1 PiMeterId (org.onosproject.net.pi.model.PiMeterId)1 PiMeterModel (org.onosproject.net.pi.model.PiMeterModel)1 PiMeterCellHandle (org.onosproject.net.pi.runtime.PiMeterCellHandle)1 PiTranslatedEntity (org.onosproject.net.pi.service.PiTranslatedEntity)1 WriteRequest (org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest)1 StorageException (org.onosproject.store.service.StorageException)1