Search in sources :

Example 1 with LabelResourcePool

use of org.onosproject.incubator.net.resource.label.LabelResourcePool in project onos by opennetworkinglab.

the class DistributedLabelResourceStore method internalApply.

private Collection<LabelResource> internalApply(LabelResourceRequest request) {
    DeviceId deviceId = request.deviceId();
    long applyNum = request.applyNum();
    Versioned<LabelResourcePool> poolOld = resourcePool.get(deviceId);
    if (poolOld == null) {
        log.info("label resource pool not allocated for deviceId {}.", deviceId);
        return Collections.emptyList();
    }
    LabelResourcePool pool = poolOld.value();
    Collection<LabelResource> result = new HashSet<>();
    long freeNum = this.getFreeNumOfDevicePool(deviceId);
    if (applyNum > freeNum) {
        log.info("the free number of the label resource pool of deviceId {} is not enough.");
        return Collections.emptyList();
    }
    Set<LabelResource> releaseLabels = new HashSet<>(pool.releaseLabelId());
    long tmp = releaseLabels.size() > applyNum ? applyNum : releaseLabels.size();
    LabelResource resource = null;
    for (int i = 0; i < tmp; i++) {
        Iterator<LabelResource> it = releaseLabels.iterator();
        if (it.hasNext()) {
            resource = it.next();
            releaseLabels.remove(resource);
        }
        result.add(resource);
    }
    for (long j = pool.currentUsedMaxLabelId().labelId(); j < pool.currentUsedMaxLabelId().labelId() + applyNum - tmp; j++) {
        resource = new DefaultLabelResource(deviceId, LabelResourceId.labelResourceId(j));
        result.add(resource);
    }
    long beginLabel = pool.beginLabel().labelId();
    long endLabel = pool.endLabel().labelId();
    long totalNum = pool.totalNum();
    long current = pool.currentUsedMaxLabelId().labelId() + applyNum - tmp;
    long usedNum = pool.usedNum() + applyNum;
    ImmutableSet<LabelResource> freeLabel = ImmutableSet.copyOf(releaseLabels);
    LabelResourcePool newPool = new LabelResourcePool(deviceId.toString(), beginLabel, endLabel, totalNum, usedNum, current, freeLabel);
    resourcePool.put(deviceId, newPool);
    log.info("success to apply label resource");
    return result;
}
Also used : DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResource(org.onosproject.incubator.net.resource.label.LabelResource) DeviceId(org.onosproject.net.DeviceId) LabelResourcePool(org.onosproject.incubator.net.resource.label.LabelResourcePool) DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) HashSet(java.util.HashSet)

Example 2 with LabelResourcePool

use of org.onosproject.incubator.net.resource.label.LabelResourcePool in project onos by opennetworkinglab.

the class LabelResourceCommand method doExecute.

@Override
protected void doExecute() {
    LabelResourceService lrs = get(LabelResourceService.class);
    LabelResourcePool pool = lrs.getDeviceLabelResourcePool(DeviceId.deviceId(deviceId));
    if (pool != null) {
        print(FMT, pool.deviceId().toString(), pool.beginLabel(), pool.endLabel(), pool.totalNum(), pool.usedNum(), pool.currentUsedMaxLabelId(), pool.releaseLabelId().toString());
    } else {
        print(FMT, deviceId, null, null, null, null, null, null);
    }
}
Also used : LabelResourceService(org.onosproject.incubator.net.resource.label.LabelResourceService) LabelResourcePool(org.onosproject.incubator.net.resource.label.LabelResourcePool)

Example 3 with LabelResourcePool

use of org.onosproject.incubator.net.resource.label.LabelResourcePool in project onos by opennetworkinglab.

the class DistributedLabelResourceStore method internalDestroy.

