Search in sources :

Example 26 with Meter

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());
}
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 27 with Meter

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

Example 28 with Meter

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));
    }
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) OFStatsReply(org.projectfloodlight.openflow.protocol.OFStatsReply) MeterProvider(org.onosproject.net.meter.MeterProvider) CoreService(org.onosproject.core.CoreService) MeterOperations(org.onosproject.net.meter.MeterOperations) DriverService(org.onosproject.net.driver.DriverService) Map(java.util.Map) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) OsgiPropertyConstants(org.onosproject.provider.of.meter.impl.OsgiPropertyConstants) Driver(org.onosproject.net.driver.Driver) MeterFailReason(org.onosproject.net.meter.MeterFailReason) DeviceId.deviceId(org.onosproject.net.DeviceId.deviceId) EnumSet(java.util.EnumSet) Band(org.onosproject.net.meter.Band) Dpid(org.onosproject.openflow.controller.Dpid) OFMeterBandStats(org.projectfloodlight.openflow.protocol.OFMeterBandStats) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) MeterOperation(org.onosproject.net.meter.MeterOperation) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ItemNotFoundException(org.onlab.util.ItemNotFoundException) OFErrorType(org.projectfloodlight.openflow.protocol.OFErrorType) Collectors(java.util.stream.Collectors) OpenFlowEventListener(org.onosproject.openflow.controller.OpenFlowEventListener) OFMeterFeatures(org.projectfloodlight.openflow.protocol.OFMeterFeatures) List(java.util.List) Dpid.uri(org.onosproject.openflow.controller.Dpid.uri) CacheBuilder(com.google.common.cache.CacheBuilder) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) OFVersion(org.projectfloodlight.openflow.protocol.OFVersion) OFPortStatus(org.projectfloodlight.openflow.protocol.OFPortStatus) MeterFeatures(org.onosproject.net.meter.MeterFeatures) Tools(org.onlab.util.Tools) OpenFlowSwitchListener(org.onosproject.openflow.controller.OpenFlowSwitchListener) ComponentContext(org.osgi.service.component.ComponentContext) MeterId(org.onosproject.net.meter.MeterId) Tools.getIntegerProperty(org.onlab.util.Tools.getIntegerProperty) MeterProviderService(org.onosproject.net.meter.MeterProviderService) Component(org.osgi.service.component.annotations.Component) Activate(org.osgi.service.component.annotations.Activate) OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) MeterProviderRegistry(org.onosproject.net.meter.MeterProviderRegistry) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) AbstractProvider(org.onosproject.net.provider.AbstractProvider) RemovalNotification(com.google.common.cache.RemovalNotification) OFMeterModFailedErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFMeterModFailedErrorMsg) Meter(org.onosproject.net.meter.Meter) Logger(org.slf4j.Logger) Properties(java.util.Properties) OFMeterConfigStatsReply(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply) OFStatsType(org.projectfloodlight.openflow.protocol.OFStatsType) DefaultBand(org.onosproject.net.meter.DefaultBand) RoleState(org.onosproject.openflow.controller.RoleState) ProviderId(org.onosproject.net.provider.ProviderId) OFMeterStatsReply(org.projectfloodlight.openflow.protocol.OFMeterStatsReply) Maps(com.google.common.collect.Maps) OpenFlowController(org.onosproject.openflow.controller.OpenFlowController) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) MeterState(org.onosproject.net.meter.MeterState) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) RemovalCause(com.google.common.cache.RemovalCause) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MeterFeaturesBuilder(org.onosproject.provider.of.meter.util.MeterFeaturesBuilder) Cache(com.google.common.cache.Cache) Reference(org.osgi.service.component.annotations.Reference) OFMeterStats(org.projectfloodlight.openflow.protocol.OFMeterStats) Properties(java.util.Properties) Modified(org.osgi.service.component.annotations.Modified)

Example 29 with Meter

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);
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) DefaultBand(org.onosproject.net.meter.DefaultBand) Band(org.onosproject.net.meter.Band) TestApplicationId(org.onosproject.TestApplicationId) ApplicationId(org.onosproject.core.ApplicationId) Test(org.junit.Test)

Example 30 with Meter

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;
}
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)

Aggregations

Meter (org.onosproject.net.meter.Meter)45 DefaultMeter (org.onosproject.net.meter.DefaultMeter)32 Test (org.junit.Test)21 DeviceId (org.onosproject.net.DeviceId)12 MeterService (org.onosproject.net.meter.MeterService)8 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)8 MeterCellId (org.onosproject.net.meter.MeterCellId)7 MeterKey (org.onosproject.net.meter.MeterKey)7 Produces (javax.ws.rs.Produces)6 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Band (org.onosproject.net.meter.Band)5 DefaultBand (org.onosproject.net.meter.DefaultBand)4 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)4 MeterOperation (org.onosproject.net.meter.MeterOperation)4 MeterRequest (org.onosproject.net.meter.MeterRequest)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Maps (com.google.common.collect.Maps)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3