Toshio Koide

Implement fake requestResources() method.

...@@ -33,4 +33,9 @@ public class BandwidthResourceRequest implements ResourceRequest { ...@@ -33,4 +33,9 @@ public class BandwidthResourceRequest implements ResourceRequest {
33 public Bandwidth bandwidth() { 33 public Bandwidth bandwidth() {
34 return bandwidth; 34 return bandwidth;
35 } 35 }
36 +
37 + @Override
38 + public ResourceType type() {
39 + return ResourceType.BANDWIDTH;
40 + }
36 } 41 }
......
...@@ -34,6 +34,12 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { ...@@ -34,6 +34,12 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest {
34 this.resources = ImmutableSet.copyOf(resources); 34 this.resources = ImmutableSet.copyOf(resources);
35 } 35 }
36 36
37 +
38 + @Override
39 + public ResourceType type() {
40 + return null;
41 + }
42 +
37 @Override 43 @Override
38 public IntentId intendId() { 44 public IntentId intendId() {
39 return intentId; 45 return intentId;
......
...@@ -5,4 +5,9 @@ package org.onlab.onos.net.resource; ...@@ -5,4 +5,9 @@ package org.onlab.onos.net.resource;
5 */ 5 */
6 public class LambdaResourceRequest implements ResourceRequest { 6 public class LambdaResourceRequest implements ResourceRequest {
7 7
8 + @Override
9 + public ResourceType type() {
10 + return ResourceType.LAMBDA;
11 + }
12 +
8 } 13 }
......
...@@ -4,5 +4,11 @@ package org.onlab.onos.net.resource; ...@@ -4,5 +4,11 @@ package org.onlab.onos.net.resource;
4 * Abstraction of resource request. 4 * Abstraction of resource request.
5 */ 5 */
6 public interface ResourceRequest { 6 public interface ResourceRequest {
7 + /**
8 + * Returns the resource type.
9 + *
10 + * @return the resource type
11 + */
12 + ResourceType type();
7 13
8 } 14 }
......
1 +package org.onlab.onos.net.resource;
2 +
3 +import java.util.Collection;
4 +import java.util.Collections;
5 +import java.util.Map;
6 +import java.util.Set;
7 +
8 +import org.onlab.onos.net.Link;
9 +import org.onlab.onos.net.intent.IntentId;
10 +
11 +/**
12 + * Implementation of {@link LinkResourceAllocations}.
13 + */
14 +public class DefaultLinkResourceAllocations implements LinkResourceAllocations {
15 + private final LinkResourceRequest request;
16 + private final Map<Link, Set<ResourceAllocation>> allocations;
17 +
18 + /**
19 + * Creates a new link resource allocations.
20 + *
21 + * @param request requested resources
22 + * @param allocations allocated resources
23 + */
24 + protected DefaultLinkResourceAllocations(LinkResourceRequest request,
25 + Map<Link, Set<ResourceAllocation>> allocations) {
26 + this.request = request;
27 + this.allocations = allocations;
28 + }
29 +
30 + @Override
31 + public IntentId intendId() {
32 + return request.intendId();
33 + }
34 +
35 + @Override
36 + public Collection<Link> links() {
37 + return request.links();
38 + }
39 +
40 + @Override
41 + public Set<ResourceRequest> resources() {
42 + return request.resources();
43 + }
44 +
45 + @Override
46 + public ResourceType type() {
47 + return null;
48 + }
49 +
50 + @Override
51 + public Set<ResourceAllocation> getResourceAllocation(Link link) {
52 + Set<ResourceAllocation> result = allocations.get(link);
53 + if (result == null) {
54 + result = Collections.emptySet();
55 + }
56 + return result;
57 + }
58 +
59 +}
...@@ -2,6 +2,10 @@ package org.onlab.onos.net.resource; ...@@ -2,6 +2,10 @@ package org.onlab.onos.net.resource;
2 2
3 import static org.slf4j.LoggerFactory.getLogger; 3 import static org.slf4j.LoggerFactory.getLogger;
4 4
5 +import java.util.HashMap;
6 +import java.util.Map;
7 +import java.util.Set;
8 +
5 import org.apache.felix.scr.annotations.Activate; 9 import org.apache.felix.scr.annotations.Activate;
6 import org.apache.felix.scr.annotations.Component; 10 import org.apache.felix.scr.annotations.Component;
7 import org.apache.felix.scr.annotations.Deactivate; 11 import org.apache.felix.scr.annotations.Deactivate;
...@@ -10,6 +14,8 @@ import org.onlab.onos.net.Link; ...@@ -10,6 +14,8 @@ import org.onlab.onos.net.Link;
10 import org.onlab.onos.net.intent.IntentId; 14 import org.onlab.onos.net.intent.IntentId;
11 import org.slf4j.Logger; 15 import org.slf4j.Logger;
12 16
17 +import com.google.common.collect.Sets;
18 +
13 /** 19 /**
14 * Provides basic implementation of link resources allocation. 20 * Provides basic implementation of link resources allocation.
15 */ 21 */
...@@ -31,8 +37,30 @@ public class LinkResourceManager implements LinkResourceService { ...@@ -31,8 +37,30 @@ public class LinkResourceManager implements LinkResourceService {
31 37
32 @Override 38 @Override
33 public LinkResourceAllocations requestResources(LinkResourceRequest req) { 39 public LinkResourceAllocations requestResources(LinkResourceRequest req) {
34 - // TODO Auto-generated method stub 40 + // TODO implement it using a resource data store.
35 - return null; 41 +
42 + ResourceAllocation alloc = null;
43 + for (ResourceRequest r: req.resources()) {
44 + switch (r.type()) {
45 + case BANDWIDTH:
46 + log.info("requestResources() always returns requested bandwidth");
47 + BandwidthResourceRequest br = (BandwidthResourceRequest) r;
48 + alloc = new BandwidthResourceAllocation(br.bandwidth());
49 + break;
50 + case LAMBDA:
51 + log.info("requestResources() always returns lambda 7");
52 + alloc = new LambdaResourceAllocation(Lambda.valueOf(7));
53 + break;
54 + default:
55 + break;
56 + }
57 + }
58 +
59 + Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
60 + for (Link link: req.links()) {
61 + allocations.put(link, Sets.newHashSet(alloc));
62 + }
63 + return new DefaultLinkResourceAllocations(req, allocations);
36 } 64 }
37 65
38 @Override 66 @Override
......