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