Search in sources :

Example 21 with Meter

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

the class OpenFlowMeterProvider method pushMeterStats.

private void pushMeterStats(Dpid dpid, OFStatsReply msg) {
    DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
    if (msg.getStatsType() == OFStatsType.METER) {
        OFMeterStatsReply reply = (OFMeterStatsReply) msg;
        Collection<Meter> meters = buildMeters(deviceId, reply.getEntries());
        // TODO do meter accounting here.
        providerService.pushMeterMetrics(deviceId, meters);
    } else if (msg.getStatsType() == OFStatsType.METER_CONFIG) {
        OFMeterConfigStatsReply reply = (OFMeterConfigStatsReply) msg;
    // FIXME: Map<Long, Meter> meters = collectMeters(deviceId, reply);
    }
}
Also used : OFMeterConfigStatsReply(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply) DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) OFMeterStatsReply(org.projectfloodlight.openflow.protocol.OFMeterStatsReply)

Example 22 with Meter

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

the class P4RuntimeMeterProgrammable method getMeters.

@Override
public CompletableFuture<Collection<Meter>> getMeters() {
    if (!setupBehaviour("getMeters()")) {
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    Collection<PiMeterCellConfig> piMeterCellConfigs;
    Set<PiMeterId> meterIds = new HashSet<>();
    for (PiMeterModel mode : pipelineModel.meters()) {
        meterIds.add(mode.id());
    }
    piMeterCellConfigs = client.read(p4DeviceId, pipeconf).meterCells(meterIds).submitSync().all(PiMeterCellConfig.class).stream().filter(piMeterCellConfig -> !piMeterCellConfig.isDefaultConfig()).collect(Collectors.toList());
    if (piMeterCellConfigs.isEmpty()) {
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    List<PiMeterCellId> inconsistentOrDefaultCells = Lists.newArrayList();
    List<Meter> meters = Lists.newArrayList();
    // Check the consistency of meter config
    for (PiMeterCellConfig config : piMeterCellConfigs) {
        PiMeterCellHandle handle = PiMeterCellHandle.of(deviceId, config);
        DefaultMeter meter = (DefaultMeter) forgeMeter(config, handle);
        if (meter == null) {
            // A default config cannot be used to forge meter
            // because meter has at least 1 band while default config has no band
            inconsistentOrDefaultCells.add(config.cellId());
        } else {
            meters.add(meter);
        }
    }
    // Reset all inconsistent meter cells to the default config
    if (!inconsistentOrDefaultCells.isEmpty()) {
        WriteRequest request = client.write(p4DeviceId, pipeconf);
        inconsistentOrDefaultCells.forEach(cellId -> request.entity(PiMeterCellConfig.reset(cellId), UpdateType.MODIFY));
        request.submit().whenComplete((response, ex) -> {
            if (ex != null) {
                log.error("Exception resetting inconsistent meter entries", ex);
            } else {
                log.debug("Successfully removed {} out of {} inconsistent meter entries", response.success().size(), response.all().size());
            }
        });
    }
    return CompletableFuture.completedFuture(meters);
}
Also used : PiMeterId(org.onosproject.net.pi.model.PiMeterId) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) PiMeterCellConfig(org.onosproject.net.pi.runtime.PiMeterCellConfig) PiMeterModel(org.onosproject.net.pi.model.PiMeterModel) WriteRequest(org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest) DefaultMeter(org.onosproject.net.meter.DefaultMeter) PiMeterCellHandle(org.onosproject.net.pi.runtime.PiMeterCellHandle) HashSet(java.util.HashSet)

Example 23 with Meter

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

the class P4RuntimeMeterProgrammable method forgeMeter.

private Meter forgeMeter(PiMeterCellConfig config, PiMeterCellHandle handle) {
    final Optional<PiTranslatedEntity<Meter, PiMeterCellConfig>> translatedEntity = translator.lookup(handle);
    // is default configuration.
    if (translatedEntity.isEmpty()) {
        if (!config.isDefaultConfig()) {
            log.warn("Meter Cell Config obtained from device {} is different from " + "one in in translation store: device={}, store=Default", deviceId, config);
        } else {
            log.debug("Configs for {} obtained from device: {} and from the store are default, " + "skipping the forge section", config.cellId(), deviceId);
        }
        return null;
    }
    // that config from devices can be default which means no band
    if (!isSimilar(translatedEntity.get().translated(), config)) {
        log.warn("Meter Cell Config obtained from device {} is different from " + "one in in translation store: device={}, store={}", deviceId, config, translatedEntity.get().translated());
        return null;
    }
    Meter original = translatedEntity.get().original();
    // Forge a meter with MeterCellId, Bands and DeviceId using the original value.
    DefaultMeter meter = (DefaultMeter) DefaultMeter.builder().withBands(original.bands()).withCellId(original.meterCellId()).forDevice(deviceId).build();
    meter.setState(MeterState.ADDED);
    return meter;
}
Also used : PiTranslatedEntity(org.onosproject.net.pi.service.PiTranslatedEntity) DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DefaultMeter(org.onosproject.net.meter.DefaultMeter)

Example 24 with Meter

use of org.onosproject.net.meter.Meter in project fabric-tna by stratum.

the class MockMeterService method submit.

@Override
public Meter submit(MeterRequest meter) {
    Meter addedMeter = DefaultMeter.builder().forDevice(meter.deviceId()).fromApp(meter.appId()).withUnit(meter.unit()).withBands(meter.bands()).withCellId(PiMeterCellId.ofIndirect(PiMeterId.of(meter.scope().id()), meter.index().get())).build();
    ((DefaultMeter) addedMeter).setState(MeterState.ADDED);
    meters.add(addedMeter);
    return addedMeter;
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DefaultMeter(org.onosproject.net.meter.DefaultMeter)

Example 25 with Meter

use of org.onosproject.net.meter.Meter 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)

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