blob: 199e9c5c47ed2e68fe6f603085df741254ce512b [file] [log] [blame]
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -07001/*
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -08002 * Copyright 2015-2016 Open Networking Laboratory
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.net.newresource;
17
18import com.google.common.annotations.Beta;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070019
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070020import java.util.List;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070021import java.util.Optional;
22
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070023/**
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -080024 * An object that represent a resource in a network.
25 * A Resource can represents path-like hierarchical structure with its ID. An ID of resource is
26 * composed of a sequence of elementary resources that are not globally identifiable. A Resource
27 * can be globally identifiable by its ID.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070028 *
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080029 * Two types of resource are considered. One is discrete type and the other is continuous type.
30 * Discrete type resource is a resource whose amount is measured as a discrete unit. VLAN ID and
31 * MPLS label are examples of discrete type resource. Continuous type resource is a resource whose
32 * amount is measured as a continuous value. Bandwidth is an example of continuous type resource.
33 * A double value is associated with a continuous type value.
34 *
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070035 * Users of this class must keep the semantics of resources regarding the hierarchical structure.
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -080036 * For example, resource, Device:1/Port:1/VLAN ID:100, is valid, but resource,
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080037 * VLAN ID:100/Device:1/Port:1 is not valid because a link is not a sub-component of a VLAN ID.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070038 */
39@Beta
Sho SHIMIZU2a704512016-01-26 14:41:34 -080040public interface Resource {
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070041
Sho SHIMIZU2a704512016-01-26 14:41:34 -080042 DiscreteResource ROOT = new DiscreteResource();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070043
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070044 /**
Sho SHIMIZU19816f42016-01-29 11:32:02 -080045 * Returns the components of this resource.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070046 *
Sho SHIMIZU19816f42016-01-29 11:32:02 -080047 * @return the components of this resource
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070048 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080049 List<Object> components();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070050
51 /**
Sho SHIMIZU2d310222016-01-22 11:45:11 -080052 * Returns the volume of this resource.
53 *
Sho SHIMIZUf0fb3612016-01-27 11:45:09 -080054 * @param <T> type of return value
Sho SHIMIZU2d310222016-01-22 11:45:11 -080055 * @return the volume of this resource
56 */
57 // TODO: think about other naming possibilities. amount? quantity?
Sho SHIMIZU2a704512016-01-26 14:41:34 -080058 <T> T volume();
Sho SHIMIZU2d310222016-01-22 11:45:11 -080059
60 /**
Sho SHIMIZU19816f42016-01-29 11:32:02 -080061 * Returns the parent resource of this instance.
62 * E.g. if this resource is Link:1/VLAN ID:100, the return value is the resource for Link:1.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070063 *
Sho SHIMIZU19816f42016-01-29 11:32:02 -080064 * @return the parent resource of this instance.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070065 * If there is no parent, empty instance will be returned.
66 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080067 Optional<DiscreteResource> parent();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070068
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -080069 /**
Sho SHIMIZU19816f42016-01-29 11:32:02 -080070 * Returns a child resource of this instance with specifying the child object.
71 * It is not allowed that a continuous type resource has a child. If the instance is
72 * ContinuousResource, {@link UnsupportedOperationException} is thrown. If the given
73 * object is a {@link Class} instance, {@link IllegalArgumentException} is thrown.
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -080074 *
75 * @param child child object
Sho SHIMIZU19816f42016-01-29 11:32:02 -080076 * @return a child resource
77 * @throws IllegalArgumentException if the given object is a {@link Class} instance.
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -080078 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080079 DiscreteResource child(Object child);
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080080
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -080081 /**
Sho SHIMIZU19816f42016-01-29 11:32:02 -080082 * Returns a child resource of this instance with specifying a child object and
83 * value. It is not allowed that a continuous type resource has a child. If the instance is
84 * ContinuousResource, {@link UnsupportedOperationException} is thrown.
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -080085 *
86 * @param child child object
87 * @param value value
Sho SHIMIZU19816f42016-01-29 11:32:02 -080088 * @return a child resource
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -080089 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080090 ContinuousResource child(Class<?> child, double value);
Sho SHIMIZU01120782015-08-21 15:48:43 -070091
92 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070093 * Returns the last component of this instance.
94 *
95 * @return the last component of this instance.
96 * The return value is equal to the last object of {@code components()}.
97 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080098 Object last();
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -080099
100 /**
Sho SHIMIZU19816f42016-01-29 11:32:02 -0800101 * Returns the ID of this resource.
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800102 *
Sho SHIMIZU19816f42016-01-29 11:32:02 -0800103 * @return the ID of this resource
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800104 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800105 ResourceId id();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700106}