Search in sources :

Example 1 with MeterTableKey

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

the class DistributedMeterStoreTest method testFreeIdInUserMode.

/**
 * Test free of meter ids in user defined index mode.
 */
@Test
public void testFreeIdInUserMode() {
    initMeterStore(true);
    meterStore.freeMeterId(did1, mid1);
    MeterTableKey globalKey = MeterTableKey.key(did1, MeterScope.globalScope());
    assertNotNull(meterStore.availableMeterIds.get(globalKey));
    assertTrue(meterStore.availableMeterIds.get(globalKey).isEmpty());
}
Also used : MeterTableKey(org.onosproject.net.meter.MeterTableKey) Test(org.junit.Test)

Example 2 with MeterTableKey

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

the class DistributedMeterStore method freeMeterId.

protected void freeMeterId(DeviceId deviceId, MeterCellId meterCellId) {
    MeterTableKey meterTableKey;
    if (meterCellId.type() == PIPELINE_INDEPENDENT) {
        meterTableKey = MeterTableKey.key(deviceId, MeterScope.of(((PiMeterCellId) meterCellId).meterId().id()));
    } else if (meterCellId.type() == INDEX) {
        meterTableKey = MeterTableKey.key(deviceId, MeterScope.globalScope());
    } else {
        log.warn("Unable to free meter id unsupported cell type {}", meterCellId.type());
        return;
    }
    freeMeterId(meterTableKey, meterCellId);
}
Also used : MeterTableKey(org.onosproject.net.meter.MeterTableKey) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId)

Example 3 with MeterTableKey

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

the class DistributedMeterStore method allocateMeterId.

@Override
public MeterCellId allocateMeterId(DeviceId deviceId, MeterScope meterScope) {
    if (userDefinedIndexMode) {
        log.warn("Unable to allocate meter id when user defined index mode is enabled");
        return null;
    }
    MeterTableKey meterTableKey = MeterTableKey.key(deviceId, meterScope);
    MeterCellId meterCellId;
    long id;
    // First, search for reusable key
    meterCellId = firstReusableMeterId(meterTableKey);
    if (meterCellId != null) {
        return meterCellId;
    }
    // If there was no reusable meter id we have to generate a new value
    // using start and end index as lower and upper bound respectively.
    long startIndex = getStartIndex(meterTableKey);
    long endIndex = getEndIndex(meterTableKey);
    // If the device does not give us MeterFeatures fallback to queryMeters
    if (startIndex == -1L || endIndex == -1L) {
        // Only meaningful for OpenFlow today
        long maxMeters = queryMaxMeters(deviceId);
        if (maxMeters == 0L) {
            return null;
        } else {
            // OpenFlow meter index starts from 1, ends with max
            startIndex = 1L;
            endIndex = maxMeters;
        }
    }
    do {
        id = meterIdGenerators.getAndIncrement(meterTableKey);
    } while (id < startIndex);
    if (id > endIndex) {
        return null;
    }
    // return a MeterId, otherwise we create a PiMeterCellId
    if (meterScope.isGlobal()) {
        return MeterId.meterId(id);
    } else {
        return PiMeterCellId.ofIndirect(PiMeterId.of(meterScope.id()), id);
    }
}
Also used : MeterTableKey(org.onosproject.net.meter.MeterTableKey) MeterCellId(org.onosproject.net.meter.MeterCellId) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId)

Example 4 with MeterTableKey

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

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

Aggregations

MeterTableKey (org.onosproject.net.meter.MeterTableKey)11 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)4 StorageException (org.onosproject.store.service.StorageException)4 DefaultMeterFeatures (org.onosproject.net.meter.DefaultMeterFeatures)3 MeterFeatures (org.onosproject.net.meter.MeterFeatures)3 MeterKey (org.onosproject.net.meter.MeterKey)3 MeterStoreResult (org.onosproject.net.meter.MeterStoreResult)3 Test (org.junit.Test)2 MeterQuery (org.onosproject.net.behaviour.MeterQuery)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2 DefaultMeter (org.onosproject.net.meter.DefaultMeter)2 Meter (org.onosproject.net.meter.Meter)2 MeterCellId (org.onosproject.net.meter.MeterCellId)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Collections2 (com.google.common.collect.Collections2)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Collection (java.util.Collection)1