blob: da80f77a98b44ddde49b801f168b365adf58e286 [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 SHIMIZUb1f16252015-11-25 23:03:16 -080019import org.onosproject.net.DeviceId;
20import org.onosproject.net.PortNumber;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070021
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070022import java.util.List;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070023import java.util.Optional;
24
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080025import static com.google.common.base.Preconditions.checkArgument;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070026
27/**
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -080028 * An object that represent a resource in a network.
29 * A Resource can represents path-like hierarchical structure with its ID. An ID of resource is
30 * composed of a sequence of elementary resources that are not globally identifiable. A Resource
31 * can be globally identifiable by its ID.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070032 *
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080033 * Two types of resource are considered. One is discrete type and the other is continuous type.
34 * Discrete type resource is a resource whose amount is measured as a discrete unit. VLAN ID and
35 * MPLS label are examples of discrete type resource. Continuous type resource is a resource whose
36 * amount is measured as a continuous value. Bandwidth is an example of continuous type resource.
37 * A double value is associated with a continuous type value.
38 *
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070039 * Users of this class must keep the semantics of resources regarding the hierarchical structure.
Sho SHIMIZU8fa670a2016-01-14 11:17:18 -080040 * For example, resource, Device:1/Port:1/VLAN ID:100, is valid, but resource,
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080041 * 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 -070042 */
43@Beta
Sho SHIMIZU2a704512016-01-26 14:41:34 -080044public interface Resource {
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070045
Sho SHIMIZU2a704512016-01-26 14:41:34 -080046 DiscreteResource ROOT = new DiscreteResource();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070047
Sho SHIMIZU2a704512016-01-26 14:41:34 -080048 static DiscreteResource discrete(DeviceId device) {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -080049 return new DiscreteResource(ResourceId.discrete(device));
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080050 }
51
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070052 /**
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080053 * Creates an resource path which represents a discrete-type resource from the specified components.
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070054 *
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080055 * @param device device ID which is the first component of the path
56 * @param components following components of the path. The order represents hierarchical structure of the resource.
Sho SHIMIZUe5524562015-11-24 14:41:20 -080057 * @return resource path instance
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070058 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080059 static DiscreteResource discrete(DeviceId device, Object... components) {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -080060 return new DiscreteResource(ResourceId.discrete(device, components));
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080061 }
62
63 /**
64 * Creates an resource path which represents a discrete-type resource from the specified components.
65 *
66 * @param device device ID which is the first component of the path
67 * @param port port number which is the second component of the path
68 * @param components following components of the path. The order represents hierarchical structure of the resource.
69 * @return resource path instance
70 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080071 static DiscreteResource discrete(DeviceId device, PortNumber port, Object... components) {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -080072 return new DiscreteResource(ResourceId.discrete(device, port, components));
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080073 }
74
75 /**
76 * Creates an resource path which represents a continuous-type resource from the specified components.
77 *
78 * @param value amount of the resource
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080079 * @param device device ID which is the first component of the path
80 * @param components following components of the path. The order represents hierarchical structure of the resource.
Sho SHIMIZU2d310222016-01-22 11:45:11 -080081 * The last element of this list must be an {@link Class} instance. Otherwise, this method throws
82 * an IllegalArgumentException.
Sho SHIMIZUe5524562015-11-24 14:41:20 -080083 * @return resource path instance
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080084 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080085 static ContinuousResource continuous(double value, DeviceId device, Object... components) {
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080086 checkArgument(components.length > 0,
87 "Length of components must be greater thant 0, but " + components.length);
88
Sho SHIMIZUf33b8932016-01-25 18:43:32 -080089 return new ContinuousResource(ResourceId.continuous(device, components), value);
Sho SHIMIZUb1f16252015-11-25 23:03:16 -080090 }
91
92 /**
93 * Creates an resource path which represents a continuous-type resource from the specified components.
94 *
95 * @param value amount of the resource
96 * @param device device ID which is the first component of the path.
97 * @param port port number which is the second component of the path.
98 * @param components following components of the path. The order represents hierarchical structure of the resource.
Sho SHIMIZU2d310222016-01-22 11:45:11 -080099 * The last element of this list must be an {@link Class} instance. Otherwise, this method throws
100 * an IllegalArgumentException.
Sho SHIMIZUb1f16252015-11-25 23:03:16 -0800101 * @return resource path instance
102 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800103 static ContinuousResource continuous(double value, DeviceId device, PortNumber port, Object... components) {
Sho SHIMIZUf33b8932016-01-25 18:43:32 -0800104 return new ContinuousResource(ResourceId.continuous(device, port, components), value);
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700105 }
106
107 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700108 * Returns the components of this resource path.
109 *
110 * @return the components of this resource path
111 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800112 List<Object> components();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700113
114 /**
Sho SHIMIZU2d310222016-01-22 11:45:11 -0800115 * Returns the volume of this resource.
116 *
Sho SHIMIZUf0fb3612016-01-27 11:45:09 -0800117 * @param <T> type of return value
Sho SHIMIZU2d310222016-01-22 11:45:11 -0800118 * @return the volume of this resource
119 */
120 // TODO: think about other naming possibilities. amount? quantity?
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800121 <T> T volume();
Sho SHIMIZU2d310222016-01-22 11:45:11 -0800122
123 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700124 * Returns the parent resource path of this instance.
125 * E.g. if this path is Link:1/VLAN ID:100, the return value is the resource path for Link:1.
126 *
127 * @return the parent resource path of this instance.
128 * If there is no parent, empty instance will be returned.
129 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800130 Optional<DiscreteResource> parent();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700131
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -0800132 /**
133 * Returns a child resource path of this instance with specifying the child object.
134 * The child resource path is discrete-type.
135 *
136 * @param child child object
137 * @return a child resource path
138 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800139 DiscreteResource child(Object child);
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -0800140
Sho SHIMIZU9e1e9de2015-11-25 15:48:48 -0800141 /**
142 * Returns a child resource path of this instance with specifying a child object and
143 * value. The child resource path is continuous-type.
144 *
145 * @param child child object
146 * @param value value
147 * @return a child resource path
148 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800149 ContinuousResource child(Class<?> child, double value);
Sho SHIMIZU01120782015-08-21 15:48:43 -0700150
151 /**
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700152 * Returns the last component of this instance.
153 *
154 * @return the last component of this instance.
155 * The return value is equal to the last object of {@code components()}.
156 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800157 Object last();
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800158
159 /**
Sho SHIMIZU5fb1ea32016-01-14 10:58:14 -0800160 * Returns the ID of this resource path.
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800161 *
Sho SHIMIZU5fb1ea32016-01-14 10:58:14 -0800162 * @return the ID of this resource path
Sho SHIMIZU7e6d18e2016-01-07 18:44:33 -0800163 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -0800164 ResourceId id();
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -0700165}