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");
}
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());
});
}
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)));
});
}
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)));
});
}
Aggregations