Search in sources :

Example 1 with DefaultLabelResource

use of org.onosproject.incubator.net.resource.label.DefaultLabelResource 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 DefaultLabelResource

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

the class LabelReleaseCommand method doExecute.

@Override
protected void doExecute() {
    LabelResourceService lrs = get(LabelResourceService.class);
    Multimap<DeviceId, LabelResource> map = ArrayListMultimap.create();
    String[] labelIds = releaseLabelIds.split(",");
    DefaultLabelResource resource = null;
    for (int i = 0; i < labelIds.length; i++) {
        resource = new DefaultLabelResource(DeviceId.deviceId(deviceId), LabelResourceId.labelResourceId(Long.parseLong(labelIds[i])));
        map.put(DeviceId.deviceId(deviceId), resource);
    }
    lrs.releaseToDevicePool(map);
}
Also used : DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResource(org.onosproject.incubator.net.resource.label.LabelResource) LabelResourceService(org.onosproject.incubator.net.resource.label.LabelResourceService) DeviceId(org.onosproject.net.DeviceId) DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource)

Example 3 with DefaultLabelResource

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

the class DistributedLabelResourceStore method releaseToGlobalPool.

@Override
public boolean releaseToGlobalPool(Set<LabelResourceId> release) {
    Set<LabelResource> set = new HashSet<>();
    DefaultLabelResource resource = null;
    for (LabelResourceId labelResource : release) {
        resource = new DefaultLabelResource(DeviceId.deviceId(GLOBAL_RESOURCE_POOL_DEVICE_ID), labelResource);
        set.add(resource);
    }
    LabelResourceRequest request = new LabelResourceRequest(DeviceId.deviceId(GLOBAL_RESOURCE_POOL_DEVICE_ID), LabelResourceRequest.Type.RELEASE, 0, ImmutableSet.copyOf(set));
    return this.internalRelease(request);
}
Also used : DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResource(org.onosproject.incubator.net.resource.label.LabelResource) LabelResourceRequest(org.onosproject.incubator.net.resource.label.LabelResourceRequest) DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResourceId(org.onosproject.incubator.net.resource.label.LabelResourceId) HashSet(java.util.HashSet)

Example 4 with DefaultLabelResource

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

the class GlobalLabelApplyCommand method doExecute.

@Override
protected void doExecute() {
    LabelResourceService lrs = get(LabelResourceService.class);
    Collection<LabelResource> result = lrs.applyFromGlobalPool(Long.parseLong(applyNum));
    if (!result.isEmpty()) {
        for (Iterator<LabelResource> iterator = result.iterator(); iterator.hasNext(); ) {
            DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next();
            print(FMT, defaultLabelResource.deviceId().toString(), defaultLabelResource.labelResourceId().toString());
        }
    }
}
Also used : DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResource(org.onosproject.incubator.net.resource.label.LabelResource) LabelResourceService(org.onosproject.incubator.net.resource.label.LabelResourceService) DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource)

Example 5 with DefaultLabelResource

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

the class LabelApplyCommand method doExecute.

@Override
protected void doExecute() {
    LabelResourceService lrs = get(LabelResourceService.class);
    Collection<LabelResource> result = lrs.applyFromDevicePool(DeviceId.deviceId(deviceId), Long.parseLong(applyNum));
    if (!result.isEmpty()) {
        for (Iterator<LabelResource> iterator = result.iterator(); iterator.hasNext(); ) {
            DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next();
            print(FMT, defaultLabelResource.deviceId().toString(), defaultLabelResource.labelResourceId().toString());
        }
    }
}
Also used : DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResource(org.onosproject.incubator.net.resource.label.LabelResource) LabelResourceService(org.onosproject.incubator.net.resource.label.LabelResourceService) DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource)

Aggregations

DefaultLabelResource (org.onosproject.incubator.net.resource.label.DefaultLabelResource)5 LabelResource (org.onosproject.incubator.net.resource.label.LabelResource)5 LabelResourceService (org.onosproject.incubator.net.resource.label.LabelResourceService)3 HashSet (java.util.HashSet)2 DeviceId (org.onosproject.net.DeviceId)2 LabelResourceId (org.onosproject.incubator.net.resource.label.LabelResourceId)1 LabelResourcePool (org.onosproject.incubator.net.resource.label.LabelResourcePool)1 LabelResourceRequest (org.onosproject.incubator.net.resource.label.LabelResourceRequest)1