Search in sources :

Example 6 with MeterKey

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;
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) MeterCellId(org.onosproject.net.meter.MeterCellId) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId)

Example 7 with MeterKey

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));
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey)

Example 8 with MeterKey

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));
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) DeviceId(org.onosproject.net.DeviceId)

Example 9 with MeterKey

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);
    }
}
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 10 with MeterKey

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;
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) DefaultMeter(org.onosproject.net.meter.DefaultMeter) MeterState(org.onosproject.net.meter.MeterState)

Aggregations

MeterKey (org.onosproject.net.meter.MeterKey)20 DefaultMeter (org.onosproject.net.meter.DefaultMeter)11 Test (org.junit.Test)7 Meter (org.onosproject.net.meter.Meter)7 CompletableFuture (java.util.concurrent.CompletableFuture)6 StorageException (org.onosproject.store.service.StorageException)6 MeterStoreResult (org.onosproject.net.meter.MeterStoreResult)5 PiMeterCellId (org.onosproject.net.pi.runtime.PiMeterCellId)5 MeterCellId (org.onosproject.net.meter.MeterCellId)4 DeviceId (org.onosproject.net.DeviceId)3 Collections2 (com.google.common.collect.Collections2)2 Maps (com.google.common.collect.Maps)2 Collection (java.util.Collection)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 ClusterService (org.onosproject.cluster.ClusterService)2 NodeId (org.onosproject.cluster.NodeId)2 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)2 VirtualNetworkMeterStore (org.onosproject.incubator.net.virtual.VirtualNetworkMeterStore)2