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