Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.optical; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 17 | |
Sho SHIMIZU | c87db55 | 2015-10-28 15:36:59 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Deactivate; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 24 | import org.onosproject.cluster.ClusterService; |
| 25 | import org.onosproject.cluster.NodeId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import org.onosproject.core.ApplicationId; |
| 27 | import org.onosproject.core.CoreService; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 28 | import org.onosproject.mastership.MastershipService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 29 | import org.onosproject.net.ConnectPoint; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 30 | import org.onosproject.net.Device; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.net.Host; |
| 32 | import org.onosproject.net.Link; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 33 | import org.onosproject.net.OchPort; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 34 | import org.onosproject.net.OduCltPort; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 35 | import org.onosproject.net.OduSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 36 | import org.onosproject.net.Path; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 37 | import org.onosproject.net.Port; |
| 38 | import org.onosproject.net.device.DeviceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 39 | import org.onosproject.net.host.HostService; |
| 40 | import org.onosproject.net.intent.HostToHostIntent; |
| 41 | import org.onosproject.net.intent.Intent; |
| 42 | import org.onosproject.net.intent.IntentEvent; |
| 43 | import org.onosproject.net.intent.IntentListener; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 44 | import org.onosproject.net.intent.IntentService; |
| 45 | import org.onosproject.net.intent.IntentState; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 46 | import org.onosproject.net.intent.OpticalCircuitIntent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 47 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 48 | import org.onosproject.net.intent.PointToPointIntent; |
Sho SHIMIZU | c87db55 | 2015-10-28 15:36:59 -0700 | [diff] [blame] | 49 | import org.onosproject.net.newresource.ResourceAllocation; |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 50 | import org.onosproject.net.newresource.ResourceService; |
Sho SHIMIZU | 7d20af1 | 2015-10-01 16:03:51 -0700 | [diff] [blame] | 51 | import org.onosproject.net.resource.device.IntentSetMultimap; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 52 | import org.onosproject.net.topology.LinkWeight; |
| 53 | import org.onosproject.net.topology.PathService; |
| 54 | import org.onosproject.net.topology.TopologyEdge; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 55 | import org.slf4j.Logger; |
| 56 | import org.slf4j.LoggerFactory; |
| 57 | |
Sho SHIMIZU | c87db55 | 2015-10-28 15:36:59 -0700 | [diff] [blame] | 58 | import java.util.Collection; |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 59 | import java.util.Collections; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 60 | import java.util.Iterator; |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 61 | import java.util.LinkedList; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 62 | import java.util.List; |
| 63 | import java.util.Set; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 64 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 65 | import static com.google.common.base.Preconditions.checkArgument; |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 66 | import static com.google.common.base.Preconditions.checkNotNull; |
| 67 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 68 | /** |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 69 | * OpticalPathProvisioner listens for event notifications from the Intent F/W. |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 70 | * It generates one or more opticalConnectivityIntent(s) and submits (or withdraws) to Intent F/W |
| 71 | * for adding/releasing capacity at the packet layer. |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 72 | */ |
| 73 | |
| 74 | @Component(immediate = true) |
| 75 | public 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'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 84 | protected PathService pathService; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 85 | |
| 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 87 | protected CoreService coreService; |
| 88 | |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 89 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 90 | protected HostService hostService; |
| 91 | |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 93 | protected MastershipService mastershipService; |
| 94 | |
| 95 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 96 | protected ClusterService clusterService; |
| 97 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 98 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 99 | protected DeviceService deviceService; |
| 100 | |
| 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | 7d20af1 | 2015-10-01 16:03:51 -0700 | [diff] [blame] | 102 | protected IntentSetMultimap intentSetMultimap; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 103 | |
| 104 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 105 | protected ResourceService resourceService; |
| 106 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 107 | private ApplicationId appId; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 108 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 109 | private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner(); |
| 110 | |
| 111 | @Activate |
| 112 | protected void activate() { |
| 113 | intentService.addListener(pathProvisioner); |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 114 | appId = coreService.registerApplication("org.onosproject.optical"); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 115 | initOpticalPorts(); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 116 | log.info("Started"); |
| 117 | } |
| 118 | |
| 119 | @Deactivate |
| 120 | protected void deactivate() { |
| 121 | intentService.removeListener(pathProvisioner); |
| 122 | log.info("Stopped"); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 125 | /** |
| 126 | * Initialize availability of optical ports. |
| 127 | */ |
| 128 | private void initOpticalPorts() { |
| 129 | // TODO: check for existing optical intents |
| 130 | return; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 131 | } |
| 132 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 133 | public class InternalOpticalPathProvisioner implements IntentListener { |
| 134 | @Override |
| 135 | public void event(IntentEvent event) { |
| 136 | switch (event.type()) { |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 137 | case INSTALL_REQ: |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 138 | break; |
| 139 | case INSTALLED: |
| 140 | break; |
| 141 | case FAILED: |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 142 | log.info("Intent {} failed, calling optical path provisioning app.", event.subject()); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 143 | setupLightpath(event.subject()); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 144 | break; |
| 145 | case WITHDRAWN: |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 146 | log.info("Intent {} withdrawn.", event.subject()); |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 147 | releaseResources(event.subject()); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 148 | break; |
| 149 | default: |
| 150 | break; |
| 151 | } |
| 152 | } |
| 153 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 154 | private void setupLightpath(Intent intent) { |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 155 | checkNotNull(intent); |
| 156 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 157 | // 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 SHIMIZU | 0a9c9c4 | 2015-07-01 15:29:16 -0700 | [diff] [blame] | 160 | if (intentService.getIntentState(intent.key()) != IntentState.FAILED) { |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 161 | return; |
Marc De Leenheer | b473b9d | 2015-02-06 15:21:03 -0800 | [diff] [blame] | 162 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 163 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 164 | // Get source and destination based on intent type |
| 165 | ConnectPoint src; |
| 166 | ConnectPoint dst; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 167 | if (intent instanceof HostToHostIntent) { |
| 168 | HostToHostIntent hostToHostIntent = (HostToHostIntent) intent; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 169 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 170 | Host one = hostService.getHost(hostToHostIntent.one()); |
| 171 | Host two = hostService.getHost(hostToHostIntent.two()); |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 172 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 173 | checkNotNull(one); |
| 174 | checkNotNull(two); |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 175 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 176 | src = one.location(); |
| 177 | dst = two.location(); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 178 | } else if (intent instanceof PointToPointIntent) { |
| 179 | PointToPointIntent p2pIntent = (PointToPointIntent) intent; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 180 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 181 | src = p2pIntent.ingressPoint(); |
| 182 | dst = p2pIntent.egressPoint(); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 183 | } else { |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 184 | return; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 185 | } |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 186 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 187 | 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 SHIMIZU | fb446fe | 2015-05-21 14:45:23 -0700 | [diff] [blame] | 199 | List<Intent> intents = getOpticalIntents(src, dst); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 200 | |
| 201 | // Submit the intents |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 202 | for (Intent i : intents) { |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 203 | intentService.submit(i); |
Sho SHIMIZU | b5d3841 | 2015-05-21 11:12:58 -0700 | [diff] [blame] | 204 | log.debug("Submitted an intent: {}", i); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 205 | } |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 208 | /** |
| 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 SHIMIZU | 819ee29 | 2015-07-01 09:36:21 -0700 | [diff] [blame] | 219 | List<ConnectPoint> connectPoints = new LinkedList<>(); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 220 | |
| 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 Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 239 | * Checks if cross connect points are of same type. |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 240 | * |
| 241 | * @param crossConnectPoints list of cross connection points |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 242 | * @return true if cross connect point pairs are of same type, false otherwise |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 243 | */ |
| 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 Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 254 | 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 Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 260 | return false; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | return true; |
| 265 | } |
| 266 | |
| 267 | /** |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 268 | * Scans the list of cross connection points and returns a list of optical connectivity intents. |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 269 | * |
| 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 SHIMIZU | 79945e8 | 2015-05-20 17:20:47 -0700 | [diff] [blame] | 276 | List<Intent> intents = new LinkedList<>(); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 277 | 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 Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 284 | Port srcPort = deviceService.getPort(src.deviceId(), src.port()); |
| 285 | Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 286 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 287 | if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) { |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 288 | // 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 Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 294 | .bidirectional(true) |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 295 | .build(); |
| 296 | intents.add(circuitIntent); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 297 | } 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 Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 305 | .bidirectional(true) |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 306 | .build(); |
| 307 | intents.add(opticalIntent); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 308 | } else { |
| 309 | log.warn("Unsupported cross connect point types {} {}", srcPort.type(), dstPort.type()); |
| 310 | return Collections.emptyList(); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 311 | } |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | return intents; |
| 315 | } |
| 316 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 317 | /** |
| 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'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 326 | Set<Path> paths = pathService.getPaths(ingress.deviceId(), |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 327 | egress.deviceId(), |
| 328 | new OpticalLinkWeight()); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 329 | |
| 330 | if (paths.isEmpty()) { |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 331 | return Collections.emptyList(); |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 332 | } |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 333 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 334 | // Search path with available cross connect points |
| 335 | for (Path path : paths) { |
| 336 | List<ConnectPoint> crossConnectPoints = getCrossConnectPoints(path); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 337 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 338 | // Skip to next path if cross connect points are mismatched |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 339 | if (!checkCrossConnectPoints(crossConnectPoints)) { |
| 340 | continue; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 343 | return getIntents(crossConnectPoints); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 344 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 345 | |
Marc De Leenheer | 234fa82 | 2015-11-18 18:24:57 -0800 | [diff] [blame] | 346 | log.warn("Unable to find multi-layer path."); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 347 | return Collections.emptyList(); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 350 | /** |
| 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'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 360 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 361 | // 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'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 370 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 371 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 372 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 373 | /** |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 374 | * Release resources associated to the given intent. |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 375 | * |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 376 | * @param intent the intent |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 377 | */ |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 378 | private void releaseResources(Intent intent) { |
Sho SHIMIZU | c87db55 | 2015-10-28 15:36:59 -0700 | [diff] [blame] | 379 | Collection<ResourceAllocation> allocations = resourceService.getResourceAllocations(intent.id()); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 380 | if (intent instanceof OpticalConnectivityIntent) { |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 381 | resourceService.release(intent.id()); |
Sho SHIMIZU | c87db55 | 2015-10-28 15:36:59 -0700 | [diff] [blame] | 382 | if (!allocations.isEmpty()) { |
| 383 | resourceService.release(ImmutableList.copyOf(allocations)); |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 384 | } |
| 385 | } else if (intent instanceof OpticalCircuitIntent) { |
Sho SHIMIZU | 5c16df8 | 2015-09-29 12:52:07 -0700 | [diff] [blame] | 386 | resourceService.release(intent.id()); |
Sho SHIMIZU | 7d20af1 | 2015-10-01 16:03:51 -0700 | [diff] [blame] | 387 | intentSetMultimap.releaseMapping(intent.id()); |
Sho SHIMIZU | c87db55 | 2015-10-28 15:36:59 -0700 | [diff] [blame] | 388 | if (!allocations.isEmpty()) { |
| 389 | resourceService.release(ImmutableList.copyOf(allocations)); |
Ayaka Koshibe | bcb0237 | 2015-06-01 10:56:42 -0700 | [diff] [blame] | 390 | } |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 391 | } |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 392 | } |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 393 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 394 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 395 | /** |
Marc De Leenheer | 234fa82 | 2015-11-18 18:24:57 -0800 | [diff] [blame] | 396 | * 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 Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 417 | * |
| 418 | * @param link the link |
Marc De Leenheer | 234fa82 | 2015-11-18 18:24:57 -0800 | [diff] [blame] | 419 | * @return true if the link is a cross-connect link, false otherwise |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 420 | */ |
Marc De Leenheer | 234fa82 | 2015-11-18 18:24:57 -0800 | [diff] [blame] | 421 | private boolean isCrossConnectLink(Link link) { |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 422 | if (link.type() != Link.Type.OPTICAL) { |
| 423 | return false; |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 424 | } |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 425 | |
Marc De Leenheer | 234fa82 | 2015-11-18 18:24:57 -0800 | [diff] [blame] | 426 | Device.Type src = deviceService.getDevice(link.src().deviceId()).type(); |
| 427 | Device.Type dst = deviceService.getDevice(link.dst().deviceId()).type(); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 428 | |
Marc De Leenheer | 234fa82 | 2015-11-18 18:24:57 -0800 | [diff] [blame] | 429 | return src != dst && |
| 430 | ((isPacketLayer(src) && isTransportLayer(dst)) || (isPacketLayer(dst) && isTransportLayer(src))); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 431 | } |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 432 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 433 | } |