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