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 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 20 | import org.apache.felix.scr.annotations.Deactivate; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Reference; |
| 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 23 | import org.onosproject.cluster.ClusterService; |
| 24 | import org.onosproject.cluster.NodeId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.core.ApplicationId; |
| 26 | import org.onosproject.core.CoreService; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 27 | import org.onosproject.mastership.MastershipService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 28 | import org.onosproject.net.ConnectPoint; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 29 | import org.onosproject.net.Device; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.net.Host; |
| 31 | import org.onosproject.net.Link; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 32 | import org.onosproject.net.OchPort; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 33 | import org.onosproject.net.OduCltPort; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 34 | import org.onosproject.net.OduSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import org.onosproject.net.Path; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 36 | import org.onosproject.net.Port; |
| 37 | import org.onosproject.net.device.DeviceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 38 | import org.onosproject.net.host.HostService; |
| 39 | import org.onosproject.net.intent.HostToHostIntent; |
| 40 | import org.onosproject.net.intent.Intent; |
| 41 | import org.onosproject.net.intent.IntentEvent; |
| 42 | import org.onosproject.net.intent.IntentListener; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 43 | import org.onosproject.net.intent.IntentService; |
| 44 | import org.onosproject.net.intent.IntentState; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 45 | import org.onosproject.net.intent.OpticalCircuitIntent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 46 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 47 | import org.onosproject.net.intent.PointToPointIntent; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 48 | import org.onosproject.net.resource.device.DeviceResourceService; |
Ayaka Koshibe | bcb0237 | 2015-06-01 10:56:42 -0700 | [diff] [blame] | 49 | import org.onosproject.net.resource.link.LinkResourceAllocations; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 50 | import org.onosproject.net.resource.link.LinkResourceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 51 | import org.onosproject.net.topology.LinkWeight; |
| 52 | import org.onosproject.net.topology.PathService; |
| 53 | import org.onosproject.net.topology.TopologyEdge; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 54 | import org.slf4j.Logger; |
| 55 | import org.slf4j.LoggerFactory; |
| 56 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 57 | import java.util.Collections; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 58 | import java.util.Iterator; |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 59 | import java.util.LinkedList; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 60 | import java.util.List; |
| 61 | import java.util.Set; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 62 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 63 | import static com.google.common.base.Preconditions.checkArgument; |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 64 | import static com.google.common.base.Preconditions.checkNotNull; |
| 65 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 66 | /** |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 67 | * OpticalPathProvisioner listens for event notifications from the Intent F/W. |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 68 | * It generates one or more opticalConnectivityIntent(s) and submits (or withdraws) to Intent F/W |
| 69 | * for adding/releasing capacity at the packet layer. |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 70 | */ |
| 71 | |
| 72 | @Component(immediate = true) |
| 73 | public class OpticalPathProvisioner { |
| 74 | |
| 75 | protected static final Logger log = LoggerFactory |
| 76 | .getLogger(OpticalPathProvisioner.class); |
| 77 | |
| 78 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 79 | private IntentService intentService; |
| 80 | |
| 81 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 82 | protected PathService pathService; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 83 | |
| 84 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 85 | protected CoreService coreService; |
| 86 | |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 87 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 88 | protected HostService hostService; |
| 89 | |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 90 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 91 | protected MastershipService mastershipService; |
| 92 | |
| 93 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 94 | protected ClusterService clusterService; |
| 95 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 96 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 97 | protected DeviceService deviceService; |
| 98 | |
| 99 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 100 | protected DeviceResourceService deviceResourceService; |
| 101 | |
| 102 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 103 | protected LinkResourceService linkResourceService; |
| 104 | |
| 105 | private ApplicationId appId; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 106 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 107 | private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner(); |
| 108 | |
| 109 | @Activate |
| 110 | protected void activate() { |
| 111 | intentService.addListener(pathProvisioner); |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 112 | appId = coreService.registerApplication("org.onosproject.optical"); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 113 | initOpticalPorts(); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 114 | log.info("Started"); |
| 115 | } |
| 116 | |
| 117 | @Deactivate |
| 118 | protected void deactivate() { |
| 119 | intentService.removeListener(pathProvisioner); |
| 120 | log.info("Stopped"); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 123 | /** |
| 124 | * Initialize availability of optical ports. |
| 125 | */ |
| 126 | private void initOpticalPorts() { |
| 127 | // TODO: check for existing optical intents |
| 128 | return; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 129 | } |
| 130 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 131 | public class InternalOpticalPathProvisioner implements IntentListener { |
| 132 | @Override |
| 133 | public void event(IntentEvent event) { |
| 134 | switch (event.type()) { |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 135 | case INSTALL_REQ: |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 136 | break; |
| 137 | case INSTALLED: |
| 138 | break; |
| 139 | case FAILED: |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 140 | log.info("Intent {} failed, calling optical path provisioning app.", event.subject()); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 141 | setupLightpath(event.subject()); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 142 | break; |
| 143 | case WITHDRAWN: |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 144 | log.info("Intent {} withdrawn.", event.subject()); |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 145 | releaseResources(event.subject()); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 146 | break; |
| 147 | default: |
| 148 | break; |
| 149 | } |
| 150 | } |
| 151 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 152 | private void setupLightpath(Intent intent) { |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 153 | checkNotNull(intent); |
| 154 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 155 | // TODO change the coordination approach between packet intents and optical intents |
| 156 | // Low speed LLDP may cause multiple calls which are not expected |
| 157 | |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 158 | if (!IntentState.FAILED.equals(intentService.getIntentState(intent.key()))) { |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 159 | return; |
Marc De Leenheer | b473b9d | 2015-02-06 15:21:03 -0800 | [diff] [blame] | 160 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 161 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 162 | // Get source and destination based on intent type |
| 163 | ConnectPoint src; |
| 164 | ConnectPoint dst; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 165 | if (intent instanceof HostToHostIntent) { |
| 166 | HostToHostIntent hostToHostIntent = (HostToHostIntent) intent; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 167 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 168 | Host one = hostService.getHost(hostToHostIntent.one()); |
| 169 | Host two = hostService.getHost(hostToHostIntent.two()); |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 170 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 171 | checkNotNull(one); |
| 172 | checkNotNull(two); |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 173 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 174 | src = one.location(); |
| 175 | dst = two.location(); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 176 | } else if (intent instanceof PointToPointIntent) { |
| 177 | PointToPointIntent p2pIntent = (PointToPointIntent) intent; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 178 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 179 | src = p2pIntent.ingressPoint(); |
| 180 | dst = p2pIntent.egressPoint(); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 181 | } else { |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 182 | return; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 183 | } |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 184 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 185 | if (src == null || dst == null) { |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | // Ignore if we're not the master for the intent's origin device |
| 190 | NodeId localNode = clusterService.getLocalNode().id(); |
| 191 | NodeId sourceMaster = mastershipService.getMasterFor(src.deviceId()); |
| 192 | if (!localNode.equals(sourceMaster)) { |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | // Generate optical connectivity intents |
Sho SHIMIZU | fb446fe | 2015-05-21 14:45:23 -0700 | [diff] [blame] | 197 | List<Intent> intents = getOpticalIntents(src, dst); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 198 | |
| 199 | // Submit the intents |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 200 | for (Intent i : intents) { |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 201 | intentService.submit(i); |
Sho SHIMIZU | b5d3841 | 2015-05-21 11:12:58 -0700 | [diff] [blame] | 202 | log.debug("Submitted an intent: {}", i); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 203 | } |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 206 | /** |
| 207 | * Returns list of cross connection points of missing optical path sections. |
| 208 | * |
| 209 | * Scans the given multi-layer path and looks for sections that use cross connect links. |
| 210 | * The ingress and egress points in the optical layer are returned in a list. |
| 211 | * |
| 212 | * @param path the multi-layer path |
| 213 | * @return list of cross connection points on the optical layer |
| 214 | */ |
| 215 | private List<ConnectPoint> getCrossConnectPoints(Path path) { |
| 216 | boolean scanning = false; |
| 217 | List<ConnectPoint> connectPoints = new LinkedList<ConnectPoint>(); |
| 218 | |
| 219 | for (Link link : path.links()) { |
| 220 | if (!isCrossConnectLink(link)) { |
| 221 | continue; |
| 222 | } |
| 223 | |
| 224 | if (scanning) { |
| 225 | connectPoints.add(checkNotNull(link.src())); |
| 226 | scanning = false; |
| 227 | } else { |
| 228 | connectPoints.add(checkNotNull(link.dst())); |
| 229 | scanning = true; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | return connectPoints; |
| 234 | } |
| 235 | |
| 236 | /** |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 237 | * Checks if cross connect points are of same type. |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 238 | * |
| 239 | * @param crossConnectPoints list of cross connection points |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 240 | * @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] | 241 | */ |
| 242 | private boolean checkCrossConnectPoints(List<ConnectPoint> crossConnectPoints) { |
| 243 | checkArgument(crossConnectPoints.size() % 2 == 0); |
| 244 | |
| 245 | Iterator<ConnectPoint> itr = crossConnectPoints.iterator(); |
| 246 | |
| 247 | while (itr.hasNext()) { |
| 248 | // checkArgument at start ensures we'll always have pairs of connect points |
| 249 | ConnectPoint src = itr.next(); |
| 250 | ConnectPoint dst = itr.next(); |
| 251 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 252 | Device.Type srcType = deviceService.getDevice(src.deviceId()).type(); |
| 253 | Device.Type dstType = deviceService.getDevice(dst.deviceId()).type(); |
| 254 | |
| 255 | // Only support connections between identical port types |
| 256 | if (srcType != dstType) { |
| 257 | log.warn("Unsupported mix of cross connect points"); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 258 | return false; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | return true; |
| 263 | } |
| 264 | |
| 265 | /** |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 266 | * 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] | 267 | * |
| 268 | * @param crossConnectPoints list of cross connection points |
| 269 | * @return list of optical connectivity intents |
| 270 | */ |
| 271 | private List<Intent> getIntents(List<ConnectPoint> crossConnectPoints) { |
| 272 | checkArgument(crossConnectPoints.size() % 2 == 0); |
| 273 | |
Sho SHIMIZU | 79945e8 | 2015-05-20 17:20:47 -0700 | [diff] [blame] | 274 | List<Intent> intents = new LinkedList<>(); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 275 | Iterator<ConnectPoint> itr = crossConnectPoints.iterator(); |
| 276 | |
| 277 | while (itr.hasNext()) { |
| 278 | // checkArgument at start ensures we'll always have pairs of connect points |
| 279 | ConnectPoint src = itr.next(); |
| 280 | ConnectPoint dst = itr.next(); |
| 281 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 282 | Port srcPort = deviceService.getPort(src.deviceId(), src.port()); |
| 283 | Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 284 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 285 | if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) { |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 286 | // Create OTN circuit |
| 287 | Intent circuitIntent = OpticalCircuitIntent.builder() |
| 288 | .appId(appId) |
| 289 | .src(src) |
| 290 | .dst(dst) |
| 291 | .signalType(OduCltPort.SignalType.CLT_10GBE) |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 292 | .bidirectional(true) |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 293 | .build(); |
| 294 | intents.add(circuitIntent); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 295 | continue; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 296 | } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) { |
| 297 | // Create lightpath |
| 298 | // FIXME: hardcoded ODU signal type |
| 299 | Intent opticalIntent = OpticalConnectivityIntent.builder() |
| 300 | .appId(appId) |
| 301 | .src(src) |
| 302 | .dst(dst) |
| 303 | .signalType(OduSignalType.ODU4) |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 304 | .bidirectional(true) |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 305 | .build(); |
| 306 | intents.add(opticalIntent); |
| 307 | continue; |
| 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 | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 346 | return Collections.emptyList(); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 349 | /** |
| 350 | * Link weight function that emphasizes re-use of packet links. |
| 351 | */ |
| 352 | private class OpticalLinkWeight implements LinkWeight { |
| 353 | @Override |
| 354 | public double weight(TopologyEdge edge) { |
| 355 | // Ignore inactive links |
| 356 | if (edge.link().state() == Link.State.INACTIVE) { |
| 357 | return -1; |
| 358 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 359 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 360 | // TODO: Ignore cross connect links with used ports |
| 361 | |
| 362 | // Transport links have highest weight |
| 363 | if (edge.link().type() == Link.Type.OPTICAL) { |
| 364 | return 1000; |
| 365 | } |
| 366 | |
| 367 | // Packet links |
| 368 | return 1; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 369 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 370 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 371 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 372 | /** |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 373 | * Release resources associated to the given intent. |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 374 | * |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 375 | * @param intent the intent |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 376 | */ |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 377 | private void releaseResources(Intent intent) { |
Ayaka Koshibe | bcb0237 | 2015-06-01 10:56:42 -0700 | [diff] [blame] | 378 | LinkResourceAllocations lra = linkResourceService.getAllocations(intent.id()); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 379 | if (intent instanceof OpticalConnectivityIntent) { |
| 380 | deviceResourceService.releasePorts(intent.id()); |
Ayaka Koshibe | bcb0237 | 2015-06-01 10:56:42 -0700 | [diff] [blame] | 381 | linkResourceService.releaseResources(lra); |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 382 | } else if (intent instanceof OpticalCircuitIntent) { |
| 383 | deviceResourceService.releasePorts(intent.id()); |
| 384 | deviceResourceService.releaseMapping(intent.id()); |
Ayaka Koshibe | bcb0237 | 2015-06-01 10:56:42 -0700 | [diff] [blame] | 385 | if (lra != null) { |
| 386 | linkResourceService.releaseResources(lra); |
| 387 | } |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 388 | } |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 389 | } |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 390 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 391 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 392 | /** |
| 393 | * Verifies if given link is cross-connect between packet and optical layer. |
| 394 | * |
| 395 | * @param link the link |
| 396 | * @return true if the link is a cross-connect link |
| 397 | */ |
| 398 | public static boolean isCrossConnectLink(Link link) { |
| 399 | if (link.type() != Link.Type.OPTICAL) { |
| 400 | return false; |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 401 | } |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 402 | |
| 403 | checkNotNull(link.annotations()); |
| 404 | checkNotNull(link.annotations().value("optical.type")); |
| 405 | |
Sho SHIMIZU | 6d28312 | 2015-05-21 11:07:02 -0700 | [diff] [blame] | 406 | return link.annotations().value("optical.type").equals("cross-connect"); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 407 | } |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 408 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 409 | } |