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