Search in sources :

Example 1 with MeterOperation

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

the class DefaultVirtualMeterProvider method activate.

@Activate
public void activate() {
    providerRegistryService.registerProvider(this);
    internalMeterListener = new InternalMeterListener();
    idGenerator = getIdGenerator();
    pendingOperations = CacheBuilder.newBuilder().expireAfterWrite(TIMEOUT, TimeUnit.SECONDS).removalListener((RemovalNotification<Long, VirtualMeterOperation> notification) -> {
        if (notification.getCause() == RemovalCause.EXPIRED) {
            NetworkId networkId = notification.getValue().networkId();
            MeterOperation op = notification.getValue().operation();
            VirtualMeterProviderService providerService = (VirtualMeterProviderService) providerRegistryService.getProviderService(networkId, VirtualMeterProvider.class);
            providerService.meterOperationFailed(op, MeterFailReason.TIMEOUT);
        }
    }).build();
    meterService.addListener(internalMeterListener);
    log.info("Started");
}
Also used : VirtualMeterProvider(org.onosproject.incubator.net.virtual.provider.VirtualMeterProvider) VirtualMeterProviderService(org.onosproject.incubator.net.virtual.provider.VirtualMeterProviderService) RemovalNotification(com.google.common.cache.RemovalNotification) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) MeterOperation(org.onosproject.net.meter.MeterOperation) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with MeterOperation

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

the class MeterManagerTest method testAddBatchFromMeterProgrammable.

/**
 * Test batch submission for meter programmable.
 */
@Test
public void testAddBatchFromMeterProgrammable() {
    initMeterStore();
    List<MeterOperation> operations = ImmutableList.of(new MeterOperation(mProgrammable, MeterOperation.Type.ADD));
    manager.defaultProvider().performMeterOperation(PROGRAMMABLE_DID, new MeterOperations(operations));
    TestTools.assertAfter(500, () -> {
        assertEquals("The meter was not added", 1, meterOperations.size());
        assertEquals("Wrong Meter Operation", meterOperations.get(0).meter().id(), mProgrammable.id());
    });
}
Also used : MeterOperations(org.onosproject.net.meter.MeterOperations) MeterOperation(org.onosproject.net.meter.MeterOperation) Test(org.junit.Test)

Example 3 with MeterOperation

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

the class MeterManagerTest method testUnknownFromMeterProgrammable.

/**
 * Verify removal of unknown meters when using meter programmable devices.
 */
@Test
public void testUnknownFromMeterProgrammable() {
    meterOperations.clear();
    testGetFromMeterProgrammable();
    TestMeterProgrammable.unknownMeter = true;
    assertThat(meterOperations.size(), is(1));
    TestTools.assertAfter(2000, () -> {
        assertEquals("The meter was not added", 1, manager.getAllMeters().size());
        Meter pendingMeter = manager.getMeter(PROGRAMMABLE_DID, MeterId.meterId(2));
        assertNull(pendingMeter);
        assertThat(meterOperations.size(), is(2));
        assertThat(meterOperations.get(meterOperations.size() - 1), is(new MeterOperation(mProgrammable2, MeterOperation.Type.REMOVE)));
    });
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) MeterOperation(org.onosproject.net.meter.MeterOperation) Test(org.junit.Test)

Example 4 with MeterOperation

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

the class MeterManagerTest method testMissingFromMeterProgrammable.

/**
 * Verify installation of missing meters when using meter programmable devices.
 */
@Test
public void testMissingFromMeterProgrammable() {
    // Workaround when running the tests all together
    meterOperations.clear();
    testGetFromMeterProgrammable();
    assertThat(meterOperations.size(), is(1));
    manager.submit(mProgrammableRequest2.add());
    TestTools.assertAfter(500, () -> {
        assertEquals("The meter was not added", 2, manager.getAllMeters().size());
        assertThat(manager.getMeter(PROGRAMMABLE_DID, MeterId.meterId(2)), is(mProgrammable2));
        assertThat(meterOperations.size(), is(2));
        assertThat(meterOperations.get(meterOperations.size() - 1), is(new MeterOperation(mProgrammable2, MeterOperation.Type.ADD)));
    });
    TestTools.assertAfter(2000, () -> {
        assertEquals("The meter was not added", 2, manager.getAllMeters().size());
        Meter pendingMeter = manager.getMeter(PROGRAMMABLE_DID, MeterId.meterId(2));
        assertThat(pendingMeter, is(mProgrammable2));
        assertEquals("incorrect state", MeterState.PENDING_ADD, pendingMeter.state());
        assertThat(meterOperations.size(), is(3));
        assertThat(meterOperations.get(meterOperations.size() - 1), is(new MeterOperation(mProgrammable2, MeterOperation.Type.ADD)));
    });
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) MeterOperation(org.onosproject.net.meter.MeterOperation) Test(org.junit.Test)

Aggregations

MeterOperation (org.onosproject.net.meter.MeterOperation)4 Test (org.junit.Test)3 DefaultMeter (org.onosproject.net.meter.DefaultMeter)2 Meter (org.onosproject.net.meter.Meter)2 RemovalNotification (com.google.common.cache.RemovalNotification)1 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)1 VirtualMeterProvider (org.onosproject.incubator.net.virtual.provider.VirtualMeterProvider)1 VirtualMeterProviderService (org.onosproject.incubator.net.virtual.provider.VirtualMeterProviderService)1 MeterOperations (org.onosproject.net.meter.MeterOperations)1 Activate (org.osgi.service.component.annotations.Activate)1