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