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