private boolean internalDestroy(DeviceId deviceId) {
    Versioned<LabelResourcePool> poolOld = resourcePool.get(deviceId);
    if (poolOld != null) {
        resourcePool.remove(deviceId);
        LabelResourceEvent event = new LabelResourceEvent(Type.POOL_DESTROYED, poolOld.value());
        notifyDelegate(event);
    }
    log.info("success to destroy the label resource pool of device id {}", deviceId);
    return true;
}
Also used : LabelResourceEvent(org.onosproject.incubator.net.resource.label.LabelResourceEvent) LabelResourcePool(org.onosproject.incubator.net.resource.label.LabelResourcePool)

Example 4 with LabelResourcePool

use of org.onosproject.incubator.net.resource.label.LabelResourcePool in project onos by opennetworkinglab.

the class DistributedLabelResourceStore method internalCreate.

private boolean internalCreate(LabelResourcePool pool) {
    Versioned<LabelResourcePool> poolOld = resourcePool.get(pool.deviceId());
    if (poolOld == null) {
        resourcePool.put(pool.deviceId(), pool);
        LabelResourceEvent event = new LabelResourceEvent(Type.POOL_CREATED, pool);
        notifyDelegate(event);
        return true;
    }
    return false;
}
Also used : LabelResourceEvent(org.onosproject.incubator.net.resource.label.LabelResourceEvent) LabelResourcePool(org.onosproject.incubator.net.resource.label.LabelResourcePool)

Example 5 with LabelResourcePool

use of org.onosproject.incubator.net.resource.label.LabelResourcePool in project onos by opennetworkinglab.

the class DistributedLabelResourceStore method internalRelease.

private boolean internalRelease(LabelResourceRequest request) {
    DeviceId deviceId = request.deviceId();
    Collection<LabelResource> release = request.releaseCollection();
    Versioned<LabelResourcePool> poolOld = resourcePool.get(deviceId);
    if (poolOld == null) {
        log.info("the label resource pool of device id {} not allocated");
        return false;
    }
    LabelResourcePool pool = poolOld.value();
    if (pool == null) {
        log.info("the label resource pool of device id {} does not exist");
        return false;
    }
    Set<LabelResource> storeSet = new HashSet<>(pool.releaseLabelId());
    LabelResource labelResource = null;
    long realReleasedNum = 0;
    for (Iterator<LabelResource> it = release.iterator(); it.hasNext(); ) {
        labelResource = it.next();
        if (labelResource.labelResourceId().labelId() < pool.beginLabel().labelId() || labelResource.labelResourceId().labelId() > pool.endLabel().labelId()) {
            continue;
        }
        if (pool.currentUsedMaxLabelId().labelId() > labelResource.labelResourceId().labelId() || !storeSet.contains(labelResource)) {
            storeSet.add(labelResource);
            realReleasedNum++;
        }
    }
    long beginNum = pool.beginLabel().labelId();
    long endNum = pool.endLabel().labelId();
    long totalNum = pool.totalNum();
    long usedNum = pool.usedNum() - realReleasedNum;
    long current = pool.currentUsedMaxLabelId().labelId();
    ImmutableSet<LabelResource> s = ImmutableSet.copyOf(storeSet);
    LabelResourcePool newPool = new LabelResourcePool(deviceId.toString(), beginNum, endNum, totalNum, usedNum, current, s);
    resourcePool.put(deviceId, newPool);
    log.info("success to release label resource");
    return true;
}
Also used : DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResource(org.onosproject.incubator.net.resource.label.LabelResource) DeviceId(org.onosproject.net.DeviceId) LabelResourcePool(org.onosproject.incubator.net.resource.label.LabelResourcePool) HashSet(java.util.HashSet)

Aggregations

LabelResourcePool (org.onosproject.incubator.net.resource.label.LabelResourcePool)6 HashSet (java.util.HashSet)2 DefaultLabelResource (org.onosproject.incubator.net.resource.label.DefaultLabelResource)2 LabelResource (org.onosproject.incubator.net.resource.label.LabelResource)2 LabelResourceEvent (org.onosproject.incubator.net.resource.label.LabelResourceEvent)2 LabelResourceService (org.onosproject.incubator.net.resource.label.LabelResourceService)2 DeviceId (org.onosproject.net.DeviceId)2