Committed by
Brian O'Connor
Add sub-types to distinguish type of resources
Change-Id: Ia43cbf4a13937c9bd9dbc97221062ef5fa3e578f
Showing
11 changed files
with
142 additions
and
49 deletions
... | @@ -19,13 +19,14 @@ import com.google.common.annotations.Beta; | ... | @@ -19,13 +19,14 @@ import com.google.common.annotations.Beta; |
19 | import com.google.common.base.MoreObjects; | 19 | import com.google.common.base.MoreObjects; |
20 | import com.google.common.collect.ImmutableList; | 20 | import com.google.common.collect.ImmutableList; |
21 | 21 | ||
22 | -import java.util.Arrays; | ||
23 | import java.util.LinkedList; | 22 | import java.util.LinkedList; |
24 | import java.util.List; | 23 | import java.util.List; |
25 | import java.util.Objects; | 24 | import java.util.Objects; |
26 | import java.util.Optional; | 25 | import java.util.Optional; |
27 | 26 | ||
27 | +import static com.google.common.base.Preconditions.checkArgument; | ||
28 | import static com.google.common.base.Preconditions.checkNotNull; | 28 | import static com.google.common.base.Preconditions.checkNotNull; |
29 | +import static com.google.common.base.Preconditions.checkState; | ||
29 | 30 | ||
30 | /** | 31 | /** |
31 | * An object that is used to locate a resource in a network. | 32 | * An object that is used to locate a resource in a network. |
... | @@ -33,25 +34,45 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -33,25 +34,45 @@ import static com.google.common.base.Preconditions.checkNotNull; |
33 | * of elementary resources that are not globally identifiable. A ResourcePath can be a globally | 34 | * of elementary resources that are not globally identifiable. A ResourcePath can be a globally |
34 | * unique resource identifier. | 35 | * unique resource identifier. |
35 | * | 36 | * |
37 | + * Two types of resource are considered. One is discrete type and the other is continuous type. | ||
38 | + * Discrete type resource is a resource whose amount is measured as a discrete unit. VLAN ID and | ||
39 | + * MPLS label are examples of discrete type resource. Continuous type resource is a resource whose | ||
40 | + * amount is measured as a continuous value. Bandwidth is an example of continuous type resource. | ||
41 | + * A double value is associated with a continuous type value. | ||
42 | + * | ||
36 | * Users of this class must keep the semantics of resources regarding the hierarchical structure. | 43 | * Users of this class must keep the semantics of resources regarding the hierarchical structure. |
37 | * For example, resource path, Link:1/VLAN ID:100, is valid, but resource path, VLAN ID:100/Link:1 | 44 | * For example, resource path, Link:1/VLAN ID:100, is valid, but resource path, VLAN ID:100/Link:1 |
38 | * is not valid because a link is not a sub-component of a VLAN ID. | 45 | * is not valid because a link is not a sub-component of a VLAN ID. |
39 | */ | 46 | */ |
40 | @Beta | 47 | @Beta |
41 | -public final class ResourcePath { | 48 | +public abstract class ResourcePath { |
42 | 49 | ||
43 | - private final ResourcePath parent; | 50 | + private final Discrete parent; |
44 | private final Object last; | 51 | private final Object last; |
45 | 52 | ||
46 | - public static final ResourcePath ROOT = new ResourcePath(ImmutableList.of()); | 53 | + public static final Discrete ROOT = new Discrete(); |
47 | 54 | ||
48 | /** | 55 | /** |
49 | - * Creates an resource path from the specified components. | 56 | + * Creates an resource path which represents a discrete-type resource from the specified components. |
57 | + * | ||
58 | + * @param components components of the path. The order represents hierarchical structure of the resource. | ||
59 | + */ | ||
60 | + public static ResourcePath discrete(Object... components) { | ||
61 | + if (components.length == 0) { | ||
62 | + return ROOT; | ||
63 | + } else { | ||
64 | + return new Discrete(ImmutableList.copyOf(components)); | ||
65 | + } | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * Creates an resource path which represents a continuous-type resource from the specified components. | ||
50 | * | 70 | * |
71 | + * @param value amount of the resource | ||
51 | * @param components components of the path. The order represents hierarchical structure of the resource. | 72 | * @param components components of the path. The order represents hierarchical structure of the resource. |
52 | */ | 73 | */ |
53 | - public ResourcePath(Object... components) { | 74 | + public static ResourcePath continuous(double value, Object... components) { |
54 | - this(Arrays.asList(components)); | 75 | + return new Continuous(ImmutableList.copyOf(components), value); |
55 | } | 76 | } |
56 | 77 | ||
57 | /** | 78 | /** |
... | @@ -59,17 +80,17 @@ public final class ResourcePath { | ... | @@ -59,17 +80,17 @@ public final class ResourcePath { |
59 | * | 80 | * |
60 | * @param components components of the path. The order represents hierarchical structure of the resource. | 81 | * @param components components of the path. The order represents hierarchical structure of the resource. |
61 | */ | 82 | */ |
62 | - public ResourcePath(List<Object> components) { | 83 | + ResourcePath(List<Object> components) { |
63 | checkNotNull(components); | 84 | checkNotNull(components); |
64 | - if (components.isEmpty()) { | 85 | + checkArgument(!components.isEmpty()); |
65 | - this.parent = null; | ||
66 | - this.last = null; | ||
67 | - return; | ||
68 | - } | ||
69 | 86 | ||
70 | LinkedList<Object> children = new LinkedList<>(components); | 87 | LinkedList<Object> children = new LinkedList<>(components); |
71 | this.last = children.pollLast(); | 88 | this.last = children.pollLast(); |
72 | - this.parent = new ResourcePath(children); | 89 | + if (children.isEmpty()) { |
90 | + this.parent = ROOT; | ||
91 | + } else { | ||
92 | + this.parent = new Discrete(children); | ||
93 | + } | ||
73 | } | 94 | } |
74 | 95 | ||
75 | /** | 96 | /** |
... | @@ -78,9 +99,12 @@ public final class ResourcePath { | ... | @@ -78,9 +99,12 @@ public final class ResourcePath { |
78 | * @param parent the parent of this resource | 99 | * @param parent the parent of this resource |
79 | * @param last a child of the parent | 100 | * @param last a child of the parent |
80 | */ | 101 | */ |
81 | - public ResourcePath(ResourcePath parent, Object last) { | 102 | + ResourcePath(Discrete parent, Object last) { |
82 | - this.parent = checkNotNull(parent); | 103 | + checkNotNull(parent); |
83 | - this.last = checkNotNull(last); | 104 | + checkNotNull(last); |
105 | + | ||
106 | + this.parent = parent; | ||
107 | + this.last = last; | ||
84 | } | 108 | } |
85 | 109 | ||
86 | // for serialization | 110 | // for serialization |
... | @@ -97,10 +121,10 @@ public final class ResourcePath { | ... | @@ -97,10 +121,10 @@ public final class ResourcePath { |
97 | public List<Object> components() { | 121 | public List<Object> components() { |
98 | LinkedList<Object> components = new LinkedList<>(); | 122 | LinkedList<Object> components = new LinkedList<>(); |
99 | 123 | ||
100 | - ResourcePath parentPath = parent; | 124 | + Optional<Discrete> parentPath = Optional.ofNullable(parent); |
101 | - while (parentPath != null) { | 125 | + while (parentPath.isPresent()) { |
102 | components.addFirst(last); | 126 | components.addFirst(last); |
103 | - parentPath = parent.parent; | 127 | + parentPath = parent.parent(); |
104 | } | 128 | } |
105 | 129 | ||
106 | return components; | 130 | return components; |
... | @@ -113,12 +137,20 @@ public final class ResourcePath { | ... | @@ -113,12 +137,20 @@ public final class ResourcePath { |
113 | * @return the parent resource path of this instance. | 137 | * @return the parent resource path of this instance. |
114 | * If there is no parent, empty instance will be returned. | 138 | * If there is no parent, empty instance will be returned. |
115 | */ | 139 | */ |
116 | - public Optional<ResourcePath> parent() { | 140 | + public Optional<Discrete> parent() { |
117 | return Optional.ofNullable(parent); | 141 | return Optional.ofNullable(parent); |
118 | } | 142 | } |
119 | 143 | ||
120 | public ResourcePath child(Object child) { | 144 | public ResourcePath child(Object child) { |
121 | - return new ResourcePath(this, child); | 145 | + checkState(this instanceof Discrete); |
146 | + | ||
147 | + return new Discrete((Discrete) this, child); | ||
148 | + } | ||
149 | + | ||
150 | + public ResourcePath child(Object child, double value) { | ||
151 | + checkState(this instanceof Discrete); | ||
152 | + | ||
153 | + return new Continuous((Discrete) this, child, value); | ||
122 | } | 154 | } |
123 | 155 | ||
124 | /** | 156 | /** |
... | @@ -156,4 +188,57 @@ public final class ResourcePath { | ... | @@ -156,4 +188,57 @@ public final class ResourcePath { |
156 | .add("last", last) | 188 | .add("last", last) |
157 | .toString(); | 189 | .toString(); |
158 | } | 190 | } |
191 | + | ||
192 | + /** | ||
193 | + * Represents a resource path which specifies a resource which can be measured | ||
194 | + * as a discrete unit. A VLAN ID and a MPLS label of a link are examples of the resource. | ||
195 | + * <p> | ||
196 | + * Note: This class is exposed to the public, but intended to be used in the resource API | ||
197 | + * implementation only. It is not for resource API user. | ||
198 | + * </p> | ||
199 | + */ | ||
200 | + public static final class Discrete extends ResourcePath { | ||
201 | + private Discrete() { | ||
202 | + super(); | ||
203 | + } | ||
204 | + | ||
205 | + private Discrete(List<Object> components) { | ||
206 | + super(components); | ||
207 | + } | ||
208 | + | ||
209 | + private Discrete(Discrete parent, Object last) { | ||
210 | + super(parent, last); | ||
211 | + } | ||
212 | + } | ||
213 | + | ||
214 | + /** | ||
215 | + * Represents a resource path which specifies a resource which can be measured | ||
216 | + * as continuous value. Bandwidth of a link is an example of the resource. | ||
217 | + * <p> | ||
218 | + * Note: This class is exposed to the public, but intended to be used in the resource API | ||
219 | + * implementation only. It is not for resource API user. | ||
220 | + */ | ||
221 | + public static final class Continuous extends ResourcePath { | ||
222 | + // Note: value is not taken into account for equality | ||
223 | + private final double value; | ||
224 | + | ||
225 | + private Continuous(List<Object> components, double value) { | ||
226 | + super(components); | ||
227 | + this.value = value; | ||
228 | + } | ||
229 | + | ||
230 | + public Continuous(Discrete parent, Object last, double value) { | ||
231 | + super(parent, last); | ||
232 | + this.value = value; | ||
233 | + } | ||
234 | + | ||
235 | + /** | ||
236 | + * Returns the value of the resource amount. | ||
237 | + * | ||
238 | + * @return the value of the resource amount | ||
239 | + */ | ||
240 | + public double value() { | ||
241 | + return value; | ||
242 | + } | ||
243 | + } | ||
159 | } | 244 | } | ... | ... |
... | @@ -38,9 +38,9 @@ public class ResourceAllocationTest { | ... | @@ -38,9 +38,9 @@ public class ResourceAllocationTest { |
38 | 38 | ||
39 | @Test | 39 | @Test |
40 | public void testEquals() { | 40 | public void testEquals() { |
41 | - ResourceAllocation alloc1 = new ResourceAllocation(new ResourcePath(LK1, VLAN1), IID1); | 41 | + ResourceAllocation alloc1 = new ResourceAllocation(ResourcePath.discrete(LK1, VLAN1), IID1); |
42 | - ResourceAllocation sameAsAlloc1 = new ResourceAllocation(new ResourcePath(LK1, VLAN1), IID1); | 42 | + ResourceAllocation sameAsAlloc1 = new ResourceAllocation(ResourcePath.discrete(LK1, VLAN1), IID1); |
43 | - ResourceAllocation alloc2 = new ResourceAllocation(new ResourcePath(LK2, VLAN1), IID1); | 43 | + ResourceAllocation alloc2 = new ResourceAllocation(ResourcePath.discrete(LK2, VLAN1), IID1); |
44 | 44 | ||
45 | new EqualsTester() | 45 | new EqualsTester() |
46 | .addEqualityGroup(alloc1, sameAsAlloc1) | 46 | .addEqualityGroup(alloc1, sameAsAlloc1) | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.net.newresource; | ... | @@ -18,6 +18,7 @@ package org.onosproject.net.newresource; |
18 | import com.google.common.testing.EqualsTester; | 18 | import com.google.common.testing.EqualsTester; |
19 | import org.junit.Test; | 19 | import org.junit.Test; |
20 | import org.onlab.packet.VlanId; | 20 | import org.onlab.packet.VlanId; |
21 | +import org.onlab.util.Bandwidth; | ||
21 | import org.onosproject.net.ConnectPoint; | 22 | import org.onosproject.net.ConnectPoint; |
22 | import org.onosproject.net.DeviceId; | 23 | import org.onosproject.net.DeviceId; |
23 | import org.onosproject.net.LinkKey; | 24 | import org.onosproject.net.LinkKey; |
... | @@ -36,37 +37,42 @@ public class ResourcePathTest { | ... | @@ -36,37 +37,42 @@ public class ResourcePathTest { |
36 | private static final ConnectPoint CP1_1 = new ConnectPoint(D1, P1); | 37 | private static final ConnectPoint CP1_1 = new ConnectPoint(D1, P1); |
37 | private static final ConnectPoint CP2_1 = new ConnectPoint(D2, P1); | 38 | private static final ConnectPoint CP2_1 = new ConnectPoint(D2, P1); |
38 | private static final VlanId VLAN1 = VlanId.vlanId((short) 100); | 39 | private static final VlanId VLAN1 = VlanId.vlanId((short) 100); |
40 | + private static final Bandwidth BW1 = Bandwidth.gbps(2); | ||
41 | + private static final Bandwidth BW2 = Bandwidth.gbps(1); | ||
39 | 42 | ||
40 | @Test | 43 | @Test |
41 | public void testEquals() { | 44 | public void testEquals() { |
42 | - ResourcePath resource1 = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); | 45 | + ResourcePath resource1 = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); |
43 | - ResourcePath sameAsResource1 = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); | 46 | + ResourcePath sameAsResource1 = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); |
44 | - ResourcePath resource2 = new ResourcePath(LinkKey.linkKey(CP2_1, CP1_1), VLAN1); | 47 | + ResourcePath resource2 = ResourcePath.discrete(LinkKey.linkKey(CP2_1, CP1_1), VLAN1); |
48 | + ResourcePath resource3 = ResourcePath.continuous(BW1.bps(), LinkKey.linkKey(CP1_1, CP2_1), BW1); | ||
49 | + ResourcePath sameAsResource3 = ResourcePath.continuous(BW2.bps(), LinkKey.linkKey(CP1_1, CP2_1), BW1); | ||
45 | 50 | ||
46 | new EqualsTester() | 51 | new EqualsTester() |
47 | .addEqualityGroup(resource1, sameAsResource1) | 52 | .addEqualityGroup(resource1, sameAsResource1) |
48 | .addEqualityGroup(resource2) | 53 | .addEqualityGroup(resource2) |
54 | + .addEqualityGroup(resource3, sameAsResource3) // this is intentional | ||
49 | .testEquals(); | 55 | .testEquals(); |
50 | } | 56 | } |
51 | 57 | ||
52 | @Test | 58 | @Test |
53 | public void testCreateWithZeroComponent() { | 59 | public void testCreateWithZeroComponent() { |
54 | - ResourcePath path = new ResourcePath(); | 60 | + ResourcePath path = ResourcePath.discrete(); |
55 | 61 | ||
56 | assertThat(path, is(ResourcePath.ROOT)); | 62 | assertThat(path, is(ResourcePath.ROOT)); |
57 | } | 63 | } |
58 | 64 | ||
59 | @Test | 65 | @Test |
60 | public void testThereIsParent() { | 66 | public void testThereIsParent() { |
61 | - ResourcePath path = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); | 67 | + ResourcePath path = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); |
62 | - ResourcePath parent = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1)); | 68 | + ResourcePath parent = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1)); |
63 | 69 | ||
64 | assertThat(path.parent(), is(Optional.of(parent))); | 70 | assertThat(path.parent(), is(Optional.of(parent))); |
65 | } | 71 | } |
66 | 72 | ||
67 | @Test | 73 | @Test |
68 | public void testNoParent() { | 74 | public void testNoParent() { |
69 | - ResourcePath path = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1)); | 75 | + ResourcePath path = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1)); |
70 | 76 | ||
71 | assertThat(path.parent(), is(Optional.of(ResourcePath.ROOT))); | 77 | assertThat(path.parent(), is(Optional.of(ResourcePath.ROOT))); |
72 | } | 78 | } |
... | @@ -74,7 +80,7 @@ public class ResourcePathTest { | ... | @@ -74,7 +80,7 @@ public class ResourcePathTest { |
74 | @Test | 80 | @Test |
75 | public void testBase() { | 81 | public void testBase() { |
76 | LinkKey linkKey = LinkKey.linkKey(CP1_1, CP2_1); | 82 | LinkKey linkKey = LinkKey.linkKey(CP1_1, CP2_1); |
77 | - ResourcePath path = new ResourcePath(linkKey); | 83 | + ResourcePath path = ResourcePath.discrete(linkKey); |
78 | 84 | ||
79 | LinkKey child = (LinkKey) path.last(); | 85 | LinkKey child = (LinkKey) path.last(); |
80 | assertThat(child, is(linkKey)); | 86 | assertThat(child, is(linkKey)); | ... | ... |
... | @@ -121,7 +121,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { | ... | @@ -121,7 +121,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { |
121 | } | 121 | } |
122 | 122 | ||
123 | List<ResourcePath> resources = labels.entrySet().stream() | 123 | List<ResourcePath> resources = labels.entrySet().stream() |
124 | - .map(x -> new ResourcePath(linkKey(x.getKey().src(), x.getKey().src()), x.getValue())) | 124 | + .map(x -> ResourcePath.discrete(linkKey(x.getKey().src(), x.getKey().src()), x.getValue())) |
125 | .collect(Collectors.toList()); | 125 | .collect(Collectors.toList()); |
126 | List<org.onosproject.net.newresource.ResourceAllocation> allocations = | 126 | List<org.onosproject.net.newresource.ResourceAllocation> allocations = |
127 | resourceService.allocate(intent.id(), resources); | 127 | resourceService.allocate(intent.id(), resources); |
... | @@ -145,7 +145,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { | ... | @@ -145,7 +145,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { |
145 | } | 145 | } |
146 | 146 | ||
147 | private Optional<MplsLabel> findMplsLabel(LinkKey link) { | 147 | private Optional<MplsLabel> findMplsLabel(LinkKey link) { |
148 | - return resourceService.getAvailableResources(new ResourcePath(link)).stream() | 148 | + return resourceService.getAvailableResources(ResourcePath.discrete(link)).stream() |
149 | .filter(x -> x.last() instanceof MplsLabel) | 149 | .filter(x -> x.last() instanceof MplsLabel) |
150 | .map(x -> (MplsLabel) x.last()) | 150 | .map(x -> (MplsLabel) x.last()) |
151 | .findFirst(); | 151 | .findFirst(); | ... | ... |
... | @@ -160,8 +160,8 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu | ... | @@ -160,8 +160,8 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu |
160 | log.debug("Compiling optical circuit intent between {} and {}", src, dst); | 160 | log.debug("Compiling optical circuit intent between {} and {}", src, dst); |
161 | 161 | ||
162 | // Reserve OduClt ports | 162 | // Reserve OduClt ports |
163 | - ResourcePath srcPortPath = new ResourcePath(src.deviceId(), src.port()); | 163 | + ResourcePath srcPortPath = ResourcePath.discrete(src.deviceId(), src.port()); |
164 | - ResourcePath dstPortPath = new ResourcePath(dst.deviceId(), dst.port()); | 164 | + ResourcePath dstPortPath = ResourcePath.discrete(dst.deviceId(), dst.port()); |
165 | List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortPath, dstPortPath); | 165 | List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortPath, dstPortPath); |
166 | if (allocation.isEmpty()) { | 166 | if (allocation.isEmpty()) { |
167 | throw new IntentCompilationException("Unable to reserve ports for intent " + intent); | 167 | throw new IntentCompilationException("Unable to reserve ports for intent " + intent); |
... | @@ -312,7 +312,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu | ... | @@ -312,7 +312,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu |
312 | if (ochCP != null) { | 312 | if (ochCP != null) { |
313 | OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); | 313 | OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); |
314 | Optional<IntentId> intentId = | 314 | Optional<IntentId> intentId = |
315 | - resourceService.getResourceAllocation(new ResourcePath(ochCP.deviceId(), ochCP.port())) | 315 | + resourceService.getResourceAllocation(ResourcePath.discrete(ochCP.deviceId(), ochCP.port())) |
316 | .map(ResourceAllocation::consumer) | 316 | .map(ResourceAllocation::consumer) |
317 | .filter(x -> x instanceof IntentId) | 317 | .filter(x -> x instanceof IntentId) |
318 | .map(x -> (IntentId) x); | 318 | .map(x -> (IntentId) x); |
... | @@ -331,7 +331,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu | ... | @@ -331,7 +331,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu |
331 | } | 331 | } |
332 | 332 | ||
333 | Optional<IntentId> intentId = | 333 | Optional<IntentId> intentId = |
334 | - resourceService.getResourceAllocation(new ResourcePath(oduPort.deviceId(), port.number())) | 334 | + resourceService.getResourceAllocation(ResourcePath.discrete(oduPort.deviceId(), port.number())) |
335 | .map(ResourceAllocation::consumer) | 335 | .map(ResourceAllocation::consumer) |
336 | .filter(x -> x instanceof IntentId) | 336 | .filter(x -> x instanceof IntentId) |
337 | .map(x -> (IntentId) x); | 337 | .map(x -> (IntentId) x); | ... | ... |
... | @@ -107,8 +107,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -107,8 +107,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
107 | log.debug("Compiling optical connectivity intent between {} and {}", src, dst); | 107 | log.debug("Compiling optical connectivity intent between {} and {}", src, dst); |
108 | 108 | ||
109 | // Reserve OCh ports | 109 | // Reserve OCh ports |
110 | - ResourcePath srcPortPath = new ResourcePath(src.deviceId(), src.port()); | 110 | + ResourcePath srcPortPath = ResourcePath.discrete(src.deviceId(), src.port()); |
111 | - ResourcePath dstPortPath = new ResourcePath(dst.deviceId(), dst.port()); | 111 | + ResourcePath dstPortPath = ResourcePath.discrete(dst.deviceId(), dst.port()); |
112 | List<org.onosproject.net.newresource.ResourceAllocation> allocation = | 112 | List<org.onosproject.net.newresource.ResourceAllocation> allocation = |
113 | resourceService.allocate(intent.id(), srcPortPath, dstPortPath); | 113 | resourceService.allocate(intent.id(), srcPortPath, dstPortPath); |
114 | if (allocation.isEmpty()) { | 114 | if (allocation.isEmpty()) { |
... | @@ -182,7 +182,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -182,7 +182,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
182 | 182 | ||
183 | IndexedLambda minLambda = findFirstLambda(lambdas); | 183 | IndexedLambda minLambda = findFirstLambda(lambdas); |
184 | List<ResourcePath> lambdaResources = path.links().stream() | 184 | List<ResourcePath> lambdaResources = path.links().stream() |
185 | - .map(x -> new ResourcePath(linkKey(x.src(), x.dst()))) | 185 | + .map(x -> ResourcePath.discrete(linkKey(x.src(), x.dst()))) |
186 | .map(x -> x.child(minLambda)) | 186 | .map(x -> x.child(minLambda)) |
187 | .collect(Collectors.toList()); | 187 | .collect(Collectors.toList()); |
188 | 188 | ||
... | @@ -196,7 +196,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -196,7 +196,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
196 | 196 | ||
197 | private Set<IndexedLambda> findCommonLambdasOverLinks(List<Link> links) { | 197 | private Set<IndexedLambda> findCommonLambdasOverLinks(List<Link> links) { |
198 | return links.stream() | 198 | return links.stream() |
199 | - .map(x -> new ResourcePath(linkKey(x.src(), x.dst()))) | 199 | + .map(x -> ResourcePath.discrete(linkKey(x.src(), x.dst()))) |
200 | .map(resourceService::getAvailableResources) | 200 | .map(resourceService::getAvailableResources) |
201 | .map(x -> Iterables.filter(x, r -> r.last() instanceof IndexedLambda)) | 201 | .map(x -> Iterables.filter(x, r -> r.last() instanceof IndexedLambda)) |
202 | .map(x -> Iterables.transform(x, r -> (IndexedLambda) r.last())) | 202 | .map(x -> Iterables.transform(x, r -> (IndexedLambda) r.last())) | ... | ... |
... | @@ -75,12 +75,12 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -75,12 +75,12 @@ final class ResourceDeviceListener implements DeviceListener { |
75 | } | 75 | } |
76 | 76 | ||
77 | private void registerPortResource(Device device, Port port) { | 77 | private void registerPortResource(Device device, Port port) { |
78 | - ResourcePath parent = new ResourcePath(device.id()); | 78 | + ResourcePath parent = ResourcePath.discrete(device.id()); |
79 | executor.submit(() -> adminService.registerResources(parent, port.number())); | 79 | executor.submit(() -> adminService.registerResources(parent, port.number())); |
80 | } | 80 | } |
81 | 81 | ||
82 | private void unregisterPortResource(Device device, Port port) { | 82 | private void unregisterPortResource(Device device, Port port) { |
83 | - ResourcePath parent = new ResourcePath(device.id()); | 83 | + ResourcePath parent = ResourcePath.discrete(device.id()); |
84 | executor.submit(() -> adminService.unregisterResources(parent, port.number())); | 84 | executor.submit(() -> adminService.unregisterResources(parent, port.number())); |
85 | } | 85 | } |
86 | } | 86 | } | ... | ... |
... | @@ -87,7 +87,7 @@ final class ResourceLinkListener implements LinkListener { | ... | @@ -87,7 +87,7 @@ final class ResourceLinkListener implements LinkListener { |
87 | LinkKey linkKey = LinkKey.linkKey(link); | 87 | LinkKey linkKey = LinkKey.linkKey(link); |
88 | adminService.registerResources(ResourcePath.ROOT, linkKey); | 88 | adminService.registerResources(ResourcePath.ROOT, linkKey); |
89 | 89 | ||
90 | - ResourcePath linkPath = new ResourcePath(linkKey); | 90 | + ResourcePath linkPath = ResourcePath.discrete(linkKey); |
91 | // register VLAN IDs against the link | 91 | // register VLAN IDs against the link |
92 | if (isEnabled(link, this::isVlanEnabled)) { | 92 | if (isEnabled(link, this::isVlanEnabled)) { |
93 | adminService.registerResources(linkPath, ENTIRE_VLAN_IDS); | 93 | adminService.registerResources(linkPath, ENTIRE_VLAN_IDS); | ... | ... |
... | @@ -231,7 +231,7 @@ public class ObjectiveTrackerTest { | ... | @@ -231,7 +231,7 @@ public class ObjectiveTrackerTest { |
231 | @Test | 231 | @Test |
232 | public void testResourceEvent() throws Exception { | 232 | public void testResourceEvent() throws Exception { |
233 | ResourceEvent event = new ResourceEvent(RESOURCE_ADDED, | 233 | ResourceEvent event = new ResourceEvent(RESOURCE_ADDED, |
234 | - new ResourcePath(linkKey(link("a", 1, "b", 1)))); | 234 | + ResourcePath.discrete(linkKey(link("a", 1, "b", 1)))); |
235 | resourceListener.event(event); | 235 | resourceListener.event(event); |
236 | 236 | ||
237 | assertThat( | 237 | assertThat( | ... | ... |
... | @@ -416,6 +416,8 @@ public final class KryoNamespaces { | ... | @@ -416,6 +416,8 @@ public final class KryoNamespaces { |
416 | BandwidthResourceAllocation.class, | 416 | BandwidthResourceAllocation.class, |
417 | LambdaResourceAllocation.class, | 417 | LambdaResourceAllocation.class, |
418 | ResourcePath.class, | 418 | ResourcePath.class, |
419 | + ResourcePath.Discrete.class, | ||
420 | + ResourcePath.Continuous.class, | ||
419 | ResourceAllocation.class, | 421 | ResourceAllocation.class, |
420 | // Constraints | 422 | // Constraints |
421 | LambdaConstraint.class, | 423 | LambdaConstraint.class, | ... | ... |
... | @@ -373,13 +373,13 @@ public class KryoSerializerTest { | ... | @@ -373,13 +373,13 @@ public class KryoSerializerTest { |
373 | 373 | ||
374 | @Test | 374 | @Test |
375 | public void testResourcePath() { | 375 | public void testResourcePath() { |
376 | - testSerializedEquals(new ResourcePath(LinkKey.linkKey(CP1, CP2), VLAN1)); | 376 | + testSerializedEquals(ResourcePath.discrete(LinkKey.linkKey(CP1, CP2), VLAN1)); |
377 | } | 377 | } |
378 | 378 | ||
379 | @Test | 379 | @Test |
380 | public void testResourceAllocation() { | 380 | public void testResourceAllocation() { |
381 | testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation( | 381 | testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation( |
382 | - new ResourcePath(LinkKey.linkKey(CP1, CP2), VLAN1), | 382 | + ResourcePath.discrete(LinkKey.linkKey(CP1, CP2), VLAN1), |
383 | IntentId.valueOf(30))); | 383 | IntentId.valueOf(30))); |
384 | } | 384 | } |
385 | 385 | ... | ... |
-
Please register or login to post a comment