Toshio Koide

Starting point for designing a resource manager API.

package org.onlab.onos.net.resource;
import java.util.Objects;
/**
* Representation of bandwidth resource.
*/
public final class Bandwidth extends LinkResource {
private final double bandwidth;
/**
* Creates a new instance with given bandwidth.
*
* @param bandwidth bandwidth value to be assigned
*/
private Bandwidth(double bandwidth) {
this.bandwidth = bandwidth;
}
/**
* Creates a new instance with given bandwidth.
*
* @param bandwidth bandwidth value to be assigned
* @return {@link Bandwidth} instance with given bandwidth
*/
public static Bandwidth valueOf(double bandwidth) {
return new Bandwidth(bandwidth);
}
/**
* Returns bandwidth as a double value.
*
* @return bandwidth as a double value
*/
public double toDouble() {
return bandwidth;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Bandwidth) {
Bandwidth that = (Bandwidth) obj;
return Objects.equals(this.bandwidth, that.bandwidth);
}
return false;
}
@Override
public int hashCode() {
return Objects.hashCode(this.bandwidth);
}
@Override
public String toString() {
return String.valueOf(this.bandwidth);
}
}
package org.onlab.onos.net.resource;
import java.util.Objects;
/**
* Representation of lambda resource.
*/
public final class Lambda extends LinkResource {
private final int lambda;
/**
* Creates a new instance with given lambda.
*
* @param lambda lambda value to be assigned
*/
private Lambda(int lambda) {
this.lambda = lambda;
}
/**
* Creates a new instance with given lambda.
*
* @param lambda lambda value to be assigned
* @return {@link Lambda} instance with given lambda
*/
public static Lambda valueOf(int lambda) {
return new Lambda(lambda);
}
/**
* Returns lambda as an int value.
* @return lambda as an int value
*/
public int toInt() {
return lambda;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Lambda) {
Lambda that = (Lambda) obj;
return Objects.equals(this.lambda, that.lambda);
}
return false;
}
@Override
public int hashCode() {
return Objects.hashCode(this.lambda);
}
@Override
public String toString() {
return String.valueOf(this.lambda);
}
}
package org.onlab.onos.net.resource;
/**
* Abstraction of link resource.
*/
public abstract class LinkResource {
}
package org.onlab.onos.net.resource;
import java.util.Map;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.PathIntent;
/**
* Service for providing link resource allocation.
*/
public interface LinkResourceService {
/**
* Allocates resources along the path.
* <p>
* Tries to allocate given resources on the links along the path specified
* by the given intent.
*
* @param res resources to be allocated
* @param intent an intent to be used for specifying the path
*/
void allocateResource(LinkResources res, PathIntent intent);
/**
* Releases resources along the path.
*
* @param intentId an ID for the intent for specifying the path
*/
void releaseResource(IntentId intentId);
/**
* Returns all allocated resources to each link.
*
* @return allocated resources to each link with {@link IntentId}
*/
Map<Link, Map<IntentId, LinkResources>> allocatedResources();
/**
* Returns all allocated resources to given link.
*
* @param link a target link
* @return allocated resources to the target link with {@link IntentId}
*/
Map<IntentId, LinkResources> allocatedResources(Link link);
/**
* Returns available resources for each link.
*
* @return available resources for each link
*/
Map<Link, LinkResources> availableResources();
/**
* Returns available resources for given link.
* @param link a target link
* @return available resources for the target link
*/
LinkResource availableResources(Link link);
}
package org.onlab.onos.net.resource;
import java.util.Set;
/**
* Abstraction of a resources of a link.
*/
public interface LinkResources {
/**
* Returns resources as a set of {@link LinkResource}s.
*
* @return a set of {@link LinkResource}s
*/
Set<LinkResource> resources();
/**
* Builder of {@link LinkResources}.
*/
public interface Builder {
/**
* Adds bandwidth resource.
* <p>
* This operation adds given bandwidth to previous bandwidth and
* generates single bandwidth resource.
*
* @param bandwidth bandwidth value to be added
* @return self
*/
public Builder addBandwidth(double bandwidth);
/**
* Adds lambda resource.
*
* @param lambda lambda value to be added
* @return self
*/
public Builder addLambda(int lambda);
/**
* Builds an immutable link resources.
*
* @return link resources
*/
public LinkResources build();
}
}