Toshio Koide

Implement fake requestResources() method.

......@@ -33,4 +33,9 @@ public class BandwidthResourceRequest implements ResourceRequest {
public Bandwidth bandwidth() {
return bandwidth;
}
@Override
public ResourceType type() {
return ResourceType.BANDWIDTH;
}
}
......
......@@ -34,6 +34,12 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest {
this.resources = ImmutableSet.copyOf(resources);
}
@Override
public ResourceType type() {
return null;
}
@Override
public IntentId intendId() {
return intentId;
......
......@@ -5,4 +5,9 @@ package org.onlab.onos.net.resource;
*/
public class LambdaResourceRequest implements ResourceRequest {
@Override
public ResourceType type() {
return ResourceType.LAMBDA;
}
}
......
......@@ -4,5 +4,11 @@ package org.onlab.onos.net.resource;
* Abstraction of resource request.
*/
public interface ResourceRequest {
/**
* Returns the resource type.
*
* @return the resource type
*/
ResourceType type();
}
......
package org.onlab.onos.net.resource;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.intent.IntentId;
/**
* Implementation of {@link LinkResourceAllocations}.
*/
public class DefaultLinkResourceAllocations implements LinkResourceAllocations {
private final LinkResourceRequest request;
private final Map<Link, Set<ResourceAllocation>> allocations;
/**
* Creates a new link resource allocations.
*
* @param request requested resources
* @param allocations allocated resources
*/
protected DefaultLinkResourceAllocations(LinkResourceRequest request,
Map<Link, Set<ResourceAllocation>> allocations) {
this.request = request;
this.allocations = allocations;
}
@Override
public IntentId intendId() {
return request.intendId();
}
@Override
public Collection<Link> links() {
return request.links();
}
@Override
public Set<ResourceRequest> resources() {
return request.resources();
}
@Override
public ResourceType type() {
return null;
}
@Override
public Set<ResourceAllocation> getResourceAllocation(Link link) {
Set<ResourceAllocation> result = allocations.get(link);
if (result == null) {
result = Collections.emptySet();
}
return result;
}
}
......@@ -2,6 +2,10 @@ package org.onlab.onos.net.resource;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -10,6 +14,8 @@ import org.onlab.onos.net.Link;
import org.onlab.onos.net.intent.IntentId;
import org.slf4j.Logger;
import com.google.common.collect.Sets;
/**
* Provides basic implementation of link resources allocation.
*/
......@@ -31,8 +37,30 @@ public class LinkResourceManager implements LinkResourceService {
@Override
public LinkResourceAllocations requestResources(LinkResourceRequest req) {
// TODO Auto-generated method stub
return null;
// TODO implement it using a resource data store.
ResourceAllocation alloc = null;
for (ResourceRequest r: req.resources()) {
switch (r.type()) {
case BANDWIDTH:
log.info("requestResources() always returns requested bandwidth");
BandwidthResourceRequest br = (BandwidthResourceRequest) r;
alloc = new BandwidthResourceAllocation(br.bandwidth());
break;
case LAMBDA:
log.info("requestResources() always returns lambda 7");
alloc = new LambdaResourceAllocation(Lambda.valueOf(7));
break;
default:
break;
}
}
Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
for (Link link: req.links()) {
allocations.put(link, Sets.newHashSet(alloc));
}
return new DefaultLinkResourceAllocations(req, allocations);
}
@Override
......