Search in sources :

Example 1 with MeterFeatures

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

the class SimpleVirtualMeterStore method deleteMeterFeatures.

@Override
public MeterStoreResult deleteMeterFeatures(NetworkId networkId, DeviceId deviceId) {
    ConcurrentMap<MeterFeaturesKey, MeterFeatures> meterFeatures = getMeterFeaturesByNetwork(networkId);
    MeterStoreResult result = MeterStoreResult.success();
    MeterFeaturesKey key = MeterFeaturesKey.key(deviceId);
    try {
        meterFeatures.remove(key);
    } catch (StorageException e) {
        result = MeterStoreResult.fail(TIMEOUT);
    }
    return result;
}
Also used : MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) MeterFeaturesKey(org.onosproject.net.meter.MeterFeaturesKey) MeterFeatures(org.onosproject.net.meter.MeterFeatures) StorageException(org.onosproject.store.service.StorageException)

Example 2 with MeterFeatures

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

the class SimpleVirtualMeterStore method getMaxMeters.

@Override
public long getMaxMeters(NetworkId networkId, MeterFeaturesKey key) {
    ConcurrentMap<MeterFeaturesKey, MeterFeatures> meterFeatures = getMeterFeaturesByNetwork(networkId);
    MeterFeatures features = meterFeatures.get(key);
    return features == null ? 0L : features.maxMeter();
}
Also used : MeterFeaturesKey(org.onosproject.net.meter.MeterFeaturesKey) MeterFeatures(org.onosproject.net.meter.MeterFeatures)

Example 3 with MeterFeatures

use of org.onosproject.net.meter.MeterFeatures 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 4 with MeterFeatures

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

the class DistributedMeterStore method deleteMeterFeatures.

@Override
public MeterStoreResult deleteMeterFeatures(Collection<MeterFeatures> meterfeatures) {
    // Same logic of storeMeterFeatures
    MeterStoreResult result = MeterStoreResult.success();
    for (MeterFeatures mf : meterfeatures) {
        try {
            MeterTableKey key = MeterTableKey.key(mf.deviceId(), mf.scope());
            metersFeatures.remove(key);
        } catch (StorageException e) {
            log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
            result = MeterStoreResult.fail(TIMEOUT);
        }
    }
    return result;
}
Also used : MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) MeterTableKey(org.onosproject.net.meter.MeterTableKey) MeterFeatures(org.onosproject.net.meter.MeterFeatures) DefaultMeterFeatures(org.onosproject.net.meter.DefaultMeterFeatures) StorageException(org.onosproject.store.service.StorageException)

Example 5 with MeterFeatures

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

the class SimpleVirtualMeterStore method storeMeterFeatures.

@Override
public MeterStoreResult storeMeterFeatures(NetworkId networkId, MeterFeatures meterfeatures) {
    ConcurrentMap<MeterFeaturesKey, MeterFeatures> meterFeatures = getMeterFeaturesByNetwork(networkId);
    MeterStoreResult result = MeterStoreResult.success();
    MeterFeaturesKey key = MeterFeaturesKey.key(meterfeatures.deviceId());
    try {
        meterFeatures.putIfAbsent(key, meterfeatures);
    } catch (StorageException e) {
        result = MeterStoreResult.fail(TIMEOUT);
    }
    return result;
}
Also used : MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) MeterFeaturesKey(org.onosproject.net.meter.MeterFeaturesKey) MeterFeatures(org.onosproject.net.meter.MeterFeatures) StorageException(org.onosproject.store.service.StorageException)

Aggregations

MeterFeatures (org.onosproject.net.meter.MeterFeatures)5 MeterFeaturesKey (org.onosproject.net.meter.MeterFeaturesKey)3 MeterStoreResult (org.onosproject.net.meter.MeterStoreResult)3 StorageException (org.onosproject.store.service.StorageException)3 DefaultMeterFeatures (org.onosproject.net.meter.DefaultMeterFeatures)2 MeterTableKey (org.onosproject.net.meter.MeterTableKey)2 MeterId (org.onosproject.net.meter.MeterId)1 PiMeterId (org.onosproject.net.pi.model.PiMeterId)1 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)1