Search in sources :

Example 6 with PiMeterCellId

use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.

the class DistributedMeterStore method validIndex.

// Validate index using the meter features, useful mainly
// when user defined index mode is enabled
private boolean validIndex(Meter meter) {
    long index;
    MeterTableKey key;
    if (meter.meterCellId().type() == PIPELINE_INDEPENDENT) {
        PiMeterCellId piMeterCellId = (PiMeterCellId) meter.meterCellId();
        index = piMeterCellId.index();
        key = MeterTableKey.key(meter.deviceId(), MeterScope.of(piMeterCellId.meterId().id()));
    } else if (meter.meterCellId().type() == INDEX) {
        MeterId meterId = (MeterId) meter.meterCellId();
        index = meterId.id();
        key = MeterTableKey.key(meter.deviceId(), MeterScope.globalScope());
    } else {
        log.warn("Unable to validate index unsupported cell type {}", meter.meterCellId().type());
        return false;
    }
    MeterFeatures features = metersFeatures.get(key);
    long startIndex = features == null ? -1L : features.startIndex();
    long endIndex = features == null ? -1L : features.endIndex();
    return index >= startIndex && index <= endIndex;
}
Also used : MeterTableKey(org.onosproject.net.meter.MeterTableKey) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterFeatures(org.onosproject.net.meter.MeterFeatures) DefaultMeterFeatures(org.onosproject.net.meter.DefaultMeterFeatures) PiMeterId(org.onosproject.net.pi.model.PiMeterId) MeterId(org.onosproject.net.meter.MeterId)

Example 7 with PiMeterCellId

use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.

the class DistributedMeterStore method purgeMeter.

@Override
public void purgeMeter(Meter m) {
    // Once we receive the ack from the sb, create the key
    // remove definitely the meter and free the id
    MeterKey key = MeterKey.key(m.deviceId(), m.meterCellId());
    try {
        if (Versioned.valueOrNull(meters.remove(key)) != null) {
            MeterScope scope;
            if (m.meterCellId().type() == PIPELINE_INDEPENDENT) {
                PiMeterCellId piMeterCellId = (PiMeterCellId) m.meterCellId();
                scope = MeterScope.of(piMeterCellId.meterId().id());
            } else {
                scope = MeterScope.globalScope();
            }
            MeterTableKey meterTableKey = MeterTableKey.key(m.deviceId(), scope);
            freeMeterId(meterTableKey, m.meterCellId());
        }
    } catch (StorageException e) {
        log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
    }
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) MeterTableKey(org.onosproject.net.meter.MeterTableKey) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterScope(org.onosproject.net.meter.MeterScope) StorageException(org.onosproject.store.service.StorageException)

Example 8 with PiMeterCellId

use of org.onosproject.net.pi.runtime.PiMeterCellId in project onos by opennetworkinglab.

the class DistributedMeterStore method freeMeterId.

protected void freeMeterId(MeterTableKey meterTableKey, MeterCellId meterCellId) {
    if (userDefinedIndexMode) {
        log.debug("Unable to free meter id when user defined index mode is enabled");
        return;
    }
    long index;
    if (meterCellId.type() == PIPELINE_INDEPENDENT) {
        PiMeterCellId piMeterCellId = (PiMeterCellId) meterCellId;
        index = piMeterCellId.index();
    } else if (meterCellId.type() == INDEX) {
        MeterId meterId = (MeterId) meterCellId;
        index = meterId.id();
    } else {
        log.warn("Unable to free meter id unsupported cell type {}", meterCellId.type());
        return;
    }
    // Avoid to free meter not allocated
    if (meterIdGenerators.get(meterTableKey) <= index) {
        return;
    }
    updateMeterIdAvailability(meterTableKey, meterCellId, true);
}
Also used : PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) PiMeterId(org.onosproject.net.pi.model.PiMeterId) MeterId(org.onosproject.net.meter.MeterId)

Example 9 with PiMeterCellId

use of org.onosproject.net.pi.runtime.PiMeterCellId 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());
    meterMirror.sync(deviceId, piMeterCellConfigs);
    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);
        for (PiMeterCellId cellId : inconsistentOrDefaultCells) {
            PiMeterCellHandle handle = PiMeterCellHandle.of(deviceId, cellId);
            appendEntryToWriteRequestOrSkip(request, handle, PiMeterCellConfig.reset(cellId));
        }
        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());
            }
            response.success().forEach(entity -> meterMirror.remove((PiMeterCellHandle) entity.handle()));
        });
    }
    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 10 with PiMeterCellId

use of org.onosproject.net.pi.runtime.PiMeterCellId in project up4 by omec-project.

the class Up4DeviceManager method meterToMeterRequestForDevice.

private MeterRequest meterToMeterRequestForDevice(Meter meter, DeviceId deviceId, boolean add) {
    assert meter.meterCellId().type().equals(MeterCellId.MeterCellType.PIPELINE_INDEPENDENT);
    PiMeterCellId piMeterCellId = (PiMeterCellId) meter.meterCellId();
    MeterScope meterScope = MeterScope.of(piMeterCellId.meterId().id());
    MeterRequest.Builder mRequestBuilder = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(meter.appId()).withUnit(meter.unit()).withScope(meterScope).withBands(meter.bands()).withIndex(piMeterCellId.index());
    if (add) {
        return mRequestBuilder.add();
    }
    return mRequestBuilder.remove();
}
Also used : PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterScope(org.onosproject.net.meter.MeterScope) MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest)

Aggregations

PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)11 MeterTableKey (org.onosproject.net.meter.MeterTableKey)4 PiMeterId (org.onosproject.net.pi.model.PiMeterId)4 MeterId (org.onosproject.net.meter.MeterId)2 MeterScope (org.onosproject.net.meter.MeterScope)2 PiMeterCellConfig (org.onosproject.net.pi.runtime.PiMeterCellConfig)2 PiMeterCellHandle (org.onosproject.net.pi.runtime.PiMeterCellHandle)2 WriteRequest (org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest)2 P4RuntimeOuterClass (p4.v1.P4RuntimeOuterClass)2 HashSet (java.util.HashSet)1 UpfMeter (org.onosproject.net.behaviour.upf.UpfMeter)1 Band (org.onosproject.net.meter.Band)1 DefaultBand (org.onosproject.net.meter.DefaultBand)1 DefaultMeter (org.onosproject.net.meter.DefaultMeter)1 DefaultMeterFeatures (org.onosproject.net.meter.DefaultMeterFeatures)1 DefaultMeterRequest (org.onosproject.net.meter.DefaultMeterRequest)1 Meter (org.onosproject.net.meter.Meter)1 MeterCellId (org.onosproject.net.meter.MeterCellId)1 MeterFeatures (org.onosproject.net.meter.MeterFeatures)1 MeterKey (org.onosproject.net.meter.MeterKey)1