Committed by
Gerrit Code Review
Support for OTN using optical circuit intents.
Refined DeviceResourceService. Change-Id: I489f368a0fac5f4a8d0a1a1cb716f845558db35e
Showing
13 changed files
with
749 additions
and
50 deletions
... | @@ -29,7 +29,9 @@ import org.onosproject.net.ConnectPoint; | ... | @@ -29,7 +29,9 @@ import org.onosproject.net.ConnectPoint; |
29 | import org.onosproject.net.Device; | 29 | import org.onosproject.net.Device; |
30 | import org.onosproject.net.Host; | 30 | import org.onosproject.net.Host; |
31 | import org.onosproject.net.Link; | 31 | import org.onosproject.net.Link; |
32 | +import org.onosproject.net.OchPort; | ||
32 | import org.onosproject.net.OduCltPort; | 33 | import org.onosproject.net.OduCltPort; |
34 | +import org.onosproject.net.OduSignalType; | ||
33 | import org.onosproject.net.Path; | 35 | import org.onosproject.net.Path; |
34 | import org.onosproject.net.Port; | 36 | import org.onosproject.net.Port; |
35 | import org.onosproject.net.device.DeviceService; | 37 | import org.onosproject.net.device.DeviceService; |
... | @@ -40,6 +42,7 @@ import org.onosproject.net.intent.IntentEvent; | ... | @@ -40,6 +42,7 @@ import org.onosproject.net.intent.IntentEvent; |
40 | import org.onosproject.net.intent.IntentListener; | 42 | import org.onosproject.net.intent.IntentListener; |
41 | import org.onosproject.net.intent.IntentService; | 43 | import org.onosproject.net.intent.IntentService; |
42 | import org.onosproject.net.intent.IntentState; | 44 | import org.onosproject.net.intent.IntentState; |
45 | +import org.onosproject.net.intent.OpticalCircuitIntent; | ||
43 | import org.onosproject.net.intent.OpticalConnectivityIntent; | 46 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
44 | import org.onosproject.net.intent.PointToPointIntent; | 47 | import org.onosproject.net.intent.PointToPointIntent; |
45 | import org.onosproject.net.resource.device.DeviceResourceService; | 48 | import org.onosproject.net.resource.device.DeviceResourceService; |
... | @@ -307,17 +310,33 @@ public class OpticalPathProvisioner { | ... | @@ -307,17 +310,33 @@ public class OpticalPathProvisioner { |
307 | 310 | ||
308 | Port srcPort = deviceService.getPort(src.deviceId(), src.port()); | 311 | Port srcPort = deviceService.getPort(src.deviceId(), src.port()); |
309 | Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); | 312 | Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); |
310 | - // Create lightpath | 313 | + |
311 | - // TODO: Ensure src & dst are of type OchPort | ||
312 | - Intent opticalIntent = OpticalConnectivityIntent.builder() | ||
313 | - .appId(appId) | ||
314 | - .src(src) | ||
315 | - .dst(dst) | ||
316 | - .build(); | ||
317 | - intents.add(opticalIntent); | ||
318 | if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) { | 314 | if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) { |
315 | + // TODO: Check availability of ports | ||
316 | + | ||
317 | + // Create OTN circuit | ||
318 | + Intent circuitIntent = OpticalCircuitIntent.builder() | ||
319 | + .appId(appId) | ||
320 | + .src(src) | ||
321 | + .dst(dst) | ||
322 | + .signalType(OduCltPort.SignalType.CLT_10GBE) | ||
323 | + .build(); | ||
324 | + intents.add(circuitIntent); | ||
325 | + continue; | ||
326 | + } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) { | ||
327 | + // Create lightpath | ||
328 | + // FIXME: hardcoded ODU signal type | ||
329 | + Intent opticalIntent = OpticalConnectivityIntent.builder() | ||
330 | + .appId(appId) | ||
331 | + .src(src) | ||
332 | + .dst(dst) | ||
333 | + .signalType(OduSignalType.ODU4) | ||
334 | + .build(); | ||
335 | + intents.add(opticalIntent); | ||
319 | continue; | 336 | continue; |
320 | - // also create OTN service | 337 | + } else { |
338 | + log.warn("Unsupported cross connect point types {} {}", srcPort.type(), dstPort.type()); | ||
339 | + return Collections.emptyList(); | ||
321 | } | 340 | } |
322 | } | 341 | } |
323 | 342 | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.cli.net; | ... | @@ -18,6 +18,7 @@ package org.onosproject.cli.net; |
18 | import org.apache.karaf.shell.commands.Argument; | 18 | import org.apache.karaf.shell.commands.Argument; |
19 | import org.apache.karaf.shell.commands.Command; | 19 | import org.apache.karaf.shell.commands.Command; |
20 | import org.onosproject.net.ConnectPoint; | 20 | import org.onosproject.net.ConnectPoint; |
21 | +import org.onosproject.net.OduSignalType; | ||
21 | import org.onosproject.net.intent.Intent; | 22 | import org.onosproject.net.intent.Intent; |
22 | import org.onosproject.net.intent.IntentService; | 23 | import org.onosproject.net.intent.IntentService; |
23 | import org.onosproject.net.intent.OpticalConnectivityIntent; | 24 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
... | @@ -47,11 +48,13 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand { | ... | @@ -47,11 +48,13 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand { |
47 | 48 | ||
48 | ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString); | 49 | ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString); |
49 | 50 | ||
51 | + // FIXME: Hardcoded ODU signal type | ||
50 | Intent intent = OpticalConnectivityIntent.builder() | 52 | Intent intent = OpticalConnectivityIntent.builder() |
51 | .appId(appId()) | 53 | .appId(appId()) |
52 | .key(key()) | 54 | .key(key()) |
53 | .src(ingress) | 55 | .src(ingress) |
54 | .dst(egress) | 56 | .dst(egress) |
57 | + .signalType(OduSignalType.ODU4) | ||
55 | .build(); | 58 | .build(); |
56 | service.submit(intent); | 59 | service.submit(intent); |
57 | print("Optical intent submitted:\n%s", intent.toString()); | 60 | print("Optical intent submitted:\n%s", intent.toString()); | ... | ... |
... | @@ -23,7 +23,7 @@ import java.util.Objects; | ... | @@ -23,7 +23,7 @@ import java.util.Objects; |
23 | import static com.google.common.base.Preconditions.checkNotNull; | 23 | import static com.google.common.base.Preconditions.checkNotNull; |
24 | 24 | ||
25 | /** | 25 | /** |
26 | - * Implementation of OCh (Optical Channel) singal type criterion. | 26 | + * Implementation of OCh (Optical Channel) signal type criterion. |
27 | */ | 27 | */ |
28 | public class OchSignalTypeCriterion implements Criterion { | 28 | public class OchSignalTypeCriterion implements Criterion { |
29 | 29 | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
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 | + */ | ||
16 | +package org.onosproject.net.intent; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import org.onosproject.core.ApplicationId; | ||
20 | +import org.onosproject.net.ConnectPoint; | ||
21 | +import org.onosproject.net.OduCltPort; | ||
22 | + | ||
23 | +import java.util.Collections; | ||
24 | + | ||
25 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
26 | + | ||
27 | +/** | ||
28 | + * An optical layer intent for circuits between two OduClt ports. | ||
29 | + * No traffic selector or traffic treatment are needed. | ||
30 | + */ | ||
31 | +public class OpticalCircuitIntent extends Intent { | ||
32 | + private final ConnectPoint src; | ||
33 | + private final ConnectPoint dst; | ||
34 | + private final OduCltPort.SignalType signalType; | ||
35 | + | ||
36 | + /** | ||
37 | + * Creates an optical circuit intent between the specified | ||
38 | + * connection points. | ||
39 | + * | ||
40 | + * @param appId application identification | ||
41 | + * @param key intent key | ||
42 | + * @param src the source transponder port | ||
43 | + * @param dst the destination transponder port | ||
44 | + * @param signalType ODU signal type | ||
45 | + * @param priority priority to use for flows from this intent | ||
46 | + */ | ||
47 | + protected OpticalCircuitIntent(ApplicationId appId, Key key, ConnectPoint src, ConnectPoint dst, | ||
48 | + OduCltPort.SignalType signalType, int priority) { | ||
49 | + super(appId, key, Collections.emptyList(), priority); | ||
50 | + this.src = checkNotNull(src); | ||
51 | + this.dst = checkNotNull(dst); | ||
52 | + this.signalType = checkNotNull(signalType); | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Returns a new optical circuit intent builder. | ||
57 | + * | ||
58 | + * @return host to host intent builder | ||
59 | + */ | ||
60 | + public static Builder builder() { | ||
61 | + return new Builder(); | ||
62 | + } | ||
63 | + | ||
64 | + | ||
65 | + /** | ||
66 | + * Builder for optical circuit intents. | ||
67 | + */ | ||
68 | + public static class Builder extends Intent.Builder { | ||
69 | + private ConnectPoint src; | ||
70 | + private ConnectPoint dst; | ||
71 | + private OduCltPort.SignalType signalType; | ||
72 | + | ||
73 | + @Override | ||
74 | + public Builder appId(ApplicationId appId) { | ||
75 | + return (Builder) super.appId(appId); | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public Builder key(Key key) { | ||
80 | + return (Builder) super.key(key); | ||
81 | + } | ||
82 | + | ||
83 | + @Override | ||
84 | + public Builder priority(int priority) { | ||
85 | + return (Builder) super.priority(priority); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Sets the source for the intent that will be built. | ||
90 | + * | ||
91 | + * @param src source to use for built intent | ||
92 | + * @return this builder | ||
93 | + */ | ||
94 | + public Builder src(ConnectPoint src) { | ||
95 | + this.src = src; | ||
96 | + return this; | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Sets the destination for the intent that will be built. | ||
101 | + * | ||
102 | + * @param dst dest to use for built intent | ||
103 | + * @return this builder | ||
104 | + */ | ||
105 | + public Builder dst(ConnectPoint dst) { | ||
106 | + this.dst = dst; | ||
107 | + return this; | ||
108 | + } | ||
109 | + | ||
110 | + /** | ||
111 | + * Sets the ODU signal type for the intent that will be built. | ||
112 | + * | ||
113 | + * @param signalType signal type to use for built intent | ||
114 | + * @return this builder | ||
115 | + */ | ||
116 | + public Builder signalType(OduCltPort.SignalType signalType) { | ||
117 | + this.signalType = signalType; | ||
118 | + return this; | ||
119 | + } | ||
120 | + | ||
121 | + /** | ||
122 | + * Builds an optical circuit intent from the accumulated parameters. | ||
123 | + * | ||
124 | + * @return point to point intent | ||
125 | + */ | ||
126 | + public OpticalCircuitIntent build() { | ||
127 | + | ||
128 | + return new OpticalCircuitIntent( | ||
129 | + appId, | ||
130 | + key, | ||
131 | + src, | ||
132 | + dst, | ||
133 | + signalType, | ||
134 | + priority | ||
135 | + ); | ||
136 | + } | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Constructor for serializer. | ||
141 | + */ | ||
142 | + protected OpticalCircuitIntent() { | ||
143 | + super(); | ||
144 | + this.src = null; | ||
145 | + this.dst = null; | ||
146 | + this.signalType = null; | ||
147 | + } | ||
148 | + | ||
149 | + /** | ||
150 | + * Returns the source transponder port. | ||
151 | + * | ||
152 | + * @return source transponder port | ||
153 | + */ | ||
154 | + public ConnectPoint getSrc() { | ||
155 | + return src; | ||
156 | + } | ||
157 | + | ||
158 | + /** | ||
159 | + * Returns the destination transponder port. | ||
160 | + * | ||
161 | + * @return source transponder port | ||
162 | + */ | ||
163 | + public ConnectPoint getDst() { | ||
164 | + return dst; | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
168 | + * Returns the ODU signal type. | ||
169 | + * | ||
170 | + * @return ODU signal type | ||
171 | + */ | ||
172 | + public OduCltPort.SignalType getSignalType() { | ||
173 | + return signalType; | ||
174 | + } | ||
175 | + | ||
176 | + @Override | ||
177 | + public String toString() { | ||
178 | + return MoreObjects.toStringHelper(this) | ||
179 | + .add("id", id()) | ||
180 | + .add("key", key()) | ||
181 | + .add("appId", appId()) | ||
182 | + .add("priority", priority()) | ||
183 | + .add("resources", resources()) | ||
184 | + .add("src", src) | ||
185 | + .add("dst", dst) | ||
186 | + .add("signalType", signalType) | ||
187 | + .toString(); | ||
188 | + } | ||
189 | + | ||
190 | +} |
... | @@ -18,6 +18,7 @@ package org.onosproject.net.intent; | ... | @@ -18,6 +18,7 @@ package org.onosproject.net.intent; |
18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
19 | import org.onosproject.core.ApplicationId; | 19 | import org.onosproject.core.ApplicationId; |
20 | import org.onosproject.net.ConnectPoint; | 20 | import org.onosproject.net.ConnectPoint; |
21 | +import org.onosproject.net.OduSignalType; | ||
21 | 22 | ||
22 | import java.util.Collections; | 23 | import java.util.Collections; |
23 | 24 | ||
... | @@ -30,6 +31,7 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -30,6 +31,7 @@ import static com.google.common.base.Preconditions.checkNotNull; |
30 | public final class OpticalConnectivityIntent extends Intent { | 31 | public final class OpticalConnectivityIntent extends Intent { |
31 | private final ConnectPoint src; | 32 | private final ConnectPoint src; |
32 | private final ConnectPoint dst; | 33 | private final ConnectPoint dst; |
34 | + private final OduSignalType signalType; | ||
33 | 35 | ||
34 | /** | 36 | /** |
35 | * Creates an optical connectivity intent between the specified | 37 | * Creates an optical connectivity intent between the specified |
... | @@ -42,13 +44,15 @@ public final class OpticalConnectivityIntent extends Intent { | ... | @@ -42,13 +44,15 @@ public final class OpticalConnectivityIntent extends Intent { |
42 | * @param priority priority to use for flows from this intent | 44 | * @param priority priority to use for flows from this intent |
43 | */ | 45 | */ |
44 | protected OpticalConnectivityIntent(ApplicationId appId, | 46 | protected OpticalConnectivityIntent(ApplicationId appId, |
45 | - Key key, | 47 | + Key key, |
46 | - ConnectPoint src, | 48 | + ConnectPoint src, |
47 | - ConnectPoint dst, | 49 | + ConnectPoint dst, |
48 | - int priority) { | 50 | + OduSignalType signalType, |
51 | + int priority) { | ||
49 | super(appId, key, Collections.emptyList(), priority); | 52 | super(appId, key, Collections.emptyList(), priority); |
50 | this.src = checkNotNull(src); | 53 | this.src = checkNotNull(src); |
51 | this.dst = checkNotNull(dst); | 54 | this.dst = checkNotNull(dst); |
55 | + this.signalType = checkNotNull(signalType); | ||
52 | } | 56 | } |
53 | 57 | ||
54 | /** | 58 | /** |
... | @@ -67,6 +71,7 @@ public final class OpticalConnectivityIntent extends Intent { | ... | @@ -67,6 +71,7 @@ public final class OpticalConnectivityIntent extends Intent { |
67 | public static class Builder extends Intent.Builder { | 71 | public static class Builder extends Intent.Builder { |
68 | private ConnectPoint src; | 72 | private ConnectPoint src; |
69 | private ConnectPoint dst; | 73 | private ConnectPoint dst; |
74 | + private OduSignalType signalType; | ||
70 | 75 | ||
71 | @Override | 76 | @Override |
72 | public Builder appId(ApplicationId appId) { | 77 | public Builder appId(ApplicationId appId) { |
... | @@ -106,6 +111,17 @@ public final class OpticalConnectivityIntent extends Intent { | ... | @@ -106,6 +111,17 @@ public final class OpticalConnectivityIntent extends Intent { |
106 | } | 111 | } |
107 | 112 | ||
108 | /** | 113 | /** |
114 | + * Sets the ODU signal type for the intent that will be built. | ||
115 | + * | ||
116 | + * @param signalType ODU signal type | ||
117 | + * @return this builder | ||
118 | + */ | ||
119 | + public Builder signalType(OduSignalType signalType) { | ||
120 | + this.signalType = signalType; | ||
121 | + return this; | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
109 | * Builds an optical connectivity intent from the accumulated parameters. | 125 | * Builds an optical connectivity intent from the accumulated parameters. |
110 | * | 126 | * |
111 | * @return point to point intent | 127 | * @return point to point intent |
... | @@ -117,6 +133,7 @@ public final class OpticalConnectivityIntent extends Intent { | ... | @@ -117,6 +133,7 @@ public final class OpticalConnectivityIntent extends Intent { |
117 | key, | 133 | key, |
118 | src, | 134 | src, |
119 | dst, | 135 | dst, |
136 | + signalType, | ||
120 | priority | 137 | priority |
121 | ); | 138 | ); |
122 | } | 139 | } |
... | @@ -129,6 +146,7 @@ public final class OpticalConnectivityIntent extends Intent { | ... | @@ -129,6 +146,7 @@ public final class OpticalConnectivityIntent extends Intent { |
129 | super(); | 146 | super(); |
130 | this.src = null; | 147 | this.src = null; |
131 | this.dst = null; | 148 | this.dst = null; |
149 | + this.signalType = null; | ||
132 | } | 150 | } |
133 | 151 | ||
134 | /** | 152 | /** |
... | @@ -149,6 +167,15 @@ public final class OpticalConnectivityIntent extends Intent { | ... | @@ -149,6 +167,15 @@ public final class OpticalConnectivityIntent extends Intent { |
149 | return dst; | 167 | return dst; |
150 | } | 168 | } |
151 | 169 | ||
170 | + /** | ||
171 | + * Returns the ODU signal type. | ||
172 | + * | ||
173 | + * @return ODU signal type | ||
174 | + */ | ||
175 | + public OduSignalType getSignalType() { | ||
176 | + return signalType; | ||
177 | + } | ||
178 | + | ||
152 | @Override | 179 | @Override |
153 | public String toString() { | 180 | public String toString() { |
154 | return MoreObjects.toStringHelper(this) | 181 | return MoreObjects.toStringHelper(this) |
... | @@ -159,6 +186,7 @@ public final class OpticalConnectivityIntent extends Intent { | ... | @@ -159,6 +186,7 @@ public final class OpticalConnectivityIntent extends Intent { |
159 | .add("resources", resources()) | 186 | .add("resources", resources()) |
160 | .add("src", src) | 187 | .add("src", src) |
161 | .add("dst", dst) | 188 | .add("dst", dst) |
189 | + .add("signalType", signalType) | ||
162 | .toString(); | 190 | .toString(); |
163 | } | 191 | } |
164 | } | 192 | } | ... | ... |
... | @@ -28,10 +28,46 @@ public interface DeviceResourceService { | ... | @@ -28,10 +28,46 @@ public interface DeviceResourceService { |
28 | /** | 28 | /** |
29 | * Request a set of ports needed to satisfy the intent. | 29 | * Request a set of ports needed to satisfy the intent. |
30 | * | 30 | * |
31 | + * @param ports set of ports to allocate | ||
31 | * @param intent the intent | 32 | * @param intent the intent |
32 | - * @return set of ports | 33 | + * @return true if ports were successfully allocated, false otherwise |
33 | */ | 34 | */ |
34 | - Set<Port> requestPorts(Intent intent); | 35 | + boolean requestPorts(Set<Port> ports, Intent intent); |
36 | + | ||
37 | + /** | ||
38 | + * Returns the set of ports allocated for an intent. | ||
39 | + * | ||
40 | + * @param intentId the intent ID | ||
41 | + * @return set of allocated ports | ||
42 | + */ | ||
43 | + Set<Port> getAllocations(IntentId intentId); | ||
44 | + | ||
45 | + /** | ||
46 | + * Returns the intent allocated to a port. | ||
47 | + * | ||
48 | + * @param port the port | ||
49 | + * @return intent ID allocated to the port | ||
50 | + */ | ||
51 | + IntentId getAllocations(Port port); | ||
52 | + | ||
53 | + /** | ||
54 | + * Request a mapping between the given intents. | ||
55 | + * | ||
56 | + * @param keyIntentId the key intent ID | ||
57 | + * @param valIntentId the value intent ID | ||
58 | + * @return true if mapping was successful, false otherwise | ||
59 | + */ | ||
60 | + boolean requestMapping(IntentId keyIntentId, IntentId valIntentId); | ||
61 | + | ||
62 | + /** | ||
63 | + * Returns the intents mapped to a lower intent. | ||
64 | + * | ||
65 | + * @param intentId the intent ID | ||
66 | + * @return the set of intent IDs | ||
67 | + */ | ||
68 | + Set<IntentId> getMapping(IntentId intentId); | ||
69 | + | ||
70 | + void releaseMapping(IntentId keyIntentId, IntentId valIntentId); | ||
35 | 71 | ||
36 | /** | 72 | /** |
37 | * Release ports associated with given intent ID. | 73 | * Release ports associated with given intent ID. | ... | ... |
... | @@ -24,7 +24,60 @@ import java.util.Set; | ... | @@ -24,7 +24,60 @@ import java.util.Set; |
24 | public interface DeviceResourceStore { | 24 | public interface DeviceResourceStore { |
25 | Set<Port> getFreePorts(DeviceId deviceId); | 25 | Set<Port> getFreePorts(DeviceId deviceId); |
26 | 26 | ||
27 | - void allocatePorts(Set<Port> port, IntentId intent); | 27 | + /** |
28 | + * Allocates the given ports to the given intent. | ||
29 | + * @param ports set of ports to allocate | ||
30 | + * @param intentId intent ID | ||
31 | + * @return true if allocation was successful, false otherwise | ||
32 | + */ | ||
33 | + boolean allocatePorts(Set<Port> ports, IntentId intentId); | ||
28 | 34 | ||
29 | - void releasePorts(IntentId intent); | 35 | + /** |
36 | + * Returns set of ports allocated for an intent. | ||
37 | + * | ||
38 | + * @param intentId the intent ID | ||
39 | + * @return set of allocated ports | ||
40 | + */ | ||
41 | + Set<Port> getAllocations(IntentId intentId); | ||
42 | + | ||
43 | + /** | ||
44 | + * Returns intent allocated to a port. | ||
45 | + * | ||
46 | + * @param port the port | ||
47 | + * @return intent ID allocated to the port | ||
48 | + */ | ||
49 | + IntentId getAllocations(Port port); | ||
50 | + | ||
51 | + /** | ||
52 | + * Allocates the mapping between the given intents. | ||
53 | + * | ||
54 | + * @param keyIntentId key intent ID | ||
55 | + * @param valIntentId value intent ID | ||
56 | + * @return true if mapping was successful, false otherwise | ||
57 | + */ | ||
58 | + boolean allocateMapping(IntentId keyIntentId, IntentId valIntentId); | ||
59 | + | ||
60 | + /** | ||
61 | + * Returns the set of intents mapped to a lower intent. | ||
62 | + * | ||
63 | + * @param intentId intent ID | ||
64 | + * @return set of intent IDs | ||
65 | + */ | ||
66 | + Set<IntentId> getMapping(IntentId intentId); | ||
67 | + | ||
68 | + /** | ||
69 | + * Releases the mapping between the given intents. | ||
70 | + * | ||
71 | + * @param keyIntentId key intent ID | ||
72 | + * @param valIntentId value intent ID | ||
73 | + */ | ||
74 | + void releaseMapping(IntentId keyIntentId, IntentId valIntentId); | ||
75 | + | ||
76 | + /** | ||
77 | + * Releases the ports allocated to the given intent. | ||
78 | + * | ||
79 | + * @param intentId intent ID | ||
80 | + * @return true if release was successful, false otherwise | ||
81 | + */ | ||
82 | + boolean releasePorts(IntentId intentId); | ||
30 | } | 83 | } | ... | ... |
core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
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 | + */ | ||
16 | +package org.onosproject.net.intent.impl.compiler; | ||
17 | + | ||
18 | +import org.apache.commons.lang3.tuple.Pair; | ||
19 | +import org.apache.felix.scr.annotations.Activate; | ||
20 | +import org.apache.felix.scr.annotations.Component; | ||
21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
22 | +import org.apache.felix.scr.annotations.Reference; | ||
23 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
24 | +import org.onosproject.core.ApplicationId; | ||
25 | +import org.onosproject.core.CoreService; | ||
26 | +import org.onosproject.net.ConnectPoint; | ||
27 | +import org.onosproject.net.DeviceId; | ||
28 | +import org.onosproject.net.OchPort; | ||
29 | +import org.onosproject.net.OduCltPort; | ||
30 | +import org.onosproject.net.OduSignalType; | ||
31 | +import org.onosproject.net.Port; | ||
32 | +import org.onosproject.net.device.DeviceService; | ||
33 | +import org.onosproject.net.flow.DefaultFlowRule; | ||
34 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
35 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
36 | +import org.onosproject.net.flow.FlowRule; | ||
37 | +import org.onosproject.net.flow.TrafficSelector; | ||
38 | +import org.onosproject.net.flow.TrafficTreatment; | ||
39 | +import org.onosproject.net.intent.FlowRuleIntent; | ||
40 | +import org.onosproject.net.intent.Intent; | ||
41 | +import org.onosproject.net.intent.IntentCompiler; | ||
42 | +import org.onosproject.net.intent.IntentExtensionService; | ||
43 | +import org.onosproject.net.intent.IntentId; | ||
44 | +import org.onosproject.net.intent.IntentService; | ||
45 | +import org.onosproject.net.intent.OpticalCircuitIntent; | ||
46 | +import org.onosproject.net.intent.OpticalConnectivityIntent; | ||
47 | +import org.onosproject.net.intent.impl.IntentCompilationException; | ||
48 | +import org.onosproject.net.resource.device.DeviceResourceService; | ||
49 | +import org.onosproject.net.resource.link.LinkResourceAllocations; | ||
50 | +import org.slf4j.Logger; | ||
51 | +import org.slf4j.LoggerFactory; | ||
52 | + | ||
53 | +import java.util.Arrays; | ||
54 | +import java.util.Collections; | ||
55 | +import java.util.HashSet; | ||
56 | +import java.util.LinkedList; | ||
57 | +import java.util.List; | ||
58 | +import java.util.Set; | ||
59 | + | ||
60 | +import static com.google.common.base.Preconditions.checkArgument; | ||
61 | + | ||
62 | +/** | ||
63 | + * An intent compiler for {@link org.onosproject.net.intent.OpticalCircuitIntent}. | ||
64 | + */ | ||
65 | +@Component(immediate = true) | ||
66 | +public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircuitIntent> { | ||
67 | + | ||
68 | + private static final Logger log = LoggerFactory.getLogger(OpticalCircuitIntentCompiler.class); | ||
69 | + | ||
70 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
71 | + protected IntentExtensionService intentManager; | ||
72 | + | ||
73 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
74 | + protected CoreService coreService; | ||
75 | + | ||
76 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
77 | + protected DeviceService deviceService; | ||
78 | + | ||
79 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
80 | + protected DeviceResourceService deviceResourceService; | ||
81 | + | ||
82 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
83 | + protected IntentService intentService; | ||
84 | + | ||
85 | + private ApplicationId appId; | ||
86 | + | ||
87 | + @Activate | ||
88 | + public void activate() { | ||
89 | + appId = coreService.registerApplication("org.onosproject.net.intent"); | ||
90 | + intentManager.registerCompiler(OpticalCircuitIntent.class, this); | ||
91 | + } | ||
92 | + | ||
93 | + @Deactivate | ||
94 | + public void deactivate() { | ||
95 | + intentManager.unregisterCompiler(OpticalCircuitIntent.class); | ||
96 | + } | ||
97 | + | ||
98 | + @Override | ||
99 | + public List<Intent> compile(OpticalCircuitIntent intent, List<Intent> installable, | ||
100 | + Set<LinkResourceAllocations> resources) { | ||
101 | + // Check if ports are OduClt ports | ||
102 | + ConnectPoint src = intent.getSrc(); | ||
103 | + ConnectPoint dst = intent.getDst(); | ||
104 | + Port srcPort = deviceService.getPort(src.deviceId(), src.port()); | ||
105 | + Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); | ||
106 | + checkArgument(srcPort instanceof OduCltPort); | ||
107 | + checkArgument(dstPort instanceof OduCltPort); | ||
108 | + | ||
109 | + log.debug("Compiling optical circuit intent between {} and {}", src, dst); | ||
110 | + | ||
111 | + // Reserve OduClt ports | ||
112 | + if (!deviceResourceService.requestPorts(new HashSet(Arrays.asList(srcPort, dstPort)), intent)) { | ||
113 | + throw new IntentCompilationException("Unable to reserve ports for intent " + intent); | ||
114 | + } | ||
115 | + | ||
116 | + LinkedList<Intent> intents = new LinkedList<>(); | ||
117 | + | ||
118 | + FlowRuleIntent circuitIntent; | ||
119 | + OpticalConnectivityIntent connIntent = findOpticalConnectivityIntent(intent); | ||
120 | + | ||
121 | + // Create optical connectivity intent if needed | ||
122 | + if (connIntent == null) { | ||
123 | + // Find OCh ports with available resources | ||
124 | + Pair<OchPort, OchPort> ochPorts = findPorts(intent); | ||
125 | + | ||
126 | + if (ochPorts == null) { | ||
127 | + return Collections.emptyList(); | ||
128 | + } | ||
129 | + | ||
130 | + // Create optical connectivity intent | ||
131 | + ConnectPoint srcCP = new ConnectPoint(src.elementId(), ochPorts.getLeft().number()); | ||
132 | + ConnectPoint dstCP = new ConnectPoint(dst.elementId(), ochPorts.getRight().number()); | ||
133 | + // FIXME: hardcoded ODU signal type | ||
134 | + connIntent = OpticalConnectivityIntent.builder() | ||
135 | + .appId(appId) | ||
136 | + .src(srcCP) | ||
137 | + .dst(dstCP) | ||
138 | + .signalType(OduSignalType.ODU4) | ||
139 | + .build(); | ||
140 | + intents.add(connIntent); | ||
141 | + } | ||
142 | + | ||
143 | + // Create optical circuit intent | ||
144 | + circuitIntent = new FlowRuleIntent( | ||
145 | + appId, | ||
146 | + createRules(src, connIntent.getSrc(), dst, connIntent.getDst()), | ||
147 | + intent.resources()); | ||
148 | + | ||
149 | + // Save circuit to connectivity intent mapping | ||
150 | + deviceResourceService.requestMapping(connIntent.id(), circuitIntent.id()); | ||
151 | + intents.add(circuitIntent); | ||
152 | + | ||
153 | + return intents; | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * Checks if current allocations on given resource can satisfy request. | ||
158 | + * | ||
159 | + * @param request | ||
160 | + * @param resource | ||
161 | + * @return | ||
162 | + */ | ||
163 | + private boolean isAvailable(Intent request, IntentId resource) { | ||
164 | + Set<IntentId> mapping = deviceResourceService.getMapping(resource); | ||
165 | + | ||
166 | + // TODO: hardcoded 10 x 10G | ||
167 | + return mapping.size() < 10; | ||
168 | + } | ||
169 | + | ||
170 | + /** | ||
171 | + * Returns existing and available optical connectivity intent that matches the given circuit intent. | ||
172 | + * | ||
173 | + * @param circuitIntent optical circuit intent | ||
174 | + * @return existing optical connectivity intent, null otherwise. | ||
175 | + */ | ||
176 | + private OpticalConnectivityIntent findOpticalConnectivityIntent(OpticalCircuitIntent circuitIntent) { | ||
177 | + for (Intent intent : intentService.getIntents()) { | ||
178 | + if (!(intent instanceof OpticalConnectivityIntent)) { | ||
179 | + continue; | ||
180 | + } | ||
181 | + | ||
182 | + OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intent; | ||
183 | + | ||
184 | + ConnectPoint src = circuitIntent.getSrc(); | ||
185 | + ConnectPoint dst = circuitIntent.getDst(); | ||
186 | + if (!src.equals(connIntent.getSrc()) && !dst.equals(connIntent.getDst())) { | ||
187 | + continue; | ||
188 | + } | ||
189 | + | ||
190 | + if (isAvailable(circuitIntent, connIntent.id())) { | ||
191 | + return connIntent; | ||
192 | + } | ||
193 | + } | ||
194 | + | ||
195 | + return null; | ||
196 | + } | ||
197 | + | ||
198 | + private OchPort findAvailableOchPort(DeviceId deviceId, OpticalCircuitIntent circuitIntent) { | ||
199 | + List<Port> ports = deviceService.getPorts(deviceId); | ||
200 | + | ||
201 | + for (Port port : ports) { | ||
202 | + if (!(port instanceof OchPort)) { | ||
203 | + continue; | ||
204 | + } | ||
205 | + | ||
206 | + // Port is not used | ||
207 | + IntentId intentId = deviceResourceService.getAllocations(port); | ||
208 | + if (intentId == null) { | ||
209 | + return (OchPort) port; | ||
210 | + } | ||
211 | + | ||
212 | + // Port is used but has free resources | ||
213 | + if (isAvailable(circuitIntent, intentId)) { | ||
214 | + return (OchPort) port; | ||
215 | + } | ||
216 | + } | ||
217 | + | ||
218 | + return null; | ||
219 | + } | ||
220 | + | ||
221 | + // TODO: Add constraints for OduClt to OCh port mappings | ||
222 | + // E.g., ports need to belong to same line card. | ||
223 | + private Pair<OchPort, OchPort> findPorts(OpticalCircuitIntent intent) { | ||
224 | + | ||
225 | + OchPort srcPort = findAvailableOchPort(intent.getSrc().deviceId(), intent); | ||
226 | + if (srcPort == null) { | ||
227 | + return null; | ||
228 | + } | ||
229 | + | ||
230 | + OchPort dstPort = findAvailableOchPort(intent.getDst().deviceId(), intent); | ||
231 | + if (dstPort == null) { | ||
232 | + return null; | ||
233 | + } | ||
234 | + | ||
235 | + return Pair.of(srcPort, dstPort); | ||
236 | + } | ||
237 | + | ||
238 | + /** | ||
239 | + * Builds flow rules for mapping between ODU and OCh ports. | ||
240 | + * | ||
241 | + * @param srcOdu | ||
242 | + * @param dstOdu | ||
243 | + * @return | ||
244 | + */ | ||
245 | + private List<FlowRule> createRules(ConnectPoint srcOdu, ConnectPoint srcOch, | ||
246 | + ConnectPoint dstOdu, ConnectPoint dstOch) { | ||
247 | + TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | ||
248 | + TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); | ||
249 | + | ||
250 | + // Source flow rule | ||
251 | + selectorBuilder.matchInPort(srcOdu.port()); | ||
252 | + //selectorBuilder.add(Criteria.matchCltSignalType) | ||
253 | + treatmentBuilder.setOutput(srcOch.port()); | ||
254 | + //treatmentBuilder.add(Instructions.modL1OduSignalType) | ||
255 | + | ||
256 | + FlowRule srcRule = DefaultFlowRule.builder() | ||
257 | + .forDevice(srcOdu.deviceId()) | ||
258 | + .withSelector(selectorBuilder.build()) | ||
259 | + .withTreatment(treatmentBuilder.build()) | ||
260 | + .withPriority(100) | ||
261 | + .fromApp(appId) | ||
262 | + .makePermanent() | ||
263 | + .build(); | ||
264 | + | ||
265 | + // Destination flow rule | ||
266 | + selectorBuilder.matchInPort(dstOch.port()); | ||
267 | + //selectorBuilder.add(Criteria.matchOduSignalType) | ||
268 | + treatmentBuilder.setOutput(dstOdu.port()); | ||
269 | + //treatmentBuilder.add(Instructions.modL1CltSignalType) | ||
270 | + | ||
271 | + FlowRule dstRule = DefaultFlowRule.builder() | ||
272 | + .forDevice(dstOdu.deviceId()) | ||
273 | + .withSelector(selectorBuilder.build()) | ||
274 | + .withTreatment(treatmentBuilder.build()) | ||
275 | + .withPriority(100) | ||
276 | + .fromApp(appId) | ||
277 | + .makePermanent() | ||
278 | + .build(); | ||
279 | + | ||
280 | + return Arrays.<FlowRule>asList(srcRule, dstRule); | ||
281 | + } | ||
282 | +} |
... | @@ -15,7 +15,8 @@ | ... | @@ -15,7 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent.impl.compiler; | 16 | package org.onosproject.net.intent.impl.compiler; |
17 | 17 | ||
18 | -import java.util.Collections; | 18 | +import java.util.Arrays; |
19 | +import java.util.HashSet; | ||
19 | import java.util.List; | 20 | import java.util.List; |
20 | import java.util.Set; | 21 | import java.util.Set; |
21 | 22 | ||
... | @@ -41,6 +42,7 @@ import org.onosproject.net.intent.IntentCompiler; | ... | @@ -41,6 +42,7 @@ import org.onosproject.net.intent.IntentCompiler; |
41 | import org.onosproject.net.intent.IntentExtensionService; | 42 | import org.onosproject.net.intent.IntentExtensionService; |
42 | import org.onosproject.net.intent.OpticalConnectivityIntent; | 43 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
43 | import org.onosproject.net.intent.OpticalPathIntent; | 44 | import org.onosproject.net.intent.OpticalPathIntent; |
45 | +import org.onosproject.net.intent.impl.IntentCompilationException; | ||
44 | import org.onosproject.net.resource.link.DefaultLinkResourceRequest; | 46 | import org.onosproject.net.resource.link.DefaultLinkResourceRequest; |
45 | import org.onosproject.net.resource.device.DeviceResourceService; | 47 | import org.onosproject.net.resource.device.DeviceResourceService; |
46 | import org.onosproject.net.resource.link.LambdaResource; | 48 | import org.onosproject.net.resource.link.LambdaResource; |
... | @@ -56,6 +58,8 @@ import org.onosproject.net.topology.TopologyEdge; | ... | @@ -56,6 +58,8 @@ import org.onosproject.net.topology.TopologyEdge; |
56 | import org.onosproject.net.topology.TopologyService; | 58 | import org.onosproject.net.topology.TopologyService; |
57 | 59 | ||
58 | import com.google.common.collect.ImmutableList; | 60 | import com.google.common.collect.ImmutableList; |
61 | +import org.slf4j.Logger; | ||
62 | +import org.slf4j.LoggerFactory; | ||
59 | 63 | ||
60 | import static com.google.common.base.Preconditions.checkArgument; | 64 | import static com.google.common.base.Preconditions.checkArgument; |
61 | 65 | ||
... | @@ -65,6 +69,8 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -65,6 +69,8 @@ import static com.google.common.base.Preconditions.checkArgument; |
65 | @Component(immediate = true) | 69 | @Component(immediate = true) |
66 | public class OpticalConnectivityIntentCompiler implements IntentCompiler<OpticalConnectivityIntent> { | 70 | public class OpticalConnectivityIntentCompiler implements IntentCompiler<OpticalConnectivityIntent> { |
67 | 71 | ||
72 | + protected static final Logger log = LoggerFactory.getLogger(OpticalConnectivityIntentCompiler.class); | ||
73 | + | ||
68 | private static final GridType DEFAULT_OCH_GRIDTYPE = GridType.DWDM; | 74 | private static final GridType DEFAULT_OCH_GRIDTYPE = GridType.DWDM; |
69 | private static final ChannelSpacing DEFAULT_CHANNEL_SPACING = ChannelSpacing.CHL_50GHZ; | 75 | private static final ChannelSpacing DEFAULT_CHANNEL_SPACING = ChannelSpacing.CHL_50GHZ; |
70 | 76 | ||
... | @@ -105,6 +111,13 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -105,6 +111,13 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
105 | checkArgument(srcPort instanceof OchPort); | 111 | checkArgument(srcPort instanceof OchPort); |
106 | checkArgument(dstPort instanceof OchPort); | 112 | checkArgument(dstPort instanceof OchPort); |
107 | 113 | ||
114 | + log.debug("Compiling optical connectivity intent between {} and {}", src, dst); | ||
115 | + | ||
116 | + // Reserve OCh ports | ||
117 | + if (!deviceResourceService.requestPorts(new HashSet(Arrays.asList(srcPort, dstPort)), intent)) { | ||
118 | + throw new IntentCompilationException("Unable to reserve ports for intent " + intent); | ||
119 | + } | ||
120 | + | ||
108 | // Calculate available light paths | 121 | // Calculate available light paths |
109 | Set<Path> paths = getOpticalPaths(intent); | 122 | Set<Path> paths = getOpticalPaths(intent); |
110 | 123 | ||
... | @@ -118,13 +131,6 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -118,13 +131,6 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
118 | 131 | ||
119 | OmsPort omsPort = (OmsPort) deviceService.getPort(path.src().deviceId(), path.src().port()); | 132 | OmsPort omsPort = (OmsPort) deviceService.getPort(path.src().deviceId(), path.src().port()); |
120 | 133 | ||
121 | - // Try to reserve port resources, roll back if unsuccessful | ||
122 | - Set<Port> portAllocs = deviceResourceService.requestPorts(intent); | ||
123 | - if (portAllocs == null) { | ||
124 | - linkResourceService.releaseResources(linkAllocs); | ||
125 | - continue; | ||
126 | - } | ||
127 | - | ||
128 | // Create installable optical path intent | 134 | // Create installable optical path intent |
129 | LambdaResourceAllocation lambdaAlloc = getWavelength(path, linkAllocs); | 135 | LambdaResourceAllocation lambdaAlloc = getWavelength(path, linkAllocs); |
130 | OchSignal ochSignal = getOchSignal(lambdaAlloc, omsPort.minFrequency(), omsPort.grid()); | 136 | OchSignal ochSignal = getOchSignal(lambdaAlloc, omsPort.minFrequency(), omsPort.grid()); |
... | @@ -143,7 +149,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -143,7 +149,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
143 | return ImmutableList.of(newIntent); | 149 | return ImmutableList.of(newIntent); |
144 | } | 150 | } |
145 | 151 | ||
146 | - return Collections.emptyList(); | 152 | + // Release port allocations if unsuccessful |
153 | + deviceResourceService.releasePorts(intent.id()); | ||
154 | + | ||
155 | + throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent); | ||
147 | } | 156 | } |
148 | 157 | ||
149 | /** | 158 | /** | ... | ... |
... | @@ -39,6 +39,8 @@ import org.onosproject.net.intent.IntentExtensionService; | ... | @@ -39,6 +39,8 @@ import org.onosproject.net.intent.IntentExtensionService; |
39 | import org.onosproject.net.intent.OpticalPathIntent; | 39 | import org.onosproject.net.intent.OpticalPathIntent; |
40 | import org.onosproject.net.resource.link.LinkResourceAllocations; | 40 | import org.onosproject.net.resource.link.LinkResourceAllocations; |
41 | import org.onosproject.net.resource.link.LinkResourceService; | 41 | import org.onosproject.net.resource.link.LinkResourceService; |
42 | +import org.slf4j.Logger; | ||
43 | +import org.slf4j.LoggerFactory; | ||
42 | 44 | ||
43 | import java.util.Collections; | 45 | import java.util.Collections; |
44 | import java.util.LinkedList; | 46 | import java.util.LinkedList; |
... | @@ -48,6 +50,8 @@ import java.util.Set; | ... | @@ -48,6 +50,8 @@ import java.util.Set; |
48 | @Component(immediate = true) | 50 | @Component(immediate = true) |
49 | public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathIntent> { | 51 | public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathIntent> { |
50 | 52 | ||
53 | + private static final Logger log = LoggerFactory.getLogger(OpticalPathIntentCompiler.class); | ||
54 | + | ||
51 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
52 | protected IntentExtensionService intentManager; | 56 | protected IntentExtensionService intentManager; |
53 | 57 | ||
... | @@ -73,6 +77,8 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte | ... | @@ -73,6 +77,8 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte |
73 | @Override | 77 | @Override |
74 | public List<Intent> compile(OpticalPathIntent intent, List<Intent> installable, | 78 | public List<Intent> compile(OpticalPathIntent intent, List<Intent> installable, |
75 | Set<LinkResourceAllocations> resources) { | 79 | Set<LinkResourceAllocations> resources) { |
80 | + log.debug("Compiling optical path intent between {} and {}", intent.src(), intent.dst()); | ||
81 | + | ||
76 | return Collections.singletonList( | 82 | return Collections.singletonList( |
77 | new FlowRuleIntent(appId, createRules(intent), intent.resources())); | 83 | new FlowRuleIntent(appId, createRules(intent), intent.resources())); |
78 | } | 84 | } | ... | ... |
... | @@ -24,13 +24,10 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -24,13 +24,10 @@ import org.apache.felix.scr.annotations.Service; |
24 | import org.onosproject.net.Port; | 24 | import org.onosproject.net.Port; |
25 | import org.onosproject.net.intent.Intent; | 25 | import org.onosproject.net.intent.Intent; |
26 | import org.onosproject.net.intent.IntentId; | 26 | import org.onosproject.net.intent.IntentId; |
27 | -import org.onosproject.net.intent.OpticalConnectivityIntent; | ||
28 | import org.onosproject.net.resource.device.DeviceResourceService; | 27 | import org.onosproject.net.resource.device.DeviceResourceService; |
29 | import org.onosproject.net.resource.device.DeviceResourceStore; | 28 | import org.onosproject.net.resource.device.DeviceResourceStore; |
30 | import org.slf4j.Logger; | 29 | import org.slf4j.Logger; |
31 | 30 | ||
32 | -import java.util.Arrays; | ||
33 | -import java.util.HashSet; | ||
34 | import java.util.Set; | 31 | import java.util.Set; |
35 | 32 | ||
36 | import static com.google.common.base.Preconditions.checkNotNull; | 33 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -59,28 +56,35 @@ public class DeviceResourceManager implements DeviceResourceService { | ... | @@ -59,28 +56,35 @@ public class DeviceResourceManager implements DeviceResourceService { |
59 | } | 56 | } |
60 | 57 | ||
61 | @Override | 58 | @Override |
62 | - public Set<Port> requestPorts(Intent intent) { | 59 | + public boolean requestPorts(Set<Port> ports, Intent intent) { |
63 | checkNotNull(intent); | 60 | checkNotNull(intent); |
64 | - if (intent instanceof OpticalConnectivityIntent) { | ||
65 | - OpticalConnectivityIntent opticalIntent = (OpticalConnectivityIntent) intent; | ||
66 | - Set<Port> srcPorts = store.getFreePorts(opticalIntent.getSrc().deviceId()); | ||
67 | - Set<Port> dstPorts = store.getFreePorts(opticalIntent.getDst().deviceId()); | ||
68 | 61 | ||
69 | - Port srcPort = getTypedPort(srcPorts, Port.Type.OCH); | 62 | + return store.allocatePorts(ports, intent.id()); |
70 | - Port dstPort = getTypedPort(dstPorts, Port.Type.OCH); | 63 | + } |
71 | 64 | ||
72 | - if (srcPort == null || dstPort == null) { | 65 | + @Override |
73 | - return null; | 66 | + public Set<Port> getAllocations(IntentId intentId) { |
74 | - } | 67 | + return store.getAllocations(intentId); |
68 | + } | ||
75 | 69 | ||
76 | - Set<Port> allocPorts = new HashSet(Arrays.asList(srcPort, dstPort)); | 70 | + @Override |
71 | + public IntentId getAllocations(Port port) { | ||
72 | + return store.getAllocations(port); | ||
73 | + } | ||
77 | 74 | ||
78 | - store.allocatePorts(allocPorts, intent.id()); | 75 | + @Override |
76 | + public void releaseMapping(IntentId keyIntentId, IntentId valIntentId) { | ||
77 | + store.releaseMapping(keyIntentId, valIntentId); | ||
78 | + } | ||
79 | 79 | ||
80 | - return allocPorts; | 80 | + @Override |
81 | - } | 81 | + public boolean requestMapping(IntentId keyIntentId, IntentId valIntentId) { |
82 | + return store.allocateMapping(keyIntentId, valIntentId); | ||
83 | + } | ||
82 | 84 | ||
83 | - return null; | 85 | + @Override |
86 | + public Set<IntentId> getMapping(IntentId intentId) { | ||
87 | + return store.getMapping(intentId); | ||
84 | } | 88 | } |
85 | 89 | ||
86 | @Override | 90 | @Override | ... | ... |
core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentDeviceResourceStore.java
... | @@ -35,6 +35,7 @@ import org.onosproject.store.service.TransactionContext; | ... | @@ -35,6 +35,7 @@ import org.onosproject.store.service.TransactionContext; |
35 | import org.onosproject.store.service.TransactionalMap; | 35 | import org.onosproject.store.service.TransactionalMap; |
36 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
37 | 37 | ||
38 | +import java.util.Collections; | ||
38 | import java.util.HashSet; | 39 | import java.util.HashSet; |
39 | import java.util.Set; | 40 | import java.util.Set; |
40 | 41 | ||
... | @@ -52,12 +53,14 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { | ... | @@ -52,12 +53,14 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { |
52 | 53 | ||
53 | private static final String PORT_ALLOCATIONS = "PortAllocations"; | 54 | private static final String PORT_ALLOCATIONS = "PortAllocations"; |
54 | private static final String INTENT_ALLOCATIONS = "IntentAllocations"; | 55 | private static final String INTENT_ALLOCATIONS = "IntentAllocations"; |
56 | + private static final String INTENT_MAPPING = "IntentMapping"; | ||
55 | 57 | ||
56 | private static final Serializer SERIALIZER = Serializer.using( | 58 | private static final Serializer SERIALIZER = Serializer.using( |
57 | new KryoNamespace.Builder().register(KryoNamespaces.API).build()); | 59 | new KryoNamespace.Builder().register(KryoNamespaces.API).build()); |
58 | 60 | ||
59 | private ConsistentMap<Port, IntentId> portAllocMap; | 61 | private ConsistentMap<Port, IntentId> portAllocMap; |
60 | private ConsistentMap<IntentId, Set<Port>> intentAllocMap; | 62 | private ConsistentMap<IntentId, Set<Port>> intentAllocMap; |
63 | + private ConsistentMap<IntentId, Set<IntentId>> intentMapping; | ||
61 | 64 | ||
62 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 65 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
63 | protected StorageService storageService; | 66 | protected StorageService storageService; |
... | @@ -75,6 +78,10 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { | ... | @@ -75,6 +78,10 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { |
75 | .withName(INTENT_ALLOCATIONS) | 78 | .withName(INTENT_ALLOCATIONS) |
76 | .withSerializer(SERIALIZER) | 79 | .withSerializer(SERIALIZER) |
77 | .build(); | 80 | .build(); |
81 | + intentMapping = storageService.<IntentId, Set<IntentId>>consistentMapBuilder() | ||
82 | + .withName(INTENT_MAPPING) | ||
83 | + .withSerializer(SERIALIZER) | ||
84 | + .build(); | ||
78 | log.info("Started"); | 85 | log.info("Started"); |
79 | } | 86 | } |
80 | 87 | ||
... | @@ -110,7 +117,7 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { | ... | @@ -110,7 +117,7 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { |
110 | } | 117 | } |
111 | 118 | ||
112 | @Override | 119 | @Override |
113 | - public void allocatePorts(Set<Port> ports, IntentId intentId) { | 120 | + public boolean allocatePorts(Set<Port> ports, IntentId intentId) { |
114 | checkNotNull(ports); | 121 | checkNotNull(ports); |
115 | checkArgument(ports.size() > 0); | 122 | checkArgument(ports.size() > 0); |
116 | checkNotNull(intentId); | 123 | checkNotNull(intentId); |
... | @@ -120,20 +127,78 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { | ... | @@ -120,20 +127,78 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { |
120 | try { | 127 | try { |
121 | TransactionalMap<Port, IntentId> portAllocs = getPortAllocs(tx); | 128 | TransactionalMap<Port, IntentId> portAllocs = getPortAllocs(tx); |
122 | for (Port port : ports) { | 129 | for (Port port : ports) { |
123 | - portAllocs.put(port, intentId); | 130 | + if (portAllocs.putIfAbsent(port, intentId) != null) { |
131 | + throw new Exception("Port already allocated " + port.toString()); | ||
132 | + } | ||
124 | } | 133 | } |
134 | + | ||
125 | TransactionalMap<IntentId, Set<Port>> intentAllocs = getIntentAllocs(tx); | 135 | TransactionalMap<IntentId, Set<Port>> intentAllocs = getIntentAllocs(tx); |
126 | intentAllocs.put(intentId, ports); | 136 | intentAllocs.put(intentId, ports); |
127 | tx.commit(); | 137 | tx.commit(); |
128 | } catch (Exception e) { | 138 | } catch (Exception e) { |
129 | log.error("Exception thrown, rolling back", e); | 139 | log.error("Exception thrown, rolling back", e); |
130 | tx.abort(); | 140 | tx.abort(); |
131 | - throw e; | 141 | + return false; |
142 | + } | ||
143 | + | ||
144 | + return true; | ||
145 | + } | ||
146 | + | ||
147 | + @Override | ||
148 | + public Set<Port> getAllocations(IntentId intentId) { | ||
149 | + if (!intentAllocMap.containsKey(intentId)) { | ||
150 | + Collections.emptySet(); | ||
151 | + } | ||
152 | + | ||
153 | + return intentAllocMap.get(intentId).value(); | ||
154 | + } | ||
155 | + | ||
156 | + @Override | ||
157 | + public IntentId getAllocations(Port port) { | ||
158 | + if (!portAllocMap.containsKey(port)) { | ||
159 | + return null; | ||
160 | + } | ||
161 | + | ||
162 | + return portAllocMap.get(port).value(); | ||
163 | + } | ||
164 | + | ||
165 | + @Override | ||
166 | + public Set<IntentId> getMapping(IntentId intentId) { | ||
167 | + return intentMapping.get(intentId).value(); | ||
168 | + } | ||
169 | + | ||
170 | + @Override | ||
171 | + public void releaseMapping(IntentId keyIntentId, IntentId valIntentId) { | ||
172 | + if (!intentMapping.containsKey(keyIntentId)) { | ||
173 | + return; | ||
174 | + } | ||
175 | + | ||
176 | + Set<IntentId> intents = intentMapping.get(keyIntentId).value(); | ||
177 | + | ||
178 | + try { | ||
179 | + intents.remove(valIntentId); | ||
180 | + } catch (Exception e) { | ||
181 | + log.error("Trying to remove non-existing mapping {} {}", keyIntentId, valIntentId); | ||
132 | } | 182 | } |
133 | } | 183 | } |
134 | 184 | ||
135 | @Override | 185 | @Override |
136 | - public void releasePorts(IntentId intentId) { | 186 | + public boolean allocateMapping(IntentId keyIntentId, IntentId valIntentId) { |
187 | + Set<IntentId> intents = intentMapping.get(keyIntentId).value(); | ||
188 | + | ||
189 | + if (intents == null) { | ||
190 | + intents = Collections.singleton(valIntentId); | ||
191 | + } else { | ||
192 | + intents.add(valIntentId); | ||
193 | + } | ||
194 | + | ||
195 | + intentMapping.put(keyIntentId, intents); | ||
196 | + | ||
197 | + return true; | ||
198 | + } | ||
199 | + | ||
200 | + @Override | ||
201 | + public boolean releasePorts(IntentId intentId) { | ||
137 | checkNotNull(intentId); | 202 | checkNotNull(intentId); |
138 | 203 | ||
139 | TransactionContext tx = getTxContext(); | 204 | TransactionContext tx = getTxContext(); |
... | @@ -150,7 +215,9 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { | ... | @@ -150,7 +215,9 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { |
150 | } catch (Exception e) { | 215 | } catch (Exception e) { |
151 | log.error("Exception thrown, rolling back", e); | 216 | log.error("Exception thrown, rolling back", e); |
152 | tx.abort(); | 217 | tx.abort(); |
153 | - throw e; | 218 | + return false; |
154 | } | 219 | } |
220 | + | ||
221 | + return true; | ||
155 | } | 222 | } |
156 | } | 223 | } | ... | ... |
... | @@ -136,6 +136,7 @@ import org.onosproject.net.intent.LinkCollectionIntent; | ... | @@ -136,6 +136,7 @@ import org.onosproject.net.intent.LinkCollectionIntent; |
136 | import org.onosproject.net.intent.MplsIntent; | 136 | import org.onosproject.net.intent.MplsIntent; |
137 | import org.onosproject.net.intent.MplsPathIntent; | 137 | import org.onosproject.net.intent.MplsPathIntent; |
138 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; | 138 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
139 | +import org.onosproject.net.intent.OpticalCircuitIntent; | ||
139 | import org.onosproject.net.intent.OpticalConnectivityIntent; | 140 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
140 | import org.onosproject.net.intent.OpticalPathIntent; | 141 | import org.onosproject.net.intent.OpticalPathIntent; |
141 | import org.onosproject.net.intent.PathIntent; | 142 | import org.onosproject.net.intent.PathIntent; |
... | @@ -361,6 +362,7 @@ public final class KryoNamespaces { | ... | @@ -361,6 +362,7 @@ public final class KryoNamespaces { |
361 | LinkCollectionIntent.class, | 362 | LinkCollectionIntent.class, |
362 | OpticalConnectivityIntent.class, | 363 | OpticalConnectivityIntent.class, |
363 | OpticalPathIntent.class, | 364 | OpticalPathIntent.class, |
365 | + OpticalCircuitIntent.class, | ||
364 | LinkResourceRequest.class, | 366 | LinkResourceRequest.class, |
365 | DefaultLinkResourceRequest.class, | 367 | DefaultLinkResourceRequest.class, |
366 | BandwidthResourceRequest.class, | 368 | BandwidthResourceRequest.class, | ... | ... |
-
Please register or login to post a comment