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