Search in sources :

Example 16 with DefaultMeter

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

the class DistributedMeterStoreTest method testStoreMeter.

/**
 * Test store meter.
 */
@Test
public void testStoreMeter() {
    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);
    MeterKey meterKey = MeterKey.key(did1, mid1);
    assertThat(1, is(meterStore.getAllMeters().size()));
    assertThat(1, is(meterStore.getAllMeters(did1).size()));
    assertThat(m1, 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) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterCellId(org.onosproject.net.meter.MeterCellId) Test(org.junit.Test)

Example 17 with DefaultMeter

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

the class DistributedMeterStoreTest method testDeleteMeter.

/**
 * Test delete meter.
 */
@Test
public void testDeleteMeter() {
    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);
    ((DefaultMeter) meterOne).setState(MeterState.PENDING_REMOVE);
    MeterKey meterKey = MeterKey.key(did1, mid1);
    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(did1).size()));
    assertNull(meterStore.getMeter(meterKey));
    assertThat(mid1, is(meterStore.allocateMeterId(did1, MeterScope.globalScope())));
}
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) ExecutionException(java.util.concurrent.ExecutionException) 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