Committed by
Gerrit Code Review
Initial sketch of LabelResource APIs
LabelResource subsystem will be used to manage label resources such as MPLS labels, ... (Part of ONOS-1223) :) Change-Id: Ib11eac84d81d7d86eaaf0222cf0bd7d3c64d2e51
Showing
14 changed files
with
819 additions
and
0 deletions
| 1 | +package org.onosproject.net.resource; | ||
| 2 | + | ||
| 3 | +import java.util.Objects; | ||
| 4 | + | ||
| 5 | +import org.onosproject.net.Annotations; | ||
| 6 | +import org.onosproject.net.DeviceId; | ||
| 7 | +import org.onosproject.net.provider.ProviderId; | ||
| 8 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * the implementation of a label resource of a device. | ||
| 12 | + */ | ||
| 13 | +public final class DefaultLabelResource implements LabelResource { | ||
| 14 | + | ||
| 15 | + private DeviceId deviceId; | ||
| 16 | + | ||
| 17 | + private LabelResourceId labelResourceId; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * Initialize a label resource object. | ||
| 21 | + * @param deviceId device identifier | ||
| 22 | + * @param labelResourceId label resource id | ||
| 23 | + */ | ||
| 24 | + public DefaultLabelResource(String deviceId, long labelResourceId) { | ||
| 25 | + this.deviceId = DeviceId.deviceId(deviceId); | ||
| 26 | + this.labelResourceId = LabelResourceId.labelResourceId(labelResourceId); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * Initialize a label resource object. | ||
| 31 | + * @param deviceId device identifier | ||
| 32 | + * @param labelResourceId label resource id | ||
| 33 | + */ | ||
| 34 | + public DefaultLabelResource(DeviceId deviceId, | ||
| 35 | + LabelResourceId labelResourceId) { | ||
| 36 | + this.deviceId = deviceId; | ||
| 37 | + this.labelResourceId = labelResourceId; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public DeviceId deviceId() { | ||
| 42 | + return deviceId; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @Override | ||
| 46 | + public LabelResourceId labelResourceId() { | ||
| 47 | + return labelResourceId; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + @Override | ||
| 51 | + public Annotations annotations() { | ||
| 52 | + return null; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + public ProviderId providerId() { | ||
| 57 | + return null; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @Override | ||
| 61 | + public int hashCode() { | ||
| 62 | + return Objects.hash(deviceId, labelResourceId); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public boolean equals(Object obj) { | ||
| 67 | + if (obj instanceof DefaultLabelResource) { | ||
| 68 | + DefaultLabelResource that = (DefaultLabelResource) obj; | ||
| 69 | + return Objects.equals(this.deviceId, that.deviceId) | ||
| 70 | + && Objects.equals(this.labelResourceId, | ||
| 71 | + that.labelResourceId); | ||
| 72 | + } | ||
| 73 | + return false; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public String toString() { | ||
| 78 | + return toStringHelper(this).add("deviceId", deviceId) | ||
| 79 | + .add("labelResourceId", labelResourceId).toString(); | ||
| 80 | + } | ||
| 81 | +} |
| 1 | +package org.onosproject.net.resource; | ||
| 2 | + | ||
| 3 | +import org.onosproject.net.Annotated; | ||
| 4 | +import org.onosproject.net.DeviceId; | ||
| 5 | +import org.onosproject.net.NetworkResource; | ||
| 6 | +import org.onosproject.net.Provided; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Representation of label resource. | ||
| 10 | + */ | ||
| 11 | +public interface LabelResource extends Annotated, Provided, NetworkResource { | ||
| 12 | + /** | ||
| 13 | + * Returns device id. | ||
| 14 | + * @return DeviceId | ||
| 15 | + */ | ||
| 16 | + public DeviceId deviceId(); | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * Returns labelResource Id. | ||
| 20 | + * @return LabelResourceId | ||
| 21 | + */ | ||
| 22 | + public LabelResourceId labelResourceId(); | ||
| 23 | +} |
| 1 | +package org.onosproject.net.resource; | ||
| 2 | + | ||
| 3 | +import org.onosproject.net.DeviceId; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * Service for managing label resource. | ||
| 7 | + */ | ||
| 8 | +public interface LabelResourceAdminService { | ||
| 9 | + /** | ||
| 10 | + * Creates the only label resource of some device id from begin label to end | ||
| 11 | + * label. | ||
| 12 | + * | ||
| 13 | + * @param deviceId device identifier | ||
| 14 | + * @param beginLabel represents for the first label id in the range of label | ||
| 15 | + * pool | ||
| 16 | + * @param endLabel represents for the last label id in the range of label | ||
| 17 | + * pool | ||
| 18 | + * @return success or fail | ||
| 19 | + */ | ||
| 20 | + boolean createDevicePool(DeviceId deviceId, LabelResourceId beginLabel, | ||
| 21 | + LabelResourceId endLabel); | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * Creates the only global label resource pool. | ||
| 25 | + * | ||
| 26 | + * @param beginLabel represents for the first label id in the range of label | ||
| 27 | + * pool | ||
| 28 | + * @param endLabel represents for the last label id in the range of label | ||
| 29 | + * pool | ||
| 30 | + * @return success or fail | ||
| 31 | + */ | ||
| 32 | + boolean createGlobalPool(LabelResourceId beginLabel, | ||
| 33 | + LabelResourceId endLabel); | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * Destroys a label resource pool of a specific device id. | ||
| 37 | + * | ||
| 38 | + * @param deviceId device identifier | ||
| 39 | + * @return success or fail | ||
| 40 | + */ | ||
| 41 | + boolean destroyDevicePool(DeviceId deviceId); | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * Destroys the global label resource pool. | ||
| 45 | + * | ||
| 46 | + * @return success or fail | ||
| 47 | + */ | ||
| 48 | + boolean destroyGlobalPool(); | ||
| 49 | +} |
| 1 | +package org.onosproject.net.resource; | ||
| 2 | + | ||
| 3 | +import org.onosproject.event.AbstractEvent; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * Describes label resource event. | ||
| 7 | + */ | ||
| 8 | +public final class LabelResourceEvent | ||
| 9 | + extends AbstractEvent<LabelResourceEvent.Type, LabelResourcePool> { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * Type of label resource event. | ||
| 13 | + */ | ||
| 14 | + public enum Type { | ||
| 15 | + /** | ||
| 16 | + * Signifies that a new pool has been administratively created. | ||
| 17 | + */ | ||
| 18 | + POOL_CREATED, | ||
| 19 | + /** | ||
| 20 | + * Signifies that a new pool has been administratively destroyed. | ||
| 21 | + */ | ||
| 22 | + POOL_DESTROYED, | ||
| 23 | + /** | ||
| 24 | + * Signifies that a new pool has been administratively changed. | ||
| 25 | + */ | ||
| 26 | + POOL_CAPACITY_CHANGED | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * Creates an event of a given type and the given LabelResourcePool. | ||
| 31 | + * | ||
| 32 | + * @param type event type | ||
| 33 | + * @param subject pool | ||
| 34 | + */ | ||
| 35 | + public LabelResourceEvent(Type type, LabelResourcePool subject) { | ||
| 36 | + super(type, subject); | ||
| 37 | + } | ||
| 38 | +} |
| 1 | +package org.onosproject.net.resource; | ||
| 2 | + | ||
| 3 | +import java.util.Objects; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * Representation of a label. | ||
| 7 | + */ | ||
| 8 | +public final class LabelResourceId implements ResourceId { | ||
| 9 | + | ||
| 10 | + private long labelId; | ||
| 11 | + | ||
| 12 | + public static LabelResourceId labelResourceId(long labelResourceId) { | ||
| 13 | + return new LabelResourceId(labelResourceId); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + // Public construction is prohibited | ||
| 17 | + private LabelResourceId(long labelId) { | ||
| 18 | + this.labelId = labelId; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public long labelId() { | ||
| 22 | + return labelId; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public int hashCode() { | ||
| 27 | + return Objects.hashCode(labelId); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public boolean equals(Object obj) { | ||
| 32 | + if (obj instanceof LabelResourceId) { | ||
| 33 | + LabelResourceId that = (LabelResourceId) obj; | ||
| 34 | + return Objects.equals(this.labelId, that.labelId); | ||
| 35 | + } | ||
| 36 | + return false; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public String toString() { | ||
| 41 | + return String.valueOf(this.labelId); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | +} |
| 1 | +package org.onosproject.net.resource; | ||
| 2 | + | ||
| 3 | +import static com.google.common.base.Preconditions.checkArgument; | ||
| 4 | + | ||
| 5 | +import java.util.Collections; | ||
| 6 | +import java.util.Objects; | ||
| 7 | +import java.util.Set; | ||
| 8 | + | ||
| 9 | +import org.onosproject.net.DeviceId; | ||
| 10 | + | ||
| 11 | +import com.google.common.base.MoreObjects; | ||
| 12 | +import com.google.common.collect.ImmutableSet; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * Abstraction of the capacity of device label resource or global label | ||
| 16 | + * resource. it's contiguous range of label resource.when a application apply | ||
| 17 | + * some labels of some device,first catch from Set that store | ||
| 18 | + * available labels,if the size of the Set less than the apply number,then get | ||
| 19 | + * labels by calculating with three attributes, beginLabel,endLabel and | ||
| 20 | + * currentUsedMaxLabelId | ||
| 21 | + */ | ||
| 22 | +public class LabelResourcePool { | ||
| 23 | + | ||
| 24 | + private final DeviceId deviceId; | ||
| 25 | + private final LabelResourceId beginLabel; | ||
| 26 | + private final LabelResourceId endLabel; | ||
| 27 | + private final long totalNum; // capacity of label resource pool | ||
| 28 | + private final long usedNum; // have used label number | ||
| 29 | + private final LabelResourceId currentUsedMaxLabelId; // the maximal label | ||
| 30 | + // number id | ||
| 31 | + private ImmutableSet<LabelResource> releaseLabelId; // Set of released label | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * Creates a pool by device id,begin label id,end label id. | ||
| 35 | + * | ||
| 36 | + * @param deviceId device identifier | ||
| 37 | + * @param beginLabel represents for the first label id in the range of label | ||
| 38 | + * resource pool | ||
| 39 | + * @param endLabel represents for the last label id in the range of label | ||
| 40 | + * resource pool | ||
| 41 | + */ | ||
| 42 | + public LabelResourcePool(String deviceId, long beginLabel, long endLabel) { | ||
| 43 | + this(deviceId, beginLabel, endLabel, endLabel - beginLabel + 1, 0L, | ||
| 44 | + beginLabel, ImmutableSet.copyOf(Collections.emptySet())); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * Creates a pool by device id,begin label id,end label id. | ||
| 49 | + * used to update a pool in the store. | ||
| 50 | + * @param deviceId device identifier | ||
| 51 | + * @param beginLabel represents for the first label id in the range of label | ||
| 52 | + * resource pool | ||
| 53 | + * @param endLabel represents for the last label id in the range of label | ||
| 54 | + * resource pool | ||
| 55 | + * @param totalNum capacity of label resource pool | ||
| 56 | + * @param usedNum have used label number | ||
| 57 | + * @param currentUsedMaxLabelId the maximal label number id | ||
| 58 | + * @param releaseLabelId Set of released label | ||
| 59 | + */ | ||
| 60 | + public LabelResourcePool(String deviceId, long beginLabel, long endLabel, | ||
| 61 | + long totalNum, long usedNum, | ||
| 62 | + long currentUsedMaxLabelId, | ||
| 63 | + ImmutableSet<LabelResource> releaseLabelId) { | ||
| 64 | + checkArgument(endLabel >= beginLabel, | ||
| 65 | + "endLabel %s must be greater than or equal to beginLabel %s", | ||
| 66 | + endLabel, beginLabel); | ||
| 67 | + this.deviceId = DeviceId.deviceId(deviceId); | ||
| 68 | + this.beginLabel = LabelResourceId.labelResourceId(beginLabel); | ||
| 69 | + this.endLabel = LabelResourceId.labelResourceId(endLabel); | ||
| 70 | + this.totalNum = totalNum; | ||
| 71 | + this.usedNum = usedNum; | ||
| 72 | + this.currentUsedMaxLabelId = LabelResourceId | ||
| 73 | + .labelResourceId(currentUsedMaxLabelId); | ||
| 74 | + this.releaseLabelId = releaseLabelId; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * Returns a device id. | ||
| 79 | + * | ||
| 80 | + * @return DeviceId | ||
| 81 | + */ | ||
| 82 | + public DeviceId deviceId() { | ||
| 83 | + return deviceId; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Returns a begin Label id. | ||
| 88 | + * | ||
| 89 | + * @return begin Label id | ||
| 90 | + */ | ||
| 91 | + public LabelResourceId beginLabel() { | ||
| 92 | + return beginLabel; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * Returns a end Label id. | ||
| 97 | + * | ||
| 98 | + * @return end Label id | ||
| 99 | + */ | ||
| 100 | + public LabelResourceId endLabel() { | ||
| 101 | + return endLabel; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * Returns a begin Label id. | ||
| 106 | + * | ||
| 107 | + * @return current Used Maximal Label Id | ||
| 108 | + */ | ||
| 109 | + public LabelResourceId currentUsedMaxLabelId() { | ||
| 110 | + return currentUsedMaxLabelId; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * Returns total number. | ||
| 115 | + * | ||
| 116 | + * @return the total label number | ||
| 117 | + */ | ||
| 118 | + public long totalNum() { | ||
| 119 | + return totalNum; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + /** | ||
| 123 | + * Returns used number. | ||
| 124 | + * | ||
| 125 | + * @return the used label number | ||
| 126 | + */ | ||
| 127 | + public long usedNum() { | ||
| 128 | + return usedNum; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * Returns the Set of released label before. | ||
| 133 | + * | ||
| 134 | + * @return the Set of LabelResource | ||
| 135 | + */ | ||
| 136 | + public Set<LabelResource> releaseLabelId() { | ||
| 137 | + return releaseLabelId; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + @Override | ||
| 141 | + public int hashCode() { | ||
| 142 | + return Objects.hash(this.deviceId, this.beginLabel, this.endLabel, | ||
| 143 | + this.totalNum, this.usedNum, | ||
| 144 | + this.currentUsedMaxLabelId, this.releaseLabelId); | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + @Override | ||
| 148 | + public boolean equals(Object obj) { | ||
| 149 | + if (obj instanceof LabelResourcePool) { | ||
| 150 | + LabelResourcePool that = (LabelResourcePool) obj; | ||
| 151 | + return Objects.equals(this.deviceId, that.deviceId) | ||
| 152 | + && Objects.equals(this.beginLabel, that.beginLabel) | ||
| 153 | + && Objects.equals(this.endLabel, that.endLabel) | ||
| 154 | + && Objects.equals(this.totalNum, that.totalNum) | ||
| 155 | + && Objects.equals(this.usedNum, that.usedNum) | ||
| 156 | + && Objects.equals(this.currentUsedMaxLabelId, | ||
| 157 | + that.currentUsedMaxLabelId) | ||
| 158 | + && Objects.equals(this.releaseLabelId, that.releaseLabelId); | ||
| 159 | + } | ||
| 160 | + return false; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + @Override | ||
| 164 | + public String toString() { | ||
| 165 | + // TODO Auto-generated method stub | ||
| 166 | + return MoreObjects.toStringHelper(this).add("deviceId", this.deviceId) | ||
| 167 | + .add("beginLabel", this.beginLabel) | ||
| 168 | + .add("endLabel", this.endLabel).add("totalNum", this.totalNum) | ||
| 169 | + .add("usedNum", this.usedNum) | ||
| 170 | + .add("currentUsedMaxLabelId", this.currentUsedMaxLabelId) | ||
| 171 | + .add("releaseLabelId", this.releaseLabelId).toString(); | ||
| 172 | + } | ||
| 173 | +} |
| 1 | +package org.onosproject.net.resource; | ||
| 2 | + | ||
| 3 | +import org.onosproject.net.provider.ProviderRegistry; | ||
| 4 | +/** | ||
| 5 | + * Abstraction of an label resource provider registry. | ||
| 6 | + */ | ||
| 7 | +public interface LabelResourceProviderRegistry | ||
| 8 | + extends ProviderRegistry<LabelResourceProvider, LabelResourceProviderService> { | ||
| 9 | + | ||
| 10 | +} |
| 1 | +package org.onosproject.net.resource; | ||
| 2 | + | ||
| 3 | +import org.onosproject.net.DeviceId; | ||
| 4 | +import org.onosproject.net.provider.ProviderService; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * Means for injecting label information into the core. | ||
| 8 | + */ | ||
| 9 | +public interface LabelResourceProviderService extends ProviderService<LabelResourceProvider> { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * Signals that a device label resource pool has been detected. | ||
| 13 | + * @param deviceId device identifier | ||
| 14 | + * @param beginLabel the begin label number of resource | ||
| 15 | + * @param endLabel the end label number of resource | ||
| 16 | + */ | ||
| 17 | + void deviceLabelResourcePoolDetected(DeviceId deviceId, | ||
| 18 | + LabelResourceId beginLabel, | ||
| 19 | + LabelResourceId endLabel); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * Signals that an label resource pool has been destroyed. | ||
| 23 | + * @param deviceId device identifier | ||
| 24 | + */ | ||
| 25 | + void deviceLabelResourcePoolDestroyed(DeviceId deviceId); | ||
| 26 | +} |
| 1 | +package org.onosproject.net.resource; | ||
| 2 | + | ||
| 3 | +import java.util.Collection; | ||
| 4 | +import java.util.Objects; | ||
| 5 | + | ||
| 6 | +import org.onosproject.net.DeviceId; | ||
| 7 | + | ||
| 8 | +import com.google.common.base.MoreObjects; | ||
| 9 | +import com.google.common.collect.ImmutableSet; | ||
| 10 | +/** | ||
| 11 | + * Represents for a label request. | ||
| 12 | + */ | ||
| 13 | +public class LabelResourceRequest { | ||
| 14 | + | ||
| 15 | + private final DeviceId deviceId; | ||
| 16 | + private final Type type; | ||
| 17 | + private final long applyNum; | ||
| 18 | + private ImmutableSet<LabelResource> releaseCollection; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * Creates LabelResourceRequest object. | ||
| 22 | + * @param deviceId device identifier | ||
| 23 | + * @param type request type | ||
| 24 | + * @param applyNum apply the number of labels | ||
| 25 | + * @param releaseCollection Set of released label | ||
| 26 | + */ | ||
| 27 | + public LabelResourceRequest(DeviceId deviceId, | ||
| 28 | + Type type, | ||
| 29 | + long applyNum, | ||
| 30 | + ImmutableSet<LabelResource> releaseCollection) { | ||
| 31 | + this.deviceId = deviceId; | ||
| 32 | + this.type = type; | ||
| 33 | + this.applyNum = applyNum; | ||
| 34 | + this.releaseCollection = releaseCollection; | ||
| 35 | + } | ||
| 36 | + /** | ||
| 37 | + * Returns a device id. | ||
| 38 | + * @return DeviceId | ||
| 39 | + */ | ||
| 40 | + public DeviceId deviceId() { | ||
| 41 | + return deviceId; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Returns request type. | ||
| 46 | + * @return Type | ||
| 47 | + */ | ||
| 48 | + public Type type() { | ||
| 49 | + return type; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * Returns apply label number. | ||
| 54 | + * @return label number | ||
| 55 | + */ | ||
| 56 | + public long applyNum() { | ||
| 57 | + return applyNum; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * Returns the collection of release labels. | ||
| 62 | + * @return Collection of DefaultLabelResource | ||
| 63 | + */ | ||
| 64 | + public Collection<LabelResource> releaseCollection() { | ||
| 65 | + return releaseCollection; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * Request type. | ||
| 70 | + */ | ||
| 71 | + public enum Type { | ||
| 72 | + APPLY, //apple label request | ||
| 73 | + RELEASE //release label request | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public int hashCode() { | ||
| 78 | + return Objects.hash(this.deviceId, this.applyNum, this.type, | ||
| 79 | + this.releaseCollection); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @Override | ||
| 83 | + public boolean equals(Object obj) { | ||
| 84 | + if (obj instanceof LabelResourceRequest) { | ||
| 85 | + LabelResourceRequest that = (LabelResourceRequest) obj; | ||
| 86 | + return Objects.equals(this.deviceId, that.deviceId) | ||
| 87 | + && Objects.equals(this.applyNum, that.applyNum) | ||
| 88 | + && Objects.equals(this.type, that.type) | ||
| 89 | + && Objects.equals(this.releaseCollection, | ||
| 90 | + that.releaseCollection); | ||
| 91 | + } | ||
| 92 | + return false; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public String toString() { | ||
| 97 | + return MoreObjects.toStringHelper(this).add("deviceId", this.deviceId) | ||
| 98 | + .add("applyNum", this.applyNum).add("type", this.type) | ||
| 99 | + .add("releaseCollection", this.releaseCollection).toString(); | ||
| 100 | + } | ||
| 101 | +} |
| 1 | +package org.onosproject.net.resource; | ||
| 2 | + | ||
| 3 | +import java.util.Collection; | ||
| 4 | +import java.util.Set; | ||
| 5 | + | ||
| 6 | +import org.onosproject.net.DeviceId; | ||
| 7 | + | ||
| 8 | +import com.google.common.collect.Multimap; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * Service for providing label resource allocation. | ||
| 12 | + */ | ||
| 13 | +public interface LabelResourceService { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * Returns labels from resource pool by a specific device id. | ||
| 17 | + * | ||
| 18 | + * @param deviceId device identifier | ||
| 19 | + * @param applyNum the applying number | ||
| 20 | + * @return collection of applying labels | ||
| 21 | + */ | ||
| 22 | + Collection<LabelResource> applyFromDevicePool(DeviceId deviceId, | ||
| 23 | + long applyNum); | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * Returns labels from the global label resource pool. | ||
| 27 | + * | ||
| 28 | + * @param applyNum the applying number | ||
| 29 | + * @return collection of applying labels | ||
| 30 | + */ | ||
| 31 | + Collection<LabelResource> applyFromGlobalPool(long applyNum); | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * Releases unused labels to device pools . | ||
| 35 | + * | ||
| 36 | + * @param release the collection of releasing labels | ||
| 37 | + * @return success or fail | ||
| 38 | + */ | ||
| 39 | + boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release); | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * Releases unused labels to the global resource pool. | ||
| 43 | + * | ||
| 44 | + * @param release release the collection of releasing labels | ||
| 45 | + * @return success or fail | ||
| 46 | + */ | ||
| 47 | + boolean releaseToGlobalPool(Set<LabelResourceId> release); | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Judges if the pool of a specific device id is full. | ||
| 51 | + * | ||
| 52 | + * @param deviceId device identifier | ||
| 53 | + * @return yes or no | ||
| 54 | + */ | ||
| 55 | + boolean isDevicePoolFull(DeviceId deviceId); | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * Judges if the global resource pool is full. | ||
| 59 | + * | ||
| 60 | + * @return yes or no | ||
| 61 | + */ | ||
| 62 | + boolean isGlobalPoolFull(); | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * Returns the unused label number of a label resource pool by a specific device | ||
| 66 | + * id. | ||
| 67 | + * | ||
| 68 | + * @param deviceId device identifier | ||
| 69 | + * @return number of unused labels | ||
| 70 | + */ | ||
| 71 | + long getFreeNumOfDevicePool(DeviceId deviceId); | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * Returns the unused label number of a global label resource pool. | ||
| 75 | + * | ||
| 76 | + * @return number of unused labels | ||
| 77 | + */ | ||
| 78 | + long getFreeNumOfGlobalPool(); | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * Returns the label resource pool of a label resource by a specific device | ||
| 82 | + * id. | ||
| 83 | + * | ||
| 84 | + * @param deviceId device identifier | ||
| 85 | + * @return the device label resource pool | ||
| 86 | + */ | ||
| 87 | + LabelResourcePool getDeviceLabelResourcePool(DeviceId deviceId); | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * Returns the global label resource pool. | ||
| 91 | + * | ||
| 92 | + * @return the global label resource pool | ||
| 93 | + */ | ||
| 94 | + LabelResourcePool getGlobalLabelResourcePool(); | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * Adds the specified label resource listener. | ||
| 98 | + * | ||
| 99 | + * @param listener label resource listener | ||
| 100 | + */ | ||
| 101 | + void addListener(LabelResourceListener listener); | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * Removes the specified label resource listener. | ||
| 105 | + * | ||
| 106 | + * @param listener label resource listener | ||
| 107 | + */ | ||
| 108 | + void removeListener(LabelResourceListener listener); | ||
| 109 | +} |
| 1 | +package org.onosproject.net.resource; | ||
| 2 | + | ||
| 3 | +import java.util.Collection; | ||
| 4 | +import java.util.Set; | ||
| 5 | + | ||
| 6 | +import org.onosproject.net.DeviceId; | ||
| 7 | +import org.onosproject.store.Store; | ||
| 8 | + | ||
| 9 | +import com.google.common.collect.Multimap; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * Manages inventory of label; not intended for direct use. | ||
| 13 | + * | ||
| 14 | + */ | ||
| 15 | +public interface LabelResourceStore | ||
| 16 | + extends Store<LabelResourceEvent, LabelResourceDelegate> { | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * Creates a label resource of some device id from begin label to end label. | ||
| 20 | + * | ||
| 21 | + * @param deviceId device identifier | ||
| 22 | + * @param beginLabel represents for the first label id in the range of label | ||
| 23 | + * pool | ||
| 24 | + * @param endLabel represents for the last label id in the range of label | ||
| 25 | + * pool | ||
| 26 | + * @return success or fail | ||
| 27 | + */ | ||
| 28 | + boolean createDevicePool(DeviceId deviceId, LabelResourceId beginLabel, | ||
| 29 | + LabelResourceId endLabel); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * Creates the global label resource pool. | ||
| 33 | + * | ||
| 34 | + * @param beginLabel represents for the first label id in the range of label | ||
| 35 | + * pool | ||
| 36 | + * @param endLabel represents for the last label id in the range of label | ||
| 37 | + * pool | ||
| 38 | + * @return success or fail | ||
| 39 | + */ | ||
| 40 | + boolean createGlobalPool(LabelResourceId beginLabel, | ||
| 41 | + LabelResourceId endLabel); | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * Destroys a label resource pool of a specific device id. | ||
| 45 | + * | ||
| 46 | + * @param deviceId device identifier | ||
| 47 | + * @return success or fail | ||
| 48 | + */ | ||
| 49 | + boolean destroyDevicePool(DeviceId deviceId); | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * Destroys a the global label resource pool. | ||
| 53 | + * | ||
| 54 | + * @return success or fail | ||
| 55 | + */ | ||
| 56 | + boolean destroyGlobalPool(); | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * Returns labels from resource pool by a specific device id. | ||
| 60 | + * | ||
| 61 | + * @param deviceId device identifier | ||
| 62 | + * @param applyNum the applying number | ||
| 63 | + * @return collection of applying labels | ||
| 64 | + */ | ||
| 65 | + Collection<LabelResource> applyFromDevicePool(DeviceId deviceId, | ||
| 66 | + long applyNum); | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * Returns labels from the global label resource pool. | ||
| 70 | + * | ||
| 71 | + * @param applyNum apply the number of labels | ||
| 72 | + * @return collection of labels | ||
| 73 | + */ | ||
| 74 | + Collection<LabelResource> applyFromGlobalPool(long applyNum); | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * Releases unused labels to device pools . | ||
| 78 | + * | ||
| 79 | + * @param release the collection of releasing labels | ||
| 80 | + * @return success or fail | ||
| 81 | + */ | ||
| 82 | + boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release); | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * Releases unused labels to the global resource pool. | ||
| 86 | + * | ||
| 87 | + * @param release release the collection of releasing labels | ||
| 88 | + * @return success or fail | ||
| 89 | + */ | ||
| 90 | + boolean releaseToGlobalPool(Set<LabelResourceId> release); | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * Judges if the pool of a specific device id is full. | ||
| 94 | + * | ||
| 95 | + * @param deviceId device identifier | ||
| 96 | + * @return yes or no | ||
| 97 | + */ | ||
| 98 | + boolean isDevicePoolFull(DeviceId deviceId); | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * Judges if the global resource pool is full. | ||
| 102 | + * | ||
| 103 | + * @return yes or no | ||
| 104 | + */ | ||
| 105 | + boolean isGlobalPoolFull(); | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * Returns the unused label number of a label resource pool by a specific device | ||
| 109 | + * id. | ||
| 110 | + * | ||
| 111 | + * @param deviceId device identifier | ||
| 112 | + * @return number of unused labels | ||
| 113 | + */ | ||
| 114 | + long getFreeNumOfDevicePool(DeviceId deviceId); | ||
| 115 | + | ||
| 116 | + /** | ||
| 117 | + * Returns the unused number of a global label resource pool. | ||
| 118 | + * | ||
| 119 | + * @return number of unused labels | ||
| 120 | + */ | ||
| 121 | + long getFreeNumOfGlobalPool(); | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * Returns the label resource pool by a specific device id. | ||
| 125 | + * | ||
| 126 | + * @param deviceId device identifier | ||
| 127 | + * @return the device label resource pool | ||
| 128 | + */ | ||
| 129 | + LabelResourcePool getDeviceLabelResourcePool(DeviceId deviceId); | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * Returns the global label resource pool. | ||
| 133 | + * | ||
| 134 | + * @return the global label resource pool | ||
| 135 | + */ | ||
| 136 | + LabelResourcePool getGlobalLabelResourcePool(); | ||
| 137 | +} |
-
Please register or login to post a comment