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; |
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; |
| 29 | import org.onosproject.net.Host; |
| 30 | import org.onosproject.net.Link; |
| 31 | import org.onosproject.net.Path; |
| 32 | import org.onosproject.net.host.HostService; |
| 33 | import org.onosproject.net.intent.HostToHostIntent; |
| 34 | import org.onosproject.net.intent.Intent; |
| 35 | import org.onosproject.net.intent.IntentEvent; |
| 36 | import org.onosproject.net.intent.IntentListener; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 37 | import org.onosproject.net.intent.IntentService; |
| 38 | import org.onosproject.net.intent.IntentState; |
| 39 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 40 | import org.onosproject.net.intent.PointToPointIntent; |
| 41 | import org.onosproject.net.topology.LinkWeight; |
| 42 | import org.onosproject.net.topology.PathService; |
| 43 | import org.onosproject.net.topology.TopologyEdge; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 44 | import org.slf4j.Logger; |
| 45 | import org.slf4j.LoggerFactory; |
| 46 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 47 | import java.util.Iterator; |
| 48 | import java.util.List; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 49 | import java.util.Map; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 50 | import java.util.Set; |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 51 | import java.util.concurrent.ConcurrentHashMap; |
| 52 | |
| 53 | import static org.onosproject.net.intent.IntentState.INSTALLED; |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 54 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 55 | /** |
| 56 | * OpticalPathProvisioner listens event notifications from the Intent F/W. |
| 57 | * It generates one or more opticalConnectivityIntent(s) and submits (or withdraws) to Intent F/W |
| 58 | * for adding/releasing capacity at the packet layer. |
| 59 | * |
| 60 | */ |
| 61 | |
| 62 | @Component(immediate = true) |
| 63 | public class OpticalPathProvisioner { |
| 64 | |
| 65 | protected static final Logger log = LoggerFactory |
| 66 | .getLogger(OpticalPathProvisioner.class); |
| 67 | |
| 68 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 69 | private IntentService intentService; |
| 70 | |
| 71 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 72 | protected PathService pathService; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 73 | |
| 74 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 75 | protected CoreService coreService; |
| 76 | |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 78 | protected HostService hostService; |
| 79 | |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 80 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 81 | protected MastershipService mastershipService; |
| 82 | |
| 83 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 84 | protected ClusterService clusterService; |
| 85 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 86 | private ApplicationId appId; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 87 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 88 | // TODO use a shared map for distributed operation |
| 89 | protected final Map<ConnectPoint, OpticalConnectivityIntent> inStatusTportMap = |
| 90 | new ConcurrentHashMap<>(); |
| 91 | protected final Map<ConnectPoint, OpticalConnectivityIntent> outStatusTportMap = |
| 92 | new ConcurrentHashMap<>(); |
| 93 | |
| 94 | protected final Map<ConnectPoint, Map<ConnectPoint, Intent>> intentMap = |
| 95 | new ConcurrentHashMap<>(); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 96 | |
| 97 | private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner(); |
| 98 | |
| 99 | @Activate |
| 100 | protected void activate() { |
| 101 | intentService.addListener(pathProvisioner); |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 102 | appId = coreService.registerApplication("org.onosproject.optical"); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 103 | initTport(); |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 104 | log.info("Starting optical path provisioning..."); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 107 | protected void initTport() { |
| 108 | inStatusTportMap.clear(); |
| 109 | outStatusTportMap.clear(); |
| 110 | for (Intent intent : intentService.getIntents()) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 111 | if (intentService.getIntentState(intent.key()) == INSTALLED) { |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 112 | if (intent instanceof OpticalConnectivityIntent) { |
| 113 | inStatusTportMap.put(((OpticalConnectivityIntent) intent).getSrc(), |
| 114 | (OpticalConnectivityIntent) intent); |
| 115 | outStatusTportMap.put(((OpticalConnectivityIntent) intent).getDst(), |
| 116 | (OpticalConnectivityIntent) intent); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 122 | protected void deactivate() { |
| 123 | intentService.removeListener(pathProvisioner); |
| 124 | } |
| 125 | |
| 126 | public class InternalOpticalPathProvisioner implements IntentListener { |
| 127 | @Override |
| 128 | public void event(IntentEvent event) { |
| 129 | switch (event.type()) { |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 130 | case INSTALL_REQ: |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 131 | break; |
| 132 | case INSTALLED: |
| 133 | break; |
| 134 | case FAILED: |
weibit | 50eb95b | 2014-10-25 21:47:54 -0700 | [diff] [blame] | 135 | log.info("packet intent {} failed, calling optical path provisioning APP.", event.subject()); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 136 | setupLightpath(event.subject()); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 137 | break; |
| 138 | case WITHDRAWN: |
| 139 | log.info("intent {} withdrawn.", event.subject()); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 140 | //FIXME |
| 141 | //teardownLightpath(event.subject()); |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 142 | break; |
| 143 | default: |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 148 | private void reserveTport(Intent intent) { |
| 149 | // TODO move to resourceManager |
| 150 | if (intent instanceof OpticalConnectivityIntent) { |
| 151 | OpticalConnectivityIntent opticalIntent = |
| 152 | (OpticalConnectivityIntent) intent; |
| 153 | if (inStatusTportMap.containsKey(opticalIntent.getSrc()) || |
| 154 | outStatusTportMap.containsKey(opticalIntent.getDst())) { |
| 155 | //TODO throw an exception, perhaps |
| 156 | log.warn("Overlapping reservation: {}", opticalIntent); |
| 157 | } |
| 158 | inStatusTportMap.put(opticalIntent.getSrc(), opticalIntent); |
| 159 | outStatusTportMap.put(opticalIntent.getDst(), opticalIntent); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Registers an intent from src to dst. |
| 165 | * @param src source point |
| 166 | * @param dst destination point |
| 167 | * @param intent intent to be registered |
| 168 | * @return true if intent has not been previously added, false otherwise |
| 169 | */ |
| 170 | private boolean addIntent(ConnectPoint src, ConnectPoint dst, Intent intent) { |
| 171 | Map<ConnectPoint, Intent> srcMap = intentMap.get(src); |
| 172 | if (srcMap == null) { |
| 173 | srcMap = new ConcurrentHashMap<>(); |
| 174 | intentMap.put(src, srcMap); |
| 175 | } |
| 176 | if (srcMap.containsKey(dst)) { |
| 177 | return false; |
| 178 | } else { |
| 179 | srcMap.put(dst, intent); |
| 180 | return true; |
| 181 | } |
| 182 | } |
| 183 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 184 | private void setupLightpath(Intent intent) { |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 185 | // TODO change the coordination approach between packet intents and optical intents |
| 186 | // Low speed LLDP may cause multiple calls which are not expected |
| 187 | |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 188 | if (!IntentState.FAILED.equals(intentService.getIntentState(intent.key()))) { |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 189 | return; |
Marc De Leenheer | b473b9d | 2015-02-06 15:21:03 -0800 | [diff] [blame] | 190 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 191 | |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 192 | NodeId localNode = clusterService.getLocalNode().id(); |
| 193 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 194 | List<Intent> intents = Lists.newArrayList(); |
| 195 | if (intent instanceof HostToHostIntent) { |
| 196 | HostToHostIntent hostToHostIntent = (HostToHostIntent) intent; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 197 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 198 | Host one = hostService.getHost(hostToHostIntent.one()); |
| 199 | Host two = hostService.getHost(hostToHostIntent.two()); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 200 | if (one == null || two == null) { |
| 201 | return; //FIXME |
| 202 | } |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 203 | |
| 204 | // Ignore if we're not the master for the intent's origin device |
| 205 | NodeId sourceMaster = mastershipService.getMasterFor(one.location().deviceId()); |
| 206 | if (!localNode.equals(sourceMaster)) { |
| 207 | return; |
| 208 | } |
| 209 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 210 | // provision both directions |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 211 | intents.addAll(getOpticalPath(one.location(), two.location())); |
Brian O'Connor | 025fb44 | 2014-12-08 20:02:15 -0800 | [diff] [blame] | 212 | // note: bi-directional intent is set up |
| 213 | // HostToHost Intent requires symmetric path! |
| 214 | //intents.addAll(getOpticalPath(two.location(), one.location())); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 215 | } else if (intent instanceof PointToPointIntent) { |
| 216 | PointToPointIntent p2pIntent = (PointToPointIntent) intent; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 217 | |
| 218 | // Ignore if we're not the master for the intent's origin device |
| 219 | NodeId sourceMaster = mastershipService.getMasterFor(p2pIntent.ingressPoint().deviceId()); |
| 220 | if (!localNode.equals(sourceMaster)) { |
| 221 | return; |
| 222 | } |
| 223 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 224 | intents.addAll(getOpticalPath(p2pIntent.ingressPoint(), p2pIntent.egressPoint())); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 225 | } else { |
| 226 | log.info("Unsupported intent type: {}", intent.getClass()); |
| 227 | } |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 228 | |
Brian O'Connor | 03406a4 | 2015-02-03 17:28:57 -0800 | [diff] [blame] | 229 | // Create the intents |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 230 | for (Intent i : intents) { |
| 231 | // 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] | 232 | // we may want to allow this carefully in future to increase capacity |
| 233 | if (i instanceof OpticalConnectivityIntent) { |
| 234 | OpticalConnectivityIntent oi = (OpticalConnectivityIntent) i; |
| 235 | if (addIntent(oi.getSrc(), oi.getDst(), oi)) { |
Brian O'Connor | 03406a4 | 2015-02-03 17:28:57 -0800 | [diff] [blame] | 236 | intentService.submit(i); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 237 | reserveTport(i); |
| 238 | } |
| 239 | } else { |
| 240 | log.warn("Invalid intent type: {} for {}", i.getClass(), i); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 241 | } |
| 242 | } |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 245 | private List<Intent> getOpticalPath(ConnectPoint ingress, ConnectPoint egress) { |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 246 | Set<Path> paths = pathService.getPaths(ingress.deviceId(), |
| 247 | egress.deviceId(), |
| 248 | new OpticalLinkWeight()); |
| 249 | |
| 250 | if (paths.isEmpty()) { |
| 251 | return Lists.newArrayList(); |
weibit | 7e58346 | 2014-10-23 10:14:05 -0700 | [diff] [blame] | 252 | } |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 253 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 254 | List<Intent> connectionList = Lists.newArrayList(); |
| 255 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 256 | Iterator<Path> itrPath = paths.iterator(); |
| 257 | while (itrPath.hasNext()) { |
| 258 | boolean usedTportFound = false; |
| 259 | Path nextPath = itrPath.next(); |
| 260 | log.info(nextPath.links().toString()); // TODO drop log level |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 261 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 262 | Iterator<Link> itrLink = nextPath.links().iterator(); |
| 263 | while (itrLink.hasNext()) { |
| 264 | ConnectPoint srcWdmPoint, dstWdmPoint; |
| 265 | Link link1 = itrLink.next(); |
| 266 | if (!isOpticalLink(link1)) { |
| 267 | continue; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 268 | } else { |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 269 | srcWdmPoint = link1.dst(); |
| 270 | dstWdmPoint = srcWdmPoint; |
| 271 | } |
| 272 | |
| 273 | while (itrLink.hasNext()) { |
| 274 | Link link2 = itrLink.next(); |
| 275 | if (isOpticalLink(link2)) { |
| 276 | dstWdmPoint = link2.src(); |
| 277 | } else { |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | if (inStatusTportMap.get(srcWdmPoint) != null || |
| 283 | outStatusTportMap.get(dstWdmPoint) != null) { |
| 284 | usedTportFound = true; |
| 285 | // log.info("used ConnectPoint {} to {} were found", srcWdmPoint, dstWdmPoint); |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 286 | break; |
| 287 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 288 | |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 289 | Intent opticalIntent = OpticalConnectivityIntent.builder() |
| 290 | .appId(appId) |
| 291 | .src(srcWdmPoint) |
| 292 | .dst(dstWdmPoint) |
| 293 | .build(); |
| 294 | Intent opticalIntent2 = OpticalConnectivityIntent.builder() |
| 295 | .appId(appId) |
| 296 | .src(dstWdmPoint) |
| 297 | .dst(srcWdmPoint) |
| 298 | .build(); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 299 | log.info("Creating optical intent from {} to {}", srcWdmPoint, dstWdmPoint); |
Brian O'Connor | 025fb44 | 2014-12-08 20:02:15 -0800 | [diff] [blame] | 300 | log.info("Creating optical intent from {} to {}", dstWdmPoint, srcWdmPoint); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 301 | connectionList.add(opticalIntent); |
Brian O'Connor | 025fb44 | 2014-12-08 20:02:15 -0800 | [diff] [blame] | 302 | connectionList.add(opticalIntent2); |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 303 | |
| 304 | break; |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 305 | } |
| 306 | |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 307 | if (!usedTportFound) { |
| 308 | break; |
| 309 | } else { |
| 310 | // reset the connection list |
| 311 | connectionList = Lists.newArrayList(); |
| 312 | } |
| 313 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 314 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 315 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 316 | return connectionList; |
| 317 | } |
| 318 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 319 | private void teardownLightpath(Intent intent) { |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 320 | /* FIXME this command doesn't make much sense. we need to define the semantics |
| 321 | // TODO move to resourceManager |
| 322 | if (intent instanceof OpticalConnectivityIntent) { |
| 323 | inStatusTportMap.remove(((OpticalConnectivityIntent) intent).getSrc()); |
| 324 | outStatusTportMap.remove(((OpticalConnectivityIntent) intent).getDst()); |
| 325 | // TODO tear down the idle lightpath if the utilization is zero. |
| 326 | |
| 327 | } |
| 328 | */ //end-FIXME |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 329 | } |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 330 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 331 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 332 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 333 | private static boolean isOpticalLink(Link link) { |
| 334 | boolean isOptical = false; |
| 335 | Link.Type lt = link.type(); |
| 336 | if (lt == Link.Type.OPTICAL) { |
| 337 | isOptical = true; |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 338 | } |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 339 | return isOptical; |
| 340 | } |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 341 | |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 342 | private static class OpticalLinkWeight implements LinkWeight { |
| 343 | @Override |
| 344 | public double weight(TopologyEdge edge) { |
Praseed Balakrishnan | 00dd1f9 | 2014-11-19 17:12:36 -0800 | [diff] [blame] | 345 | if (edge.link().state() == Link.State.INACTIVE) { |
| 346 | return -1; // ignore inactive links |
| 347 | } |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 348 | if (isOpticalLink(edge.link())) { |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 349 | return 1000; // optical links |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 350 | } else { |
Brian O'Connor | c7bdd8c | 2014-12-08 01:29:53 -0800 | [diff] [blame] | 351 | return 1; // packet links |
Brian O'Connor | 772852a | 2014-11-17 15:51:19 -0800 | [diff] [blame] | 352 | } |
| 353 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | } |