Showing
1 changed file
with
32 additions
and
7 deletions
| ... | @@ -15,7 +15,8 @@ | ... | @@ -15,7 +15,8 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onlab.onos.store.trivial.impl; | 16 | package org.onlab.onos.store.trivial.impl; |
| 17 | 17 | ||
| 18 | -import static com.google.common.base.Preconditions.*; | 18 | +import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | +import static com.google.common.base.Preconditions.checkState; | ||
| 19 | import static org.slf4j.LoggerFactory.getLogger; | 20 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | 21 | ||
| 21 | import java.util.Collections; | 22 | import java.util.Collections; |
| ... | @@ -65,6 +66,13 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -65,6 +66,13 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 65 | log.info("Stopped"); | 66 | log.info("Stopped"); |
| 66 | } | 67 | } |
| 67 | 68 | ||
| 69 | + /** | ||
| 70 | + * Returns free resources for a given link obtaining from topology | ||
| 71 | + * information. | ||
| 72 | + * | ||
| 73 | + * @param link the target link | ||
| 74 | + * @return free resources | ||
| 75 | + */ | ||
| 68 | private Set<ResourceAllocation> readOriginalFreeResources(Link link) { | 76 | private Set<ResourceAllocation> readOriginalFreeResources(Link link) { |
| 69 | // TODO read capacity and lambda resources from topology | 77 | // TODO read capacity and lambda resources from topology |
| 70 | Set<ResourceAllocation> allocations = new HashSet<>(); | 78 | Set<ResourceAllocation> allocations = new HashSet<>(); |
| ... | @@ -75,6 +83,15 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -75,6 +83,15 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 75 | return allocations; | 83 | return allocations; |
| 76 | } | 84 | } |
| 77 | 85 | ||
| 86 | + /** | ||
| 87 | + * Finds and returns {@link BandwidthResourceAllocation} object from a given | ||
| 88 | + * set. | ||
| 89 | + * | ||
| 90 | + * @param freeRes a set of ResourceAllocation object. | ||
| 91 | + * @return {@link BandwidthResourceAllocation} object if found, otherwise | ||
| 92 | + * {@link BandwidthResourceAllocation} object with 0 bandwidth | ||
| 93 | + * | ||
| 94 | + */ | ||
| 78 | private BandwidthResourceAllocation getBandwidth(Set<ResourceAllocation> freeRes) { | 95 | private BandwidthResourceAllocation getBandwidth(Set<ResourceAllocation> freeRes) { |
| 79 | for (ResourceAllocation res : freeRes) { | 96 | for (ResourceAllocation res : freeRes) { |
| 80 | if (res.type() == ResourceType.BANDWIDTH) { | 97 | if (res.type() == ResourceType.BANDWIDTH) { |
| ... | @@ -84,12 +101,16 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -84,12 +101,16 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 84 | return new BandwidthResourceAllocation(Bandwidth.valueOf(0)); | 101 | return new BandwidthResourceAllocation(Bandwidth.valueOf(0)); |
| 85 | } | 102 | } |
| 86 | 103 | ||
| 104 | + /** | ||
| 105 | + * Subtracts given resources from free resources for given link. | ||
| 106 | + * | ||
| 107 | + * @param link the target link | ||
| 108 | + * @param allocations the resources to be subtracted | ||
| 109 | + */ | ||
| 87 | private void subtractFreeResources(Link link, LinkResourceAllocations allocations) { | 110 | private void subtractFreeResources(Link link, LinkResourceAllocations allocations) { |
| 88 | // TODO Use lock or version for updating freeResources. | 111 | // TODO Use lock or version for updating freeResources. |
| 89 | checkNotNull(link); | 112 | checkNotNull(link); |
| 90 | - Set<ResourceAllocation> freeRes = freeResources.get(link); | 113 | + Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link)); |
| 91 | - checkNotNull(freeRes); | ||
| 92 | - freeRes = new HashSet<>(freeRes); | ||
| 93 | Set<ResourceAllocation> subRes = allocations.getResourceAllocation(link); | 114 | Set<ResourceAllocation> subRes = allocations.getResourceAllocation(link); |
| 94 | for (ResourceAllocation res : subRes) { | 115 | for (ResourceAllocation res : subRes) { |
| 95 | switch (res.type()) { | 116 | switch (res.type()) { |
| ... | @@ -114,11 +135,15 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -114,11 +135,15 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 114 | 135 | ||
| 115 | } | 136 | } |
| 116 | 137 | ||
| 138 | + /** | ||
| 139 | + * Adds given resources to free resources for given link. | ||
| 140 | + * | ||
| 141 | + * @param link the target link | ||
| 142 | + * @param allocations the resources to be added | ||
| 143 | + */ | ||
| 117 | private void addFreeResources(Link link, LinkResourceAllocations allocations) { | 144 | private void addFreeResources(Link link, LinkResourceAllocations allocations) { |
| 118 | // TODO Use lock or version for updating freeResources. | 145 | // TODO Use lock or version for updating freeResources. |
| 119 | - Set<ResourceAllocation> freeRes = freeResources.get(link); | 146 | + Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link)); |
| 120 | - checkNotNull(freeRes); | ||
| 121 | - freeRes = new HashSet<>(freeRes); | ||
| 122 | Set<ResourceAllocation> addRes = allocations.getResourceAllocation(link); | 147 | Set<ResourceAllocation> addRes = allocations.getResourceAllocation(link); |
| 123 | for (ResourceAllocation res : addRes) { | 148 | for (ResourceAllocation res : addRes) { |
| 124 | switch (res.type()) { | 149 | switch (res.type()) { | ... | ... |
-
Please register or login to post a comment