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