blob: e3c5c47d09167ca18f25f2e4530dd56af305e5d4 [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;
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080019
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080020import org.onosproject.net.DeviceId;
21import org.onosproject.net.PortNumber;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070022
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070023import java.util.List;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070024import java.util.Optional;
25
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080026import static com.google.common.base.Preconditions.checkArgument;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070027
28/**
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -080029 * An object that represent a resource in a network.
30 * A Resource can represents path-like hierarchical structure with its ID. An ID of resource is
31 * composed of a sequence of elementary resources that are not globally identifiable. A Resource
32 * can be globally identifiable by its ID.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070033 *
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080034 * Two types of resource are considered. One is discrete type and the other is continuous type.
35 * Discrete type resource is a resource whose amount is measured as a discrete unit. VLAN ID and
36 * MPLS label are examples of discrete type resource. Continuous type resource is a resource whose
37 * amount is measured as a continuous value. Bandwidth is an example of continuous type resource.
38 * A double value is associated with a continuous type value.
39 *
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070040 * Users of this class must keep the semantics of resources regarding the hierarchical structure.
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -080041 * For example, resource, Device:1/Port:1/VLAN ID:100, is valid, but resource,
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080042 * 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 -070043 */
44@Beta
Sho SHIMIZU2a704512016-01-26 14:41:34 -080045public interface Resource {
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070046
Sho SHIMIZU2a704512016-01-26 14:41:34 -080047 DiscreteResource ROOT = new DiscreteResource();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070048
Sho SHIMIZU2a704512016-01-26 14:41:34 -080049 static DiscreteResource discrete(DeviceId device) {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -080050 return new DiscreteResource(ResourceId.discrete(device));
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080051 }
52
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070053 /**
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080054 * Creates an resource path which represents a discrete-type resource from the specified components.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070055 *
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080056 * @param device device ID which is the first component of the path
57 * @param components following components of the path. The order represents hierarchical structure of the resource.
Sho SHIMIZUe5524562015-11-24 14:41:20 -080058 * @return resource path instance
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070059 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080060 static DiscreteResource discrete(DeviceId device, Object... components) {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -080061 return new DiscreteResource(ResourceId.discrete(device, components));
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080062 }
63
64 /**
65 * Creates an resource path which represents a discrete-type resource from the specified components.
66 *
67 * @param device device ID which is the first component of the path
68 * @param port port number which is the second component of the path
69 * @param components following components of the path. The order represents hierarchical structure of the resource.
70 * @return resource path instance
71 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080072 static DiscreteResource discrete(DeviceId device, PortNumber port, Object... components) {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -080073 return new DiscreteResource(ResourceId.discrete(device, port, components));
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080074 }
75
76 /**
77 * Creates an resource path which represents a continuous-type resource from the specified components.
78 *
79 * @param value amount of the resource
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080080 * @param device device ID which is the first component of the path
81 * @param components following components of the path. The order represents hierarchical structure of the resource.
Sho SHIMIZU2d310222016-01-22 11:45:11 -080082 * The last element of this list must be an {@link Class} instance. Otherwise, this method throws
83 * an IllegalArgumentException.
Sho SHIMIZUe5524562015-11-24 14:41:20 -080084 * @return resource path instance
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080085 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080086 static ContinuousResource continuous(double value, DeviceId device, Object... components) {
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080087 checkArgument(components.length > 0,
88 "Length of components must be greater thant 0, but " + components.length);
89
Sho SHIMIZUf33b8932016-01-25 18:43:32 -080090 return new ContinuousResource(ResourceId.continuous(device, components), value);
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080091 }
92
93 /**
94 * Creates an resource path which represents a continuous-type resource from the specified components.
95 *
96 * @param value amount of the resource
97 * @param device device ID which is the first component of the path.
98 * @param port port number which is the second component of the path.
99 * @param components following components of the path. The order represents hierarchical structure of the resource.
Sho SHIMIZU2d310222016-01-22 11:45:11 -0800100 * The last element of this list must be an {@link Class} instance. Otherwise, this method throws
101 * an IllegalArgumentException.
Sho SHIMIZUb1f16252015-11-25 23:03:16 -0800102 * @return resource path instance
103 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800104 static ContinuousResource continuous(double value, DeviceId device, PortNumber port, Object... components) {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800105 return new ContinuousResource(ResourceId.continuous(device, port, components), value);
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700106 }
107
108 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700109 * Returns the components of this resource path.
110 *
111 * @return the components of this resource path
112 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800113 List<Object> components();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700114
115 /**
Sho SHIMIZU2d310222016-01-22 11:45:11 -0800116 * Returns the volume of this resource.
117 *
Sho SHIMIZUf0fb3612016-01-27 11:45:09 -0800118 * @param <T> type of return value
Sho SHIMIZU2d310222016-01-22 11:45:11 -0800119 * @return the volume of this resource
120 */
121 // TODO: think about other naming possibilities. amount? quantity?
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800122 <T> T volume();
Sho SHIMIZU2d310222016-01-22 11:45:11 -0800123
124 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700125 * Returns the parent resource path of this instance.
126 * E.g. if this path is Link:1/VLAN ID:100, the return value is the resource path for Link:1.
127 *
128 * @return the parent resource path of this instance.
129 * If there is no parent, empty instance will be returned.
130 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800131 Optional<DiscreteResource> parent();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700132
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -0800133 /**
134 * Returns a child resource path of this instance with specifying the child object.
135 * The child resource path is discrete-type.
136 *
137 * @param child child object
138 * @return a child resource path
139 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800140 DiscreteResource child(Object child);
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -0800141
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -0800142 /**
143 * Returns a child resource path of this instance with specifying a child object and
144 * value. The child resource path is continuous-type.
145 *
146 * @param child child object
147 * @param value value
148 * @return a child resource path
149 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800150 ContinuousResource child(Class<?> child, double value);
Sho SHIMIZU01120782015-08-21 15:48:43 -0700151
152 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700153 * Returns the last component of this instance.
154 *
155 * @return the last component of this instance.
156 * The return value is equal to the last object of {@code components()}.
157 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800158 Object last();
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800159
160 /**
Sho SHIMIZU5fb1ea32016-01-14 10:58:14 -0800161 * Returns the ID of this resource path.
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800162 *
Sho SHIMIZU5fb1ea32016-01-14 10:58:14 -0800163 * @return the ID of this resource path
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800164 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800165 ResourceId id();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700166}