use of org.onosproject.net.meter.Meter 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());
}
use of org.onosproject.net.meter.Meter 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())));
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class OpenFlowMeterProvider method modified.
@Modified
public void modified(ComponentContext context) {
Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
// update FORCE_STATS_AFTER_METER_REMOVAL if needed
Boolean forceStatsAfterMeterRemovalEnabled = Tools.isPropertyEnabled(properties, FORCE_STATS_AFTER_METER_REMOVAL);
if (forceStatsAfterMeterRemovalEnabled == null) {
log.info("forceStatsAfterMeterRemoval is not configured, " + "using current value of {}", forceStatsAfterMeterRemoval);
} else {
forceStatsAfterMeterRemoval = forceStatsAfterMeterRemovalEnabled;
log.info("Configured. forceStatsAfterMeterRemoval is {}", forceStatsAfterMeterRemovalEnabled ? "enabled" : "disabled");
}
// update METER_STATS_POLL_INTERVAL if needed
Integer newMeterPollInterval = getIntegerProperty(properties, METER_STATS_POLL_INTERVAL);
if (newMeterPollInterval != null && newMeterPollInterval > 0 && newMeterPollInterval != meterStatsPollInterval) {
meterStatsPollInterval = newMeterPollInterval;
// restart meter stats collectors, old instances will be automatically purged before creation
// in the call to createStatsCollection
controller.getSwitches().forEach((sw -> {
createStatsCollection(sw);
}));
log.info("Configured. meterStatsPollInterval to {}", newMeterPollInterval);
} else if (newMeterPollInterval != null && newMeterPollInterval <= 0) {
log.warn("meterStatsPollInterval must be greater than 0");
// Reset property with the old value
cfgService.setProperty(getClass().getName(), METER_STATS_POLL_INTERVAL, Integer.toString(meterStatsPollInterval));
}
}
use of org.onosproject.net.meter.Meter in project onos by opennetworkinglab.
the class BandwidthProfileTest method testMeterConversion.
@Test
public void testMeterConversion() {
DeviceId deviceId = DeviceId.deviceId("netconf:10.0.0.1:22");
ApplicationId appId = TestApplicationId.create("org.onosproject.foo.app");
Meter.Builder meterBuilder = new DefaultMeter.Builder().withId(MeterId.meterId(ONE)).withUnit(Meter.Unit.KB_PER_SEC).forDevice(deviceId).burst();
// Create Meter with single band
Band band1 = DefaultBand.builder().ofType(Band.Type.DROP).withRate(TEN_M).burstSize(TWO_K).build();
Meter meter = meterBuilder.fromApp(appId).withBands(Arrays.asList(band1)).build();
BandwidthProfile bandwidthProfile = BandwidthProfile.fromMeter(meter);
assertEquals("wrong bw profile name", bandwidthProfile.name(), meter.id().toString());
assertEquals("wrong bw profile type", bandwidthProfile.type(), BandwidthProfile.Type.sr2CM);
assertEquals("wrong bw profile CIR", bandwidthProfile.cir().bps(), band1.rate() * EIGHT_K, 0);
assertEquals("wrong bw profile CBS", (long) bandwidthProfile.cbs(), (long) band1.burst());
assertNull(bandwidthProfile.pir());
assertNull(bandwidthProfile.pbs());
assertNull(bandwidthProfile.ebs());
assertEquals("wrong green action", bandwidthProfile.greenAction(), getBuilder(Action.PASS).build());
assertNull(bandwidthProfile.yellowAction());
assertEquals("wrong red action", bandwidthProfile.redAction(), getBuilder(Action.DISCARD).build());
assertEquals("wrong color-aware mode", bandwidthProfile.colorAware(), false);
// Create Meter with two bands
Band band2 = DefaultBand.builder().burstSize(ONE_K).ofType(Band.Type.REMARK).dropPrecedence((short) 0b001010).withRate(ONE_M).build();
meter = meterBuilder.fromApp(appId).withBands(Arrays.asList(band1, band2)).build();
bandwidthProfile = BandwidthProfile.fromMeter(meter);
assertEquals("wrong bw profile name", bandwidthProfile.name(), meter.id().toString());
assertEquals("wrong bw profile type", bandwidthProfile.type(), BandwidthProfile.Type.trTCM);
assertEquals("wrong bw profile CIR", bandwidthProfile.cir().bps(), band2.rate() * EIGHT_K, 0);
assertEquals("wrong bw profile CBS", (long) bandwidthProfile.cbs(), (long) band2.burst());
assertEquals("wrong bw profile PIR", bandwidthProfile.pir().bps(), band1.rate() * EIGHT_K, 0);
assertEquals("wrong bw profile PBS", (long) bandwidthProfile.pbs(), (long) band1.burst());
assertNull(bandwidthProfile.ebs());
assertEquals("wrong green action", bandwidthProfile.greenAction(), getBuilder(Action.PASS).build());
assertEquals("wrong yellow action", bandwidthProfile.yellowAction(), getBuilder(Action.REMARK).dscpClass(DscpClass.AF11).build());
assertEquals("wrong red action", bandwidthProfile.redAction(), getBuilder(Action.DISCARD).build());
assertEquals("wrong color-aware mode", bandwidthProfile.colorAware(), false);
}
use of org.onosproject.net.meter.Meter 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;
}
Aggregations