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