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 | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 32 | import org.onosproject.net.OduCltPort; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.net.Path; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 34 | import org.onosproject.net.Port; |
| 35 | import org.onosproject.net.device.DeviceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 36 | import org.onosproject.net.host.HostService; |
| 37 | import org.onosproject.net.intent.HostToHostIntent; |
| 38 | import org.onosproject.net.intent.Intent; |
| 39 | import org.onosproject.net.intent.IntentEvent; |
| 40 | import org.onosproject.net.intent.IntentListener; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 41 | import org.onosproject.net.intent.IntentService; |
| 42 | import org.onosproject.net.intent.IntentState; |
| 43 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 44 | import org.onosproject.net.intent.PointToPointIntent; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 45 | import org.onosproject.net.resource.device.DeviceResourceService; |
| 46 | import org.onosproject.net.resource.link.LinkResourceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 47 | import org.onosproject.net.topology.LinkWeight; |
| 48 | import org.onosproject.net.topology.PathService; |
| 49 | import org.onosproject.net.topology.TopologyEdge; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 50 | import org.slf4j.Logger; |
| 51 | import org.slf4j.LoggerFactory; |
| 52 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 53 | import java.util.Collections; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 54 | import java.util.Iterator; |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 55 | import java.util.LinkedList; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 56 | import java.util.List; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 57 | import java.util.Map; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 58 | import java.util.Set; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 59 | import java.util.concurrent.ConcurrentHashMap; |
| 60 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 61 | import static com.google.common.base.Preconditions.checkArgument; |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -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.checkNotNull; |
| 64 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 65 | /** |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 66 | * OpticalPathProvisioner listens for event notifications from the Intent F/W. |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 67 | * It generates one or more opticalConnectivityIntent(s) and submits (or withdraws) to Intent F/W |
| 68 | * for adding/releasing capacity at the packet layer. |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 69 | */ |
| 70 | |
| 71 | @Component(immediate = true) |
| 72 | public class OpticalPathProvisioner { |
| 73 | |
| 74 | protected static final Logger log = LoggerFactory |
| 75 | .getLogger(OpticalPathProvisioner.class); |
| 76 | |
| 77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 78 | private IntentService intentService; |
| 79 | |
| 80 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 81 | protected PathService pathService; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 82 | |
| 83 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 84 | protected CoreService coreService; |
| 85 | |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 87 | protected HostService hostService; |
| 88 | |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 89 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 90 | protected MastershipService mastershipService; |
| 91 | |
| 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 93 | protected ClusterService clusterService; |
| 94 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 95 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 96 | protected DeviceService deviceService; |
| 97 | |
| 98 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 99 | protected DeviceResourceService deviceResourceService; |
| 100 | |
| 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 102 | protected LinkResourceService linkResourceService; |
| 103 | |
| 104 | private ApplicationId appId; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 105 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 106 | private final Map<ConnectPoint, Map<ConnectPoint, Intent>> intentMap = |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 107 | new ConcurrentHashMap<>(); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 108 | |
| 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: |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 140 | // track h2h & p2p intents using our connectivity |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 141 | break; |
| 142 | case FAILED: |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 143 | log.info("Intent {} failed, calling optical path provisioning app.", event.subject()); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 144 | setupLightpath(event.subject()); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 145 | break; |
| 146 | case WITHDRAWN: |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 147 | log.info("Intent {} withdrawn.", event.subject()); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 148 | withdrawIntent(event.subject()); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 149 | break; |
| 150 | default: |
| 151 | break; |
| 152 | } |
| 153 | } |
| 154 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 155 | /** |
| 156 | * Registers an intent from src to dst. |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 157 | * |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 158 | * @param src source point |
| 159 | * @param dst destination point |
| 160 | * @param intent intent to be registered |
| 161 | * @return true if intent has not been previously added, false otherwise |
| 162 | */ |
| 163 | private boolean addIntent(ConnectPoint src, ConnectPoint dst, Intent intent) { |
| 164 | Map<ConnectPoint, Intent> srcMap = intentMap.get(src); |
| 165 | if (srcMap == null) { |
| 166 | srcMap = new ConcurrentHashMap<>(); |
| 167 | intentMap.put(src, srcMap); |
| 168 | } |
| 169 | if (srcMap.containsKey(dst)) { |
| 170 | return false; |
| 171 | } else { |
| 172 | srcMap.put(dst, intent); |
| 173 | return true; |
| 174 | } |
| 175 | } |
| 176 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 177 | private void setupLightpath(Intent intent) { |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 178 | checkNotNull(intent); |
| 179 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 180 | // TODO change the coordination approach between packet intents and optical intents |
| 181 | // Low speed LLDP may cause multiple calls which are not expected |
| 182 | |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 183 | if (!IntentState.FAILED.equals(intentService.getIntentState(intent.key()))) { |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 184 | return; |
Marc De Leenheer | b473b9d | 2015-02-06 15:21:03 -0800 | [diff] [blame] | 185 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 186 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 187 | // Get source and destination based on intent type |
| 188 | ConnectPoint src; |
| 189 | ConnectPoint dst; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 190 | if (intent instanceof HostToHostIntent) { |
| 191 | HostToHostIntent hostToHostIntent = (HostToHostIntent) intent; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 192 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 193 | Host one = hostService.getHost(hostToHostIntent.one()); |
| 194 | Host two = hostService.getHost(hostToHostIntent.two()); |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 195 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 196 | checkNotNull(one); |
| 197 | checkNotNull(two); |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 198 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 199 | src = one.location(); |
| 200 | dst = two.location(); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 201 | } else if (intent instanceof PointToPointIntent) { |
| 202 | PointToPointIntent p2pIntent = (PointToPointIntent) intent; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 203 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 204 | src = p2pIntent.ingressPoint(); |
| 205 | dst = p2pIntent.egressPoint(); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 206 | } else { |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 207 | log.error("Unsupported intent type: {}", intent.getClass()); |
| 208 | return; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 209 | } |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 210 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 211 | if (src == null || dst == null) { |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | // Ignore if we're not the master for the intent's origin device |
| 216 | NodeId localNode = clusterService.getLocalNode().id(); |
| 217 | NodeId sourceMaster = mastershipService.getMasterFor(src.deviceId()); |
| 218 | if (!localNode.equals(sourceMaster)) { |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | // Generate optical connectivity intents |
Sho SHIMIZU | fb446fe | 2015-05-21 14:45:23 -0700 | [diff] [blame] | 223 | List<Intent> intents = getOpticalIntents(src, dst); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 224 | |
| 225 | // Submit the intents |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 226 | for (Intent i : intents) { |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 227 | intentService.submit(i); |
Sho SHIMIZU | b5d3841 | 2015-05-21 11:12:58 -0700 | [diff] [blame] | 228 | log.debug("Submitted an intent: {}", i); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 229 | } |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 232 | /** |
| 233 | * Returns list of cross connection points of missing optical path sections. |
| 234 | * |
| 235 | * Scans the given multi-layer path and looks for sections that use cross connect links. |
| 236 | * The ingress and egress points in the optical layer are returned in a list. |
| 237 | * |
| 238 | * @param path the multi-layer path |
| 239 | * @return list of cross connection points on the optical layer |
| 240 | */ |
| 241 | private List<ConnectPoint> getCrossConnectPoints(Path path) { |
| 242 | boolean scanning = false; |
| 243 | List<ConnectPoint> connectPoints = new LinkedList<ConnectPoint>(); |
| 244 | |
| 245 | for (Link link : path.links()) { |
| 246 | if (!isCrossConnectLink(link)) { |
| 247 | continue; |
| 248 | } |
| 249 | |
| 250 | if (scanning) { |
| 251 | connectPoints.add(checkNotNull(link.src())); |
| 252 | scanning = false; |
| 253 | } else { |
| 254 | connectPoints.add(checkNotNull(link.dst())); |
| 255 | scanning = true; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | return connectPoints; |
| 260 | } |
| 261 | |
| 262 | /** |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 263 | * Checks if cross connect points are of same type. |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 264 | * |
| 265 | * @param crossConnectPoints list of cross connection points |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 266 | * @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] | 267 | */ |
| 268 | private boolean checkCrossConnectPoints(List<ConnectPoint> crossConnectPoints) { |
| 269 | checkArgument(crossConnectPoints.size() % 2 == 0); |
| 270 | |
| 271 | Iterator<ConnectPoint> itr = crossConnectPoints.iterator(); |
| 272 | |
| 273 | while (itr.hasNext()) { |
| 274 | // checkArgument at start ensures we'll always have pairs of connect points |
| 275 | ConnectPoint src = itr.next(); |
| 276 | ConnectPoint dst = itr.next(); |
| 277 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 278 | Device.Type srcType = deviceService.getDevice(src.deviceId()).type(); |
| 279 | Device.Type dstType = deviceService.getDevice(dst.deviceId()).type(); |
| 280 | |
| 281 | // Only support connections between identical port types |
| 282 | if (srcType != dstType) { |
| 283 | log.warn("Unsupported mix of cross connect points"); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 284 | return false; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | return true; |
| 289 | } |
| 290 | |
| 291 | /** |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 292 | * 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] | 293 | * |
| 294 | * @param crossConnectPoints list of cross connection points |
| 295 | * @return list of optical connectivity intents |
| 296 | */ |
| 297 | private List<Intent> getIntents(List<ConnectPoint> crossConnectPoints) { |
| 298 | checkArgument(crossConnectPoints.size() % 2 == 0); |
| 299 | |
Sho SHIMIZU | 79945e8 | 2015-05-20 17:20:47 -0700 | [diff] [blame] | 300 | List<Intent> intents = new LinkedList<>(); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 301 | Iterator<ConnectPoint> itr = crossConnectPoints.iterator(); |
| 302 | |
| 303 | while (itr.hasNext()) { |
| 304 | // checkArgument at start ensures we'll always have pairs of connect points |
| 305 | ConnectPoint src = itr.next(); |
| 306 | ConnectPoint dst = itr.next(); |
| 307 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 308 | Port srcPort = deviceService.getPort(src.deviceId(), src.port()); |
| 309 | Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); |
| 310 | // Create lightpath |
| 311 | // TODO: Ensure src & dst are of type OchPort |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 312 | Intent opticalIntent = OpticalConnectivityIntent.builder() |
| 313 | .appId(appId) |
| 314 | .src(src) |
| 315 | .dst(dst) |
| 316 | .build(); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 317 | intents.add(opticalIntent); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 318 | if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) { |
| 319 | continue; |
| 320 | // also create OTN service |
| 321 | } |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | return intents; |
| 325 | } |
| 326 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 327 | /** |
| 328 | * Returns list of optical connectivity intents needed to create connectivity |
| 329 | * between ingress and egress. |
| 330 | * |
| 331 | * @param ingress the ingress connect point |
| 332 | * @param egress the egress connect point |
| 333 | * @return list of optical connectivity intents, empty list if no path was found |
| 334 | */ |
| 335 | private List<Intent> getOpticalIntents(ConnectPoint ingress, ConnectPoint egress) { |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 336 | Set<Path> paths = pathService.getPaths(ingress.deviceId(), |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 337 | egress.deviceId(), |
| 338 | new OpticalLinkWeight()); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 339 | |
| 340 | if (paths.isEmpty()) { |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 341 | return Collections.emptyList(); |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 342 | } |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 343 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 344 | // Search path with available cross connect points |
| 345 | for (Path path : paths) { |
| 346 | List<ConnectPoint> crossConnectPoints = getCrossConnectPoints(path); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 347 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 348 | // Skip to next path if cross connect points are mismatched |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 349 | if (!checkCrossConnectPoints(crossConnectPoints)) { |
| 350 | continue; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 351 | } |
| 352 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 353 | return getIntents(crossConnectPoints); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 354 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 355 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 356 | return Collections.emptyList(); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 359 | /** |
| 360 | * Link weight function that emphasizes re-use of packet links. |
| 361 | */ |
| 362 | private class OpticalLinkWeight implements LinkWeight { |
| 363 | @Override |
| 364 | public double weight(TopologyEdge edge) { |
| 365 | // Ignore inactive links |
| 366 | if (edge.link().state() == Link.State.INACTIVE) { |
| 367 | return -1; |
| 368 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 369 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 370 | // TODO: Ignore cross connect links with used ports |
| 371 | |
| 372 | // Transport links have highest weight |
| 373 | if (edge.link().type() == Link.Type.OPTICAL) { |
| 374 | return 1000; |
| 375 | } |
| 376 | |
| 377 | // Packet links |
| 378 | return 1; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 379 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 380 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 381 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 382 | /** |
| 383 | * Handle withdrawn intent on each network layer. |
| 384 | * |
| 385 | * @param intent the withdrawn intent |
| 386 | */ |
| 387 | private void withdrawIntent(Intent intent) { |
| 388 | if (intent instanceof OpticalConnectivityIntent) { |
| 389 | deviceResourceService.releasePorts(intent.id()); |
| 390 | linkResourceService.releaseResources(linkResourceService.getAllocations(intent.id())); |
| 391 | } |
| 392 | // TODO: add other layers |
| 393 | } |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 394 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 395 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 396 | /** |
| 397 | * Verifies if given link is cross-connect between packet and optical layer. |
| 398 | * |
| 399 | * @param link the link |
| 400 | * @return true if the link is a cross-connect link |
| 401 | */ |
| 402 | public static boolean isCrossConnectLink(Link link) { |
| 403 | if (link.type() != Link.Type.OPTICAL) { |
| 404 | return false; |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 405 | } |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame] | 406 | |
| 407 | checkNotNull(link.annotations()); |
| 408 | checkNotNull(link.annotations().value("optical.type")); |
| 409 | |
Sho SHIMIZU | 6d28312 | 2015-05-21 11:07:02 -0700 | [diff] [blame] | 410 | return link.annotations().value("optical.type").equals("cross-connect"); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 411 | } |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 412 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 413 | } |