Search in sources :

Example 11 with DefaultMeter

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

the class VirtualNetworkMeterManager method submit.

@Override
public Meter submit(MeterRequest request) {
    MeterId id = allocateMeterId(request.deviceId());
    Meter.Builder mBuilder = DefaultMeter.builder().forDevice(request.deviceId()).fromApp(request.appId()).withBands(request.bands()).withId(id).withUnit(request.unit());
    if (request.isBurst()) {
        mBuilder.burst();
    }
    DefaultMeter m = (DefaultMeter) mBuilder.build();
    m.setState(MeterState.PENDING_ADD);
    store.storeMeter(networkId(), 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) MeterId(org.onosproject.net.meter.MeterId)

Example 12 with DefaultMeter

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

the class MeterManager method withdraw.

@Override
public void withdraw(MeterRequest request, MeterCellId meterCellId) {
    checkNotNull(request, "request cannot be null.");
    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();
    // Meter removal logic (happy ending case)
    // PENDING -> stats -> removed from the map -> future completes
    m.setState(MeterState.PENDING_REMOVE);
    store.deleteMeter(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 13 with DefaultMeter

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

the class SimpleVirtualMeterStore method updateMeterState.

@Override
public void updateMeterState(NetworkId networkId, Meter meter) {
    ConcurrentMap<MeterKey, MeterData> meters = getMetersByNetwork(networkId);
    MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
    meters.computeIfPresent(key, (k, v) -> {
        DefaultMeter m = (DefaultMeter) v.meter();
        m.setState(meter.state());
        m.setProcessedPackets(meter.packetsSeen());
        m.setProcessedBytes(meter.bytesSeen());
        m.setLife(meter.life());
        // TODO: Prune if drops to zero.
        m.setReferenceCount(meter.referenceCount());
        return new MeterData(m, null, v.origin());
    });
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) DefaultMeter(org.onosproject.net.meter.DefaultMeter)

Example 14 with DefaultMeter

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

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

the class DistributedMeterStoreTest method testPurgeMetersDeviceAndApp.

/**
 * Test purge meter given device and application.
 */
@Test
public void testPurgeMetersDeviceAndApp() {
    initMeterStore(false);
    ((DefaultMeter) m1).setState(MeterState.PENDING_ADD);
    ((DefaultMeter) m2).setState(MeterState.PENDING_ADD);
    ((DefaultMeter) m3).setState(MeterState.PENDING_ADD);
    meterStore.addOrUpdateMeter(m1);
    meterStore.addOrUpdateMeter(m2);
    meterStore.addOrUpdateMeter(m3);
    assertThat(3, is(meterStore.getAllMeters().size()));
    meterStore.purgeMeters(did1, APP_ID_2);
    MeterKey keyTwo = MeterKey.key(did1, mid2);
    assertThat(2, is(meterStore.getAllMeters().size()));
    assertThat(1, is(meterStore.getAllMeters(did1).size()));
    assertThat(1, is(meterStore.getAllMeters(did2).size()));
    assertNull(meterStore.getMeter(keyTwo));
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) DefaultMeter(org.onosproject.net.meter.DefaultMeter) 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