use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class DistributedMeterStore method firstReusableMeterId.
// Implements reuse strategy of the meter cell ids
private MeterCellId firstReusableMeterId(MeterTableKey meterTableKey) {
DistributedSet<MeterKey> keySet = availableMeterIds.get(meterTableKey);
if (keySet == null) {
log.warn("Reusable Key set for device: {} scope: {} not found", meterTableKey.deviceId(), meterTableKey.scope());
return null;
}
Set<MeterCellId> localAvailableMeterIds = keySet.stream().filter(meterKey -> meterKey.deviceId().equals(meterTableKey.deviceId())).map(MeterKey::meterCellId).collect(Collectors.toSet());
MeterCellId meterId = getNextAvailableId(localAvailableMeterIds);
while (meterId != null) {
if (updateMeterIdAvailability(meterTableKey, meterId, false)) {
return meterId;
}
localAvailableMeterIds.remove(meterId);
meterId = getNextAvailableId(localAvailableMeterIds);
}
// there are no available ids that can be reused
return null;
}
use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class DistributedMeterStore method failedMeter.
@Override
public void failedMeter(MeterOperation op, MeterFailReason reason) {
// Meter ops failed (got notification from the sb)
MeterKey key = MeterKey.key(op.meter().deviceId(), op.meter().meterCellId());
meters.computeIfPresent(key, (k, v) -> new MeterData(v.meter(), reason));
}
use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class DistributedMeterStore method updateMeterIdAvailability.
private boolean updateMeterIdAvailability(MeterTableKey meterTableKey, MeterCellId id, boolean available) {
DistributedSet<MeterKey> keySet = availableMeterIds.get(meterTableKey);
if (keySet == null) {
log.warn("Reusable Key set for device: {} scope: {} not found", meterTableKey.deviceId(), meterTableKey.scope());
return false;
}
// According to available, make available or unavailable a meter key
DeviceId deviceId = meterTableKey.deviceId();
return available ? keySet.add(MeterKey.key(deviceId, id)) : keySet.remove(MeterKey.key(deviceId, id));
}
use of org.onosproject.net.meter.MeterKey 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);
}
}
use of org.onosproject.net.meter.MeterKey in project onos by opennetworkinglab.
the class DistributedMeterStore method updateMeterState.
@Override
public Meter updateMeterState(Meter meter) {
// Update meter if present (stats workflow)
MeterKey key = MeterKey.key(meter.deviceId(), meter.meterCellId());
Versioned<MeterData> value = meters.computeIfPresent(key, (k, v) -> {
DefaultMeter m = (DefaultMeter) v.meter();
MeterState meterState = m.state();
if (meterState == MeterState.PENDING_ADD) {
m.setState(meter.state());
}
m.setProcessedPackets(meter.packetsSeen());
m.setProcessedBytes(meter.bytesSeen());
m.setLife(meter.life());
// TODO: Prune if drops to zero.
m.setReferenceCount(meter.referenceCount());
return new MeterData(m, null);
});
return value != null ? value.value().meter() : null;
}
Aggregations