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 | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 24 | import org.onosproject.cluster.ClusterService; |
| 25 | import org.onosproject.cluster.NodeId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import org.onosproject.core.ApplicationId; |
| 27 | import org.onosproject.core.CoreService; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 28 | import org.onosproject.mastership.MastershipService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 29 | import org.onosproject.net.ConnectPoint; |
| 30 | import org.onosproject.net.Host; |
| 31 | import org.onosproject.net.Link; |
| 32 | import org.onosproject.net.Path; |
| 33 | import org.onosproject.net.host.HostService; |
| 34 | import org.onosproject.net.intent.HostToHostIntent; |
| 35 | import org.onosproject.net.intent.Intent; |
| 36 | import org.onosproject.net.intent.IntentEvent; |
| 37 | import org.onosproject.net.intent.IntentListener; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 38 | import org.onosproject.net.intent.IntentService; |
| 39 | import org.onosproject.net.intent.IntentState; |
| 40 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 41 | import org.onosproject.net.intent.PointToPointIntent; |
| 42 | import org.onosproject.net.topology.LinkWeight; |
| 43 | import org.onosproject.net.topology.PathService; |
| 44 | import org.onosproject.net.topology.TopologyEdge; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 45 | import org.slf4j.Logger; |
| 46 | import org.slf4j.LoggerFactory; |
| 47 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 48 | import java.util.Collections; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 49 | import java.util.Iterator; |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 50 | import java.util.LinkedList; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 51 | import java.util.List; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 52 | import java.util.Map; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 53 | import java.util.Set; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 54 | import java.util.concurrent.ConcurrentHashMap; |
| 55 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 56 | import static com.google.common.base.Preconditions.checkArgument; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 57 | import static org.onosproject.net.intent.IntentState.INSTALLED; |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 58 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 59 | import static com.google.common.base.Preconditions.checkNotNull; |
| 60 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 61 | /** |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 62 | * OpticalPathProvisioner listens for event notifications from the Intent F/W. |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 63 | * It generates one or more opticalConnectivityIntent(s) and submits (or withdraws) to Intent F/W |
| 64 | * for adding/releasing capacity at the packet layer. |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 65 | */ |
| 66 | |
| 67 | @Component(immediate = true) |
| 68 | public class OpticalPathProvisioner { |
| 69 | |
| 70 | protected static final Logger log = LoggerFactory |
| 71 | .getLogger(OpticalPathProvisioner.class); |
| 72 | |
| 73 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 74 | private IntentService intentService; |
| 75 | |
| 76 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 77 | protected PathService pathService; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 78 | |
| 79 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 80 | protected CoreService coreService; |
| 81 | |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 83 | protected HostService hostService; |
| 84 | |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 86 | protected MastershipService mastershipService; |
| 87 | |
| 88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 89 | protected ClusterService clusterService; |
| 90 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 91 | private ApplicationId appId; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 92 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 93 | // TODO use a shared map for distributed operation |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 94 | private final Map<ConnectPoint, OpticalConnectivityIntent> inStatusTportMap = |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 95 | new ConcurrentHashMap<>(); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 96 | private final Map<ConnectPoint, OpticalConnectivityIntent> outStatusTportMap = |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 97 | new ConcurrentHashMap<>(); |
| 98 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 99 | private final Map<ConnectPoint, Map<ConnectPoint, Intent>> intentMap = |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 100 | new ConcurrentHashMap<>(); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 101 | |
| 102 | private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner(); |
| 103 | |
| 104 | @Activate |
| 105 | protected void activate() { |
| 106 | intentService.addListener(pathProvisioner); |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 107 | appId = coreService.registerApplication("org.onosproject.optical"); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 108 | initTport(); |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 109 | log.info("Started"); |
| 110 | } |
| 111 | |
| 112 | @Deactivate |
| 113 | protected void deactivate() { |
| 114 | intentService.removeListener(pathProvisioner); |
| 115 | log.info("Stopped"); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 118 | protected void initTport() { |
| 119 | inStatusTportMap.clear(); |
| 120 | outStatusTportMap.clear(); |
| 121 | for (Intent intent : intentService.getIntents()) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 122 | if (intentService.getIntentState(intent.key()) == INSTALLED) { |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 123 | if (intent instanceof OpticalConnectivityIntent) { |
| 124 | inStatusTportMap.put(((OpticalConnectivityIntent) intent).getSrc(), |
| 125 | (OpticalConnectivityIntent) intent); |
| 126 | outStatusTportMap.put(((OpticalConnectivityIntent) intent).getDst(), |
| 127 | (OpticalConnectivityIntent) intent); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 133 | public class InternalOpticalPathProvisioner implements IntentListener { |
| 134 | @Override |
| 135 | public void event(IntentEvent event) { |
| 136 | switch (event.type()) { |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 137 | case INSTALL_REQ: |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 138 | break; |
| 139 | case INSTALLED: |
| 140 | break; |
| 141 | case FAILED: |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 142 | log.info("Intent {} failed, calling optical path provisioning app.", event.subject()); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 143 | setupLightpath(event.subject()); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 144 | break; |
| 145 | case WITHDRAWN: |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 146 | log.info("Intent {} withdrawn.", event.subject()); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 147 | //FIXME |
| 148 | //teardownLightpath(event.subject()); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 149 | break; |
| 150 | default: |
| 151 | break; |
| 152 | } |
| 153 | } |
| 154 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 155 | private void reserveTport(Intent intent) { |
| 156 | // TODO move to resourceManager |
| 157 | if (intent instanceof OpticalConnectivityIntent) { |
| 158 | OpticalConnectivityIntent opticalIntent = |
| 159 | (OpticalConnectivityIntent) intent; |
| 160 | if (inStatusTportMap.containsKey(opticalIntent.getSrc()) || |
| 161 | outStatusTportMap.containsKey(opticalIntent.getDst())) { |
| 162 | //TODO throw an exception, perhaps |
| 163 | log.warn("Overlapping reservation: {}", opticalIntent); |
| 164 | } |
| 165 | inStatusTportMap.put(opticalIntent.getSrc(), opticalIntent); |
| 166 | outStatusTportMap.put(opticalIntent.getDst(), opticalIntent); |
| 167 | } |
| 168 | } |
| 169 | |
| 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) { |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 193 | // TODO change the coordination approach between packet intents and optical intents |
| 194 | // Low speed LLDP may cause multiple calls which are not expected |
| 195 | |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 196 | if (!IntentState.FAILED.equals(intentService.getIntentState(intent.key()))) { |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 197 | return; |
Marc De Leenheer | b473b9d | 2015-02-06 15:21:03 -0800 | [diff] [blame] | 198 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 199 | |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 200 | NodeId localNode = clusterService.getLocalNode().id(); |
| 201 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 202 | List<Intent> intents = Lists.newArrayList(); |
| 203 | if (intent instanceof HostToHostIntent) { |
| 204 | HostToHostIntent hostToHostIntent = (HostToHostIntent) intent; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 205 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 206 | Host one = hostService.getHost(hostToHostIntent.one()); |
| 207 | Host two = hostService.getHost(hostToHostIntent.two()); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 208 | if (one == null || two == null) { |
| 209 | return; //FIXME |
| 210 | } |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 211 | |
| 212 | // Ignore if we're not the master for the intent's origin device |
| 213 | NodeId sourceMaster = mastershipService.getMasterFor(one.location().deviceId()); |
| 214 | if (!localNode.equals(sourceMaster)) { |
| 215 | return; |
| 216 | } |
| 217 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 218 | // provision both directions |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 219 | intents.addAll(getOpticalPath(one.location(), two.location())); |
Brian O'Connor | 025fb44 | 2014-12-08 20:02:15 -0800 | [diff] [blame] | 220 | // note: bi-directional intent is set up |
| 221 | // HostToHost Intent requires symmetric path! |
| 222 | //intents.addAll(getOpticalPath(two.location(), one.location())); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 223 | } else if (intent instanceof PointToPointIntent) { |
| 224 | PointToPointIntent p2pIntent = (PointToPointIntent) intent; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 225 | |
| 226 | // Ignore if we're not the master for the intent's origin device |
| 227 | NodeId sourceMaster = mastershipService.getMasterFor(p2pIntent.ingressPoint().deviceId()); |
| 228 | if (!localNode.equals(sourceMaster)) { |
| 229 | return; |
| 230 | } |
| 231 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 232 | intents.addAll(getOpticalPath(p2pIntent.ingressPoint(), p2pIntent.egressPoint())); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 233 | } else { |
| 234 | log.info("Unsupported intent type: {}", intent.getClass()); |
| 235 | } |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 236 | |
Brian O'Connor | 03406a4 | 2015-02-03 17:28:57 -0800 | [diff] [blame] | 237 | // Create the intents |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 238 | for (Intent i : intents) { |
| 239 | // TODO: don't allow duplicate intents between the same points for now |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 240 | // we may want to allow this carefully in future to increase capacity |
| 241 | if (i instanceof OpticalConnectivityIntent) { |
| 242 | OpticalConnectivityIntent oi = (OpticalConnectivityIntent) i; |
| 243 | if (addIntent(oi.getSrc(), oi.getDst(), oi)) { |
Brian O'Connor | 03406a4 | 2015-02-03 17:28:57 -0800 | [diff] [blame] | 244 | intentService.submit(i); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 245 | reserveTport(i); |
| 246 | } |
| 247 | } else { |
| 248 | log.warn("Invalid intent type: {} for {}", i.getClass(), i); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 249 | } |
| 250 | } |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 253 | /** |
| 254 | * Returns list of cross connection points of missing optical path sections. |
| 255 | * |
| 256 | * Scans the given multi-layer path and looks for sections that use cross connect links. |
| 257 | * The ingress and egress points in the optical layer are returned in a list. |
| 258 | * |
| 259 | * @param path the multi-layer path |
| 260 | * @return list of cross connection points on the optical layer |
| 261 | */ |
| 262 | private List<ConnectPoint> getCrossConnectPoints(Path path) { |
| 263 | boolean scanning = false; |
| 264 | List<ConnectPoint> connectPoints = new LinkedList<ConnectPoint>(); |
| 265 | |
| 266 | for (Link link : path.links()) { |
| 267 | if (!isCrossConnectLink(link)) { |
| 268 | continue; |
| 269 | } |
| 270 | |
| 271 | if (scanning) { |
| 272 | connectPoints.add(checkNotNull(link.src())); |
| 273 | scanning = false; |
| 274 | } else { |
| 275 | connectPoints.add(checkNotNull(link.dst())); |
| 276 | scanning = true; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | return connectPoints; |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Checks availability of cross connect points by verifying T port status. |
| 285 | * TODO: refactor after rewriting OpticalConnectivityIntentCompiler |
| 286 | * |
| 287 | * @param crossConnectPoints list of cross connection points |
| 288 | * @return true if all cross connect points are available, false otherwise |
| 289 | */ |
| 290 | private boolean checkCrossConnectPoints(List<ConnectPoint> crossConnectPoints) { |
| 291 | checkArgument(crossConnectPoints.size() % 2 == 0); |
| 292 | |
| 293 | Iterator<ConnectPoint> itr = crossConnectPoints.iterator(); |
| 294 | |
| 295 | while (itr.hasNext()) { |
| 296 | // checkArgument at start ensures we'll always have pairs of connect points |
| 297 | ConnectPoint src = itr.next(); |
| 298 | ConnectPoint dst = itr.next(); |
| 299 | |
| 300 | if (inStatusTportMap.get(src) != null || outStatusTportMap.get(dst) != null) { |
| 301 | return false; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | return true; |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Scans the list of cross connection points and returns a list of optical connectivity intents |
| 310 | * in both directions. |
| 311 | * |
| 312 | * @param crossConnectPoints list of cross connection points |
| 313 | * @return list of optical connectivity intents |
| 314 | */ |
| 315 | private List<Intent> getIntents(List<ConnectPoint> crossConnectPoints) { |
| 316 | checkArgument(crossConnectPoints.size() % 2 == 0); |
| 317 | |
| 318 | List<Intent> intents = new LinkedList<Intent>(); |
| 319 | Iterator<ConnectPoint> itr = crossConnectPoints.iterator(); |
| 320 | |
| 321 | while (itr.hasNext()) { |
| 322 | // checkArgument at start ensures we'll always have pairs of connect points |
| 323 | ConnectPoint src = itr.next(); |
| 324 | ConnectPoint dst = itr.next(); |
| 325 | |
| 326 | // TODO: should have option for bidirectional OpticalConnectivityIntent |
| 327 | Intent opticalIntent = OpticalConnectivityIntent.builder() |
| 328 | .appId(appId) |
| 329 | .src(src) |
| 330 | .dst(dst) |
| 331 | .build(); |
| 332 | Intent opticalIntentRev = OpticalConnectivityIntent.builder() |
| 333 | .appId(appId) |
| 334 | .src(dst) |
| 335 | .dst(src) |
| 336 | .build(); |
| 337 | intents.add(opticalIntent); |
| 338 | intents.add(opticalIntentRev); |
| 339 | } |
| 340 | |
| 341 | return intents; |
| 342 | } |
| 343 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 344 | private List<Intent> getOpticalPath(ConnectPoint ingress, ConnectPoint egress) { |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 345 | Set<Path> paths = pathService.getPaths(ingress.deviceId(), |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 346 | egress.deviceId(), |
| 347 | new OpticalLinkWeight()); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 348 | |
| 349 | if (paths.isEmpty()) { |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 350 | return Collections.emptyList(); |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 351 | } |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 352 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 353 | List<Intent> connectionList = Lists.newArrayList(); |
| 354 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 355 | // Iterate over all paths until a suitable one has been found |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 356 | Iterator<Path> itrPath = paths.iterator(); |
| 357 | while (itrPath.hasNext()) { |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 358 | Path nextPath = itrPath.next(); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 359 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 360 | List<ConnectPoint> crossConnectPoints = getCrossConnectPoints(nextPath); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 361 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 362 | // Skip to next path if not all connect points are available |
| 363 | if (!checkCrossConnectPoints(crossConnectPoints)) { |
| 364 | continue; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 367 | return getIntents(crossConnectPoints); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 368 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 369 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 370 | return Collections.emptyList(); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 371 | } |
| 372 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 373 | private void teardownLightpath(Intent intent) { |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 374 | /* FIXME this command doesn't make much sense. we need to define the semantics |
| 375 | // TODO move to resourceManager |
| 376 | if (intent instanceof OpticalConnectivityIntent) { |
| 377 | inStatusTportMap.remove(((OpticalConnectivityIntent) intent).getSrc()); |
| 378 | outStatusTportMap.remove(((OpticalConnectivityIntent) intent).getDst()); |
| 379 | // TODO tear down the idle lightpath if the utilization is zero. |
| 380 | |
| 381 | } |
| 382 | */ //end-FIXME |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 383 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 384 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 385 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 386 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 387 | /** |
| 388 | * Verifies if given link is cross-connect between packet and optical layer. |
| 389 | * |
| 390 | * @param link the link |
| 391 | * @return true if the link is a cross-connect link |
| 392 | */ |
| 393 | public static boolean isCrossConnectLink(Link link) { |
| 394 | if (link.type() != Link.Type.OPTICAL) { |
| 395 | return false; |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 396 | } |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 397 | |
| 398 | checkNotNull(link.annotations()); |
| 399 | checkNotNull(link.annotations().value("optical.type")); |
| 400 | |
| 401 | if (link.annotations().value("optical.type").equals("cross-connect")) { |
| 402 | return true; |
| 403 | } |
| 404 | |
| 405 | return false; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 406 | } |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 407 | |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 408 | /** |
| 409 | * Link weight function that emphasizes re-use of packet links. |
| 410 | */ |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 411 | private static class OpticalLinkWeight implements LinkWeight { |
| 412 | @Override |
| 413 | public double weight(TopologyEdge edge) { |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 414 | // Ignore inactive links |
Praseed Balakrishnan | 00dd1f9 | 2014-11-19 17:12:36 -0800 | [diff] [blame] | 415 | if (edge.link().state() == Link.State.INACTIVE) { |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 416 | return -1; |
Praseed Balakrishnan | 00dd1f9 | 2014-11-19 17:12:36 -0800 | [diff] [blame] | 417 | } |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 418 | |
| 419 | // Transport links have highest weight |
| 420 | if (edge.link().type() == Link.Type.OPTICAL) { |
| 421 | return 1000; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 422 | } |
Marc De Leenheer | 16f857b | 2015-05-05 20:50:24 -0700 | [diff] [blame^] | 423 | |
| 424 | // Packet links |
| 425 | return 1; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 426 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | } |