blob: 3890bb4a492ca2168389e73af7dfdaa56e5a2a19 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.optical;
weibitf32383b2014-10-22 10:17:31 -070017
Sho SHIMIZUc87db552015-10-28 15:36:59 -070018import com.google.common.collect.ImmutableList;
weibitf32383b2014-10-22 10:17:31 -070019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
Marc De Leenheer16f857b2015-05-05 20:50:24 -070021import org.apache.felix.scr.annotations.Deactivate;
weibitf32383b2014-10-22 10:17:31 -070022import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
Marc De Leenheer8b3e80b2015-03-06 14:27:03 -080024import org.onosproject.cluster.ClusterService;
25import org.onosproject.cluster.NodeId;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import org.onosproject.core.ApplicationId;
27import org.onosproject.core.CoreService;
Marc De Leenheer8b3e80b2015-03-06 14:27:03 -080028import org.onosproject.mastership.MastershipService;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.ConnectPoint;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070030import org.onosproject.net.Device;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import org.onosproject.net.Host;
32import org.onosproject.net.Link;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070033import org.onosproject.net.OchPort;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070034import org.onosproject.net.OduCltPort;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070035import org.onosproject.net.OduSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080036import org.onosproject.net.Path;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070037import org.onosproject.net.Port;
38import org.onosproject.net.device.DeviceService;
Brian O'Connorabafb502014-12-02 22:26:20 -080039import org.onosproject.net.host.HostService;
40import org.onosproject.net.intent.HostToHostIntent;
41import org.onosproject.net.intent.Intent;
42import org.onosproject.net.intent.IntentEvent;
43import org.onosproject.net.intent.IntentListener;
Brian O'Connorabafb502014-12-02 22:26:20 -080044import org.onosproject.net.intent.IntentService;
45import org.onosproject.net.intent.IntentState;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070046import org.onosproject.net.intent.OpticalCircuitIntent;
Brian O'Connorabafb502014-12-02 22:26:20 -080047import org.onosproject.net.intent.OpticalConnectivityIntent;
48import org.onosproject.net.intent.PointToPointIntent;
Sho SHIMIZUc87db552015-10-28 15:36:59 -070049import org.onosproject.net.newresource.ResourceAllocation;
Sho SHIMIZU5c16df82015-09-29 12:52:07 -070050import org.onosproject.net.newresource.ResourceService;
Sho SHIMIZU7d20af12015-10-01 16:03:51 -070051import org.onosproject.net.resource.device.IntentSetMultimap;
Brian O'Connorabafb502014-12-02 22:26:20 -080052import org.onosproject.net.topology.LinkWeight;
53import org.onosproject.net.topology.PathService;
54import org.onosproject.net.topology.TopologyEdge;
weibitf32383b2014-10-22 10:17:31 -070055import org.slf4j.Logger;
56import org.slf4j.LoggerFactory;
57
Sho SHIMIZUc87db552015-10-28 15:36:59 -070058import java.util.Collection;
Marc De Leenheer16f857b2015-05-05 20:50:24 -070059import java.util.Collections;
Brian O'Connor772852a2014-11-17 15:51:19 -080060import java.util.Iterator;
Marc De Leenheer16f857b2015-05-05 20:50:24 -070061import java.util.LinkedList;
Brian O'Connor772852a2014-11-17 15:51:19 -080062import java.util.List;
63import java.util.Set;
Brian O'Connorc7bdd8c2014-12-08 01:29:53 -080064
Marc De Leenheer16f857b2015-05-05 20:50:24 -070065import static com.google.common.base.Preconditions.checkArgument;
Marc De Leenheer16f857b2015-05-05 20:50:24 -070066import static com.google.common.base.Preconditions.checkNotNull;
67
weibitf32383b2014-10-22 10:17:31 -070068/**
Marc De Leenheer16f857b2015-05-05 20:50:24 -070069 * OpticalPathProvisioner listens for event notifications from the Intent F/W.
weibitf32383b2014-10-22 10:17:31 -070070 * It generates one or more opticalConnectivityIntent(s) and submits (or withdraws) to Intent F/W
71 * for adding/releasing capacity at the packet layer.
weibitf32383b2014-10-22 10:17:31 -070072 */
73
74@Component(immediate = true)
75public class OpticalPathProvisioner {
76
77 protected static final Logger log = LoggerFactory
78 .getLogger(OpticalPathProvisioner.class);
79
80 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
81 private IntentService intentService;
82
83 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Brian O'Connor772852a2014-11-17 15:51:19 -080084 protected PathService pathService;
weibitf32383b2014-10-22 10:17:31 -070085
86 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
87 protected CoreService coreService;
88
weibit7e583462014-10-23 10:14:05 -070089 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Praseed Balakrishnanc0029652014-11-14 13:38:49 -080090 protected HostService hostService;
91
Marc De Leenheer8b3e80b2015-03-06 14:27:03 -080092 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
93 protected MastershipService mastershipService;
94
95 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
96 protected ClusterService clusterService;
97
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070098 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070099 protected DeviceService deviceService;
100
101 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sho SHIMIZU7d20af12015-10-01 16:03:51 -0700102 protected IntentSetMultimap intentSetMultimap;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700103
104 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sho SHIMIZU5c16df82015-09-29 12:52:07 -0700105 protected ResourceService resourceService;
106
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700107 private ApplicationId appId;
Brian O'Connorc7bdd8c2014-12-08 01:29:53 -0800108
weibitf32383b2014-10-22 10:17:31 -0700109 private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner();
110
111 @Activate
112 protected void activate() {
113 intentService.addListener(pathProvisioner);
Brian O'Connorabafb502014-12-02 22:26:20 -0800114 appId = coreService.registerApplication("org.onosproject.optical");
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700115 initOpticalPorts();
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700116 log.info("Started");
117 }
118
119 @Deactivate
120 protected void deactivate() {
121 intentService.removeListener(pathProvisioner);
122 log.info("Stopped");
weibitf32383b2014-10-22 10:17:31 -0700123 }
124
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700125 /**
126 * Initialize availability of optical ports.
127 */
128 private void initOpticalPorts() {
129 // TODO: check for existing optical intents
130 return;
Brian O'Connorc7bdd8c2014-12-08 01:29:53 -0800131 }
132
weibitf32383b2014-10-22 10:17:31 -0700133 public class InternalOpticalPathProvisioner implements IntentListener {
134 @Override
135 public void event(IntentEvent event) {
136 switch (event.type()) {
Brian O'Connor7a71d5d2014-12-02 00:12:27 -0800137 case INSTALL_REQ:
weibitf32383b2014-10-22 10:17:31 -0700138 break;
139 case INSTALLED:
140 break;
141 case FAILED:
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700142 log.info("Intent {} failed, calling optical path provisioning app.", event.subject());
Brian O'Connor772852a2014-11-17 15:51:19 -0800143 setupLightpath(event.subject());
weibitf32383b2014-10-22 10:17:31 -0700144 break;
145 case WITHDRAWN:
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700146 log.info("Intent {} withdrawn.", event.subject());
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700147 releaseResources(event.subject());
weibitf32383b2014-10-22 10:17:31 -0700148 break;
149 default:
150 break;
151 }
152 }
153
Brian O'Connor772852a2014-11-17 15:51:19 -0800154 private void setupLightpath(Intent intent) {
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700155 checkNotNull(intent);
156
Brian O'Connorc7bdd8c2014-12-08 01:29:53 -0800157 // TODO change the coordination approach between packet intents and optical intents
158 // Low speed LLDP may cause multiple calls which are not expected
159
Sho SHIMIZU0a9c9c42015-07-01 15:29:16 -0700160 if (intentService.getIntentState(intent.key()) != IntentState.FAILED) {
Marc De Leenheer8b3e80b2015-03-06 14:27:03 -0800161 return;
Marc De Leenheerb473b9d2015-02-06 15:21:03 -0800162 }
Brian O'Connorc7bdd8c2014-12-08 01:29:53 -0800163
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700164 // Get source and destination based on intent type
165 ConnectPoint src;
166 ConnectPoint dst;
Brian O'Connor772852a2014-11-17 15:51:19 -0800167 if (intent instanceof HostToHostIntent) {
168 HostToHostIntent hostToHostIntent = (HostToHostIntent) intent;
Marc De Leenheer8b3e80b2015-03-06 14:27:03 -0800169
Brian O'Connor772852a2014-11-17 15:51:19 -0800170 Host one = hostService.getHost(hostToHostIntent.one());
171 Host two = hostService.getHost(hostToHostIntent.two());
Marc De Leenheer8b3e80b2015-03-06 14:27:03 -0800172
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700173 checkNotNull(one);
174 checkNotNull(two);
Marc De Leenheer8b3e80b2015-03-06 14:27:03 -0800175
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700176 src = one.location();
177 dst = two.location();
Brian O'Connor772852a2014-11-17 15:51:19 -0800178 } else if (intent instanceof PointToPointIntent) {
179 PointToPointIntent p2pIntent = (PointToPointIntent) intent;
Marc De Leenheer8b3e80b2015-03-06 14:27:03 -0800180
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700181 src = p2pIntent.ingressPoint();
182 dst = p2pIntent.egressPoint();
Brian O'Connor772852a2014-11-17 15:51:19 -0800183 } else {
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700184 return;
Brian O'Connor772852a2014-11-17 15:51:19 -0800185 }
Praseed Balakrishnanc0029652014-11-14 13:38:49 -0800186
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700187 if (src == null || dst == null) {
188 return;
189 }
190
191 // Ignore if we're not the master for the intent's origin device
192 NodeId localNode = clusterService.getLocalNode().id();
193 NodeId sourceMaster = mastershipService.getMasterFor(src.deviceId());
194 if (!localNode.equals(sourceMaster)) {
195 return;
196 }
197
198 // Generate optical connectivity intents
Sho SHIMIZUfb446fe2015-05-21 14:45:23 -0700199 List<Intent> intents = getOpticalIntents(src, dst);
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700200
201 // Submit the intents
Brian O'Connor772852a2014-11-17 15:51:19 -0800202 for (Intent i : intents) {
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700203 intentService.submit(i);
Sho SHIMIZUb5d38412015-05-21 11:12:58 -0700204 log.debug("Submitted an intent: {}", i);
Brian O'Connor772852a2014-11-17 15:51:19 -0800205 }
weibit7e583462014-10-23 10:14:05 -0700206 }
207
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700208 /**
209 * Returns list of cross connection points of missing optical path sections.
210 *
211 * Scans the given multi-layer path and looks for sections that use cross connect links.
212 * The ingress and egress points in the optical layer are returned in a list.
213 *
214 * @param path the multi-layer path
215 * @return list of cross connection points on the optical layer
216 */
217 private List<ConnectPoint> getCrossConnectPoints(Path path) {
218 boolean scanning = false;
Sho SHIMIZU819ee292015-07-01 09:36:21 -0700219 List<ConnectPoint> connectPoints = new LinkedList<>();
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700220
221 for (Link link : path.links()) {
222 if (!isCrossConnectLink(link)) {
223 continue;
224 }
225
226 if (scanning) {
227 connectPoints.add(checkNotNull(link.src()));
228 scanning = false;
229 } else {
230 connectPoints.add(checkNotNull(link.dst()));
231 scanning = true;
232 }
233 }
234
235 return connectPoints;
236 }
237
238 /**
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700239 * Checks if cross connect points are of same type.
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700240 *
241 * @param crossConnectPoints list of cross connection points
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700242 * @return true if cross connect point pairs are of same type, false otherwise
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700243 */
244 private boolean checkCrossConnectPoints(List<ConnectPoint> crossConnectPoints) {
245 checkArgument(crossConnectPoints.size() % 2 == 0);
246
247 Iterator<ConnectPoint> itr = crossConnectPoints.iterator();
248
249 while (itr.hasNext()) {
250 // checkArgument at start ensures we'll always have pairs of connect points
251 ConnectPoint src = itr.next();
252 ConnectPoint dst = itr.next();
253
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700254 Device.Type srcType = deviceService.getDevice(src.deviceId()).type();
255 Device.Type dstType = deviceService.getDevice(dst.deviceId()).type();
256
257 // Only support connections between identical port types
258 if (srcType != dstType) {
259 log.warn("Unsupported mix of cross connect points");
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700260 return false;
261 }
262 }
263
264 return true;
265 }
266
267 /**
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700268 * Scans the list of cross connection points and returns a list of optical connectivity intents.
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700269 *
270 * @param crossConnectPoints list of cross connection points
271 * @return list of optical connectivity intents
272 */
273 private List<Intent> getIntents(List<ConnectPoint> crossConnectPoints) {
274 checkArgument(crossConnectPoints.size() % 2 == 0);
275
Sho SHIMIZU79945e82015-05-20 17:20:47 -0700276 List<Intent> intents = new LinkedList<>();
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700277 Iterator<ConnectPoint> itr = crossConnectPoints.iterator();
278
279 while (itr.hasNext()) {
280 // checkArgument at start ensures we'll always have pairs of connect points
281 ConnectPoint src = itr.next();
282 ConnectPoint dst = itr.next();
283
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700284 Port srcPort = deviceService.getPort(src.deviceId(), src.port());
285 Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700286
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700287 if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700288 // Create OTN circuit
289 Intent circuitIntent = OpticalCircuitIntent.builder()
290 .appId(appId)
291 .src(src)
292 .dst(dst)
293 .signalType(OduCltPort.SignalType.CLT_10GBE)
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700294 .bidirectional(true)
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700295 .build();
296 intents.add(circuitIntent);
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700297 } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
298 // Create lightpath
299 // FIXME: hardcoded ODU signal type
300 Intent opticalIntent = OpticalConnectivityIntent.builder()
301 .appId(appId)
302 .src(src)
303 .dst(dst)
304 .signalType(OduSignalType.ODU4)
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700305 .bidirectional(true)
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700306 .build();
307 intents.add(opticalIntent);
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700308 } else {
309 log.warn("Unsupported cross connect point types {} {}", srcPort.type(), dstPort.type());
310 return Collections.emptyList();
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700311 }
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700312 }
313
314 return intents;
315 }
316
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700317 /**
318 * Returns list of optical connectivity intents needed to create connectivity
319 * between ingress and egress.
320 *
321 * @param ingress the ingress connect point
322 * @param egress the egress connect point
323 * @return list of optical connectivity intents, empty list if no path was found
324 */
325 private List<Intent> getOpticalIntents(ConnectPoint ingress, ConnectPoint egress) {
Brian O'Connor772852a2014-11-17 15:51:19 -0800326 Set<Path> paths = pathService.getPaths(ingress.deviceId(),
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700327 egress.deviceId(),
328 new OpticalLinkWeight());
Brian O'Connor772852a2014-11-17 15:51:19 -0800329
330 if (paths.isEmpty()) {
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700331 return Collections.emptyList();
weibit7e583462014-10-23 10:14:05 -0700332 }
Brian O'Connor772852a2014-11-17 15:51:19 -0800333
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700334 // Search path with available cross connect points
335 for (Path path : paths) {
336 List<ConnectPoint> crossConnectPoints = getCrossConnectPoints(path);
Brian O'Connor772852a2014-11-17 15:51:19 -0800337
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700338 // Skip to next path if cross connect points are mismatched
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700339 if (!checkCrossConnectPoints(crossConnectPoints)) {
340 continue;
Brian O'Connor772852a2014-11-17 15:51:19 -0800341 }
342
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700343 return getIntents(crossConnectPoints);
Brian O'Connor772852a2014-11-17 15:51:19 -0800344 }
Brian O'Connorc7bdd8c2014-12-08 01:29:53 -0800345
Marc De Leenheer234fa822015-11-18 18:24:57 -0800346 log.warn("Unable to find multi-layer path.");
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700347 return Collections.emptyList();
Brian O'Connor772852a2014-11-17 15:51:19 -0800348 }
349
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700350 /**
351 * Link weight function that emphasizes re-use of packet links.
352 */
353 private class OpticalLinkWeight implements LinkWeight {
354 @Override
355 public double weight(TopologyEdge edge) {
356 // Ignore inactive links
357 if (edge.link().state() == Link.State.INACTIVE) {
358 return -1;
359 }
Brian O'Connorc7bdd8c2014-12-08 01:29:53 -0800360
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700361 // TODO: Ignore cross connect links with used ports
362
363 // Transport links have highest weight
364 if (edge.link().type() == Link.Type.OPTICAL) {
365 return 1000;
366 }
367
368 // Packet links
369 return 1;
Brian O'Connorc7bdd8c2014-12-08 01:29:53 -0800370 }
weibitf32383b2014-10-22 10:17:31 -0700371 }
Brian O'Connorc7bdd8c2014-12-08 01:29:53 -0800372
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700373 /**
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700374 * Release resources associated to the given intent.
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700375 *
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700376 * @param intent the intent
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700377 */
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700378 private void releaseResources(Intent intent) {
Sho SHIMIZUc87db552015-10-28 15:36:59 -0700379 Collection<ResourceAllocation> allocations = resourceService.getResourceAllocations(intent.id());
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700380 if (intent instanceof OpticalConnectivityIntent) {
Sho SHIMIZU5c16df82015-09-29 12:52:07 -0700381 resourceService.release(intent.id());
Sho SHIMIZUc87db552015-10-28 15:36:59 -0700382 if (!allocations.isEmpty()) {
383 resourceService.release(ImmutableList.copyOf(allocations));
Marc De Leenheerc9733082015-06-04 12:22:38 -0700384 }
385 } else if (intent instanceof OpticalCircuitIntent) {
Sho SHIMIZU5c16df82015-09-29 12:52:07 -0700386 resourceService.release(intent.id());
Sho SHIMIZU7d20af12015-10-01 16:03:51 -0700387 intentSetMultimap.releaseMapping(intent.id());
Sho SHIMIZUc87db552015-10-28 15:36:59 -0700388 if (!allocations.isEmpty()) {
389 resourceService.release(ImmutableList.copyOf(allocations));
Ayaka Koshibebcb02372015-06-01 10:56:42 -0700390 }
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700391 }
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700392 }
Brian O'Connor772852a2014-11-17 15:51:19 -0800393 }
weibitf32383b2014-10-22 10:17:31 -0700394
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700395 /**
Marc De Leenheer234fa822015-11-18 18:24:57 -0800396 * Verifies if given device type is in packet layer, i.e., ROADM, OTN or ROADM_OTN device.
397 *
398 * @param type device type
399 * @return true if in packet layer, false otherwise
400 */
401 private boolean isPacketLayer(Device.Type type) {
402 return type == Device.Type.SWITCH || type == Device.Type.ROUTER;
403 }
404
405 /**
406 * Verifies if given device type is in packet layer, i.e., switch or router device.
407 *
408 * @param type device type
409 * @return true if in packet layer, false otherwise
410 */
411 private boolean isTransportLayer(Device.Type type) {
412 return type == Device.Type.ROADM || type == Device.Type.OTN || type == Device.Type.ROADM_OTN;
413 }
414
415 /**
416 * Verifies if given link forms a cross-connection between packet and optical layer.
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700417 *
418 * @param link the link
Marc De Leenheer234fa822015-11-18 18:24:57 -0800419 * @return true if the link is a cross-connect link, false otherwise
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700420 */
Marc De Leenheer234fa822015-11-18 18:24:57 -0800421 private boolean isCrossConnectLink(Link link) {
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700422 if (link.type() != Link.Type.OPTICAL) {
423 return false;
Praseed Balakrishnanc0029652014-11-14 13:38:49 -0800424 }
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700425
Marc De Leenheer234fa822015-11-18 18:24:57 -0800426 Device.Type src = deviceService.getDevice(link.src().deviceId()).type();
427 Device.Type dst = deviceService.getDevice(link.dst().deviceId()).type();
Marc De Leenheer16f857b2015-05-05 20:50:24 -0700428
Marc De Leenheer234fa822015-11-18 18:24:57 -0800429 return src != dst &&
430 ((isPacketLayer(src) && isTransportLayer(dst)) || (isPacketLayer(dst) && isTransportLayer(src)));
Brian O'Connor772852a2014-11-17 15:51:19 -0800431 }
Praseed Balakrishnanc0029652014-11-14 13:38:49 -0800432
weibitf32383b2014-10-22 10:17:31 -0700433}