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.provider.lldp.impl; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableMap; |
| 19 | import com.google.common.collect.ImmutableSet; |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 20 | import com.google.common.collect.Maps; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Modified; |
| 25 | import org.apache.felix.scr.annotations.Property; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 26 | import org.apache.felix.scr.annotations.Reference; |
| 27 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 28 | import org.onlab.packet.Ethernet; |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 29 | import org.onosproject.cfg.ComponentConfigService; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 32 | import org.onosproject.mastership.MastershipEvent; |
| 33 | import org.onosproject.mastership.MastershipListener; |
| 34 | import org.onosproject.mastership.MastershipService; |
| 35 | import org.onosproject.net.ConnectPoint; |
| 36 | import org.onosproject.net.Device; |
| 37 | import org.onosproject.net.DeviceId; |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 38 | import org.onosproject.net.LinkKey; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 39 | import org.onosproject.net.Port; |
| 40 | import org.onosproject.net.device.DeviceEvent; |
| 41 | import org.onosproject.net.device.DeviceListener; |
| 42 | import org.onosproject.net.device.DeviceService; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 43 | import org.onosproject.net.flow.DefaultTrafficSelector; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 44 | import org.onosproject.net.flow.TrafficSelector; |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 45 | import org.onosproject.net.link.DefaultLinkDescription; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 46 | import org.onosproject.net.link.LinkProvider; |
| 47 | import org.onosproject.net.link.LinkProviderRegistry; |
| 48 | import org.onosproject.net.link.LinkProviderService; |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 49 | import org.onosproject.net.link.LinkService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 50 | import org.onosproject.net.packet.PacketContext; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 51 | import org.onosproject.net.packet.PacketPriority; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 52 | import org.onosproject.net.packet.PacketProcessor; |
| 53 | import org.onosproject.net.packet.PacketService; |
| 54 | import org.onosproject.net.provider.AbstractProvider; |
| 55 | import org.onosproject.net.provider.ProviderId; |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 56 | import org.osgi.service.component.ComponentContext; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 57 | import org.slf4j.Logger; |
| 58 | |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 59 | import java.io.IOException; |
| 60 | import java.util.Dictionary; |
| 61 | import java.util.EnumSet; |
| 62 | import java.util.Map; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 63 | import java.util.Properties; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 64 | import java.util.concurrent.ConcurrentHashMap; |
| 65 | import java.util.concurrent.ScheduledExecutorService; |
| 66 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 67 | import static com.google.common.base.Strings.isNullOrEmpty; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 68 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
| 69 | import static java.util.concurrent.TimeUnit.SECONDS; |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame^] | 70 | import static org.onlab.packet.Ethernet.TYPE_BSN; |
| 71 | import static org.onlab.packet.Ethernet.TYPE_LLDP; |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 72 | import static org.onlab.util.Tools.get; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 73 | import static org.onlab.util.Tools.groupedThreads; |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 74 | import static org.onosproject.net.Link.Type.DIRECT; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 75 | import static org.slf4j.LoggerFactory.getLogger; |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 76 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 77 | /** |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 78 | * Provider which uses LLDP and BDDP packets to detect network infrastructure links. |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 79 | */ |
| 80 | @Component(immediate = true) |
| 81 | public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { |
| 82 | |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 83 | private static final String PROVIDER_NAME = "org.onosproject.provider.lldp"; |
| 84 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 85 | private static final String FORMAT = |
| 86 | "Settings: enabled={}, useBDDP={}, probeRate={}, " + |
| 87 | "staleLinkAge={}, lldpSuppression={}"; |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 88 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 89 | private final Logger log = getLogger(getClass()); |
| 90 | |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 91 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 92 | protected CoreService coreService; |
| 93 | |
| 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 95 | protected LinkProviderRegistry providerRegistry; |
| 96 | |
| 97 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 98 | protected DeviceService deviceService; |
| 99 | |
| 100 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 101 | protected LinkService linkService; |
| 102 | |
| 103 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 104 | protected PacketService packetService; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 105 | |
alshabib | 875d626 | 2014-10-17 16:19:40 -0700 | [diff] [blame] | 106 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 107 | protected MastershipService masterService; |
| 108 | |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 109 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 110 | protected ComponentConfigService cfgService; |
| 111 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 112 | private LinkProviderService providerService; |
| 113 | |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 114 | private ScheduledExecutorService executor; |
| 115 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 116 | // TODO: Add sanity checking for the configurable params based on the delays |
| 117 | private static final long DEVICE_SYNC_DELAY = 5; |
| 118 | private static final long LINK_PRUNER_DELAY = 3; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 119 | |
| 120 | private static final String PROP_ENABLED = "enabled"; |
| 121 | @Property(name = PROP_ENABLED, boolValue = true, |
| 122 | label = "If false, link discovery is disabled") |
| 123 | private boolean enabled = false; |
| 124 | |
| 125 | private static final String PROP_USE_BDDP = "useBDDP"; |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 126 | @Property(name = PROP_USE_BDDP, boolValue = true, |
| 127 | label = "Use BDDP for link discovery") |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 128 | private boolean useBDDP = true; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 129 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 130 | private static final String PROP_PROBE_RATE = "probeRate"; |
| 131 | private static final int DEFAULT_PROBE_RATE = 3_000; |
| 132 | @Property(name = PROP_PROBE_RATE, intValue = DEFAULT_PROBE_RATE, |
| 133 | label = "LLDP and BDDP probe rate specified in millis") |
| 134 | private int probeRate = DEFAULT_PROBE_RATE; |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 135 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 136 | private static final String PROP_STALE_LINK_AGE = "staleLinkAge"; |
| 137 | private static final int DEFAULT_STALE_LINK_AGE = 10_000; |
| 138 | @Property(name = PROP_STALE_LINK_AGE, intValue = DEFAULT_STALE_LINK_AGE, |
| 139 | label = "Number of millis beyond which links will be considered stale") |
| 140 | private int staleLinkAge = DEFAULT_STALE_LINK_AGE; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 141 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 142 | // FIXME: convert to use network config subsystem instead |
| 143 | private static final String PROP_LLDP_SUPPRESSION = "lldpSuppression"; |
| 144 | private static final String DEFAULT_LLDP_SUPPRESSION_CONFIG = "../config/lldp_suppression.json"; |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 145 | @Property(name = PROP_LLDP_SUPPRESSION, value = DEFAULT_LLDP_SUPPRESSION_CONFIG, |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 146 | label = "Path to LLDP suppression configuration file") |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 147 | private String lldpSuppression = DEFAULT_LLDP_SUPPRESSION_CONFIG; |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 148 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 149 | private final DiscoveryContext context = new InternalDiscoveryContext(); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 150 | private final InternalRoleListener roleListener = new InternalRoleListener(); |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 151 | private final InternalDeviceListener deviceListener = new InternalDeviceListener(); |
| 152 | private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor(); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 153 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 154 | // Device link discovery helpers. |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 155 | protected final Map<DeviceId, LinkDiscovery> discoverers = new ConcurrentHashMap<>(); |
| 156 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 157 | // Most recent time a tracked link was seen; links are tracked if their |
| 158 | // destination connection point is mastered by this controller instance. |
| 159 | private final Map<LinkKey, Long> linkTimes = Maps.newConcurrentMap(); |
| 160 | |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 161 | private SuppressionRules rules; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 162 | private ApplicationId appId; |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 163 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 164 | /** |
| 165 | * Creates an OpenFlow link provider. |
| 166 | */ |
| 167 | public LLDPLinkProvider() { |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 168 | super(new ProviderId("lldp", PROVIDER_NAME)); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | @Activate |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 172 | public void activate(ComponentContext context) { |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 173 | cfgService.registerProperties(getClass()); |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 174 | appId = coreService.registerApplication(PROVIDER_NAME); |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 175 | modified(context); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 176 | log.info("Started"); |
| 177 | } |
| 178 | |
| 179 | @Deactivate |
| 180 | public void deactivate() { |
| 181 | cfgService.unregisterProperties(getClass(), false); |
| 182 | disable(); |
| 183 | log.info("Stopped"); |
| 184 | } |
| 185 | |
| 186 | @Modified |
| 187 | public void modified(ComponentContext context) { |
| 188 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 189 | |
| 190 | boolean newEnabled, newUseBddp; |
| 191 | int newProbeRate, newStaleLinkAge; |
| 192 | String newLldpSuppression; |
| 193 | try { |
| 194 | String s = get(properties, PROP_ENABLED); |
| 195 | newEnabled = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim()); |
| 196 | |
| 197 | s = get(properties, PROP_USE_BDDP); |
| 198 | newUseBddp = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim()); |
| 199 | |
| 200 | s = get(properties, PROP_PROBE_RATE); |
| 201 | newProbeRate = isNullOrEmpty(s) ? probeRate : Integer.parseInt(s.trim()); |
| 202 | |
| 203 | s = get(properties, PROP_STALE_LINK_AGE); |
| 204 | newStaleLinkAge = isNullOrEmpty(s) ? staleLinkAge : Integer.parseInt(s.trim()); |
| 205 | |
| 206 | s = get(properties, PROP_LLDP_SUPPRESSION); |
| 207 | newLldpSuppression = isNullOrEmpty(s) ? DEFAULT_LLDP_SUPPRESSION_CONFIG : s; |
| 208 | |
| 209 | } catch (NumberFormatException e) { |
| 210 | log.warn(e.getMessage()); |
| 211 | newEnabled = enabled; |
| 212 | newUseBddp = useBDDP; |
| 213 | newProbeRate = probeRate; |
| 214 | newStaleLinkAge = staleLinkAge; |
| 215 | newLldpSuppression = lldpSuppression; |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 216 | } |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 217 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 218 | boolean wasEnabled = enabled; |
| 219 | |
| 220 | enabled = newEnabled; |
| 221 | useBDDP = newUseBddp; |
| 222 | probeRate = newProbeRate; |
| 223 | staleLinkAge = newStaleLinkAge; |
| 224 | lldpSuppression = newLldpSuppression; |
| 225 | |
| 226 | if (!wasEnabled && enabled) { |
| 227 | enable(); |
| 228 | } else if (wasEnabled && !enabled) { |
| 229 | disable(); |
| 230 | } |
| 231 | |
| 232 | log.info(FORMAT, enabled, useBDDP, probeRate, staleLinkAge, lldpSuppression); |
| 233 | } |
| 234 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 235 | /** |
| 236 | * Enables link discovery processing. |
| 237 | */ |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 238 | private void enable() { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 239 | providerService = providerRegistry.register(this); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 240 | masterService.addListener(roleListener); |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 241 | deviceService.addListener(deviceListener); |
| 242 | packetService.addProcessor(packetProcessor, PacketProcessor.advisor(0)); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 243 | |
Jon Hall | 3edc08a | 2015-09-14 16:59:07 -0700 | [diff] [blame] | 244 | loadSuppressionRules(); |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 245 | loadDevices(); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 246 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 247 | executor = newSingleThreadScheduledExecutor(groupedThreads("onos/link", "discovery-%d")); |
| 248 | executor.scheduleAtFixedRate(new SyncDeviceInfoTask(), |
| 249 | DEVICE_SYNC_DELAY, DEVICE_SYNC_DELAY, SECONDS); |
| 250 | executor.scheduleAtFixedRate(new LinkPrunerTask(), |
| 251 | LINK_PRUNER_DELAY, LINK_PRUNER_DELAY, SECONDS); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 252 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 253 | requestIntercepts(); |
| 254 | } |
| 255 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 256 | /** |
| 257 | * Disables link discovery processing. |
| 258 | */ |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 259 | private void disable() { |
| 260 | withdrawIntercepts(); |
| 261 | |
| 262 | providerRegistry.unregister(this); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 263 | masterService.removeListener(roleListener); |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 264 | deviceService.removeListener(deviceListener); |
| 265 | packetService.removeProcessor(packetProcessor); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 266 | |
| 267 | if (executor != null) { |
| 268 | executor.shutdownNow(); |
| 269 | } |
| 270 | discoverers.values().forEach(LinkDiscovery::stop); |
| 271 | discoverers.clear(); |
| 272 | |
| 273 | providerService = null; |
| 274 | } |
| 275 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 276 | /** |
| 277 | * Loads available devices and registers their ports to be probed. |
| 278 | */ |
| 279 | private void loadDevices() { |
alshabib | 5dc5a34 | 2014-12-03 14:11:16 -0800 | [diff] [blame] | 280 | for (Device device : deviceService.getAvailableDevices()) { |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 281 | if (rules.isSuppressed(device)) { |
| 282 | log.debug("LinkDiscovery from {} disabled by configuration", device.id()); |
| 283 | continue; |
| 284 | } |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 285 | LinkDiscovery ld = new LinkDiscovery(device, context); |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 286 | discoverers.put(device.id(), ld); |
Jonathan Hart | 45066bc | 2015-07-28 11:18:34 -0700 | [diff] [blame] | 287 | addPorts(ld, device.id()); |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 288 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 291 | /** |
| 292 | * Adds ports of the specified device to the specified discovery helper. |
| 293 | */ |
Jonathan Hart | 45066bc | 2015-07-28 11:18:34 -0700 | [diff] [blame] | 294 | private void addPorts(LinkDiscovery discoverer, DeviceId deviceId) { |
| 295 | for (Port p : deviceService.getPorts(deviceId)) { |
| 296 | if (rules.isSuppressed(p)) { |
| 297 | continue; |
| 298 | } |
| 299 | if (!p.number().isLogical()) { |
| 300 | discoverer.addPort(p); |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 305 | |
| 306 | /** |
| 307 | * Loads LLDP suppression rules. |
| 308 | */ |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 309 | private void loadSuppressionRules() { |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 310 | // FIXME: convert to use network configuration |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 311 | SuppressionRulesStore store = new SuppressionRulesStore(lldpSuppression); |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 312 | try { |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 313 | log.info("Reading suppression rules from {}", lldpSuppression); |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 314 | rules = store.read(); |
| 315 | } catch (IOException e) { |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 316 | log.info("Failed to load {}, using built-in rules", lldpSuppression); |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 317 | // default rule to suppress ROADM to maintain compatibility |
| 318 | rules = new SuppressionRules(ImmutableSet.of(), |
| 319 | EnumSet.of(Device.Type.ROADM), |
| 320 | ImmutableMap.of()); |
| 321 | } |
| 322 | |
| 323 | // should refresh discoverers when we need dynamic reconfiguration |
| 324 | } |
| 325 | |
Charles M.C. Chan | e148de8 | 2015-05-06 12:38:21 +0800 | [diff] [blame] | 326 | /** |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 327 | * Requests packet intercepts. |
Charles M.C. Chan | e148de8 | 2015-05-06 12:38:21 +0800 | [diff] [blame] | 328 | */ |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 329 | private void requestIntercepts() { |
| 330 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame^] | 331 | selector.matchEthType(TYPE_LLDP); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 332 | packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 333 | |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame^] | 334 | selector.matchEthType(TYPE_BSN); |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 335 | if (useBDDP) { |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 336 | packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); |
| 337 | } else { |
| 338 | packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 342 | /** |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 343 | * Withdraws packet intercepts. |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 344 | */ |
| 345 | private void withdrawIntercepts() { |
| 346 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame^] | 347 | selector.matchEthType(TYPE_LLDP); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 348 | packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame^] | 349 | selector.matchEthType(TYPE_BSN); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 350 | packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); |
| 351 | } |
| 352 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 353 | /** |
| 354 | * Processes device mastership role changes. |
| 355 | */ |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 356 | private class InternalRoleListener implements MastershipListener { |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 357 | @Override |
| 358 | public void event(MastershipEvent event) { |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 359 | if (MastershipEvent.Type.BACKUPS_CHANGED.equals(event.type())) { |
| 360 | // only need new master events |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | DeviceId deviceId = event.subject(); |
| 365 | Device device = deviceService.getDevice(deviceId); |
| 366 | if (device == null) { |
Thomas Vachuska | 3358af2 | 2015-05-19 18:40:34 -0700 | [diff] [blame] | 367 | log.debug("Device {} doesn't exist, or isn't there yet", deviceId); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 368 | return; |
| 369 | } |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 370 | if (rules.isSuppressed(device)) { |
| 371 | return; |
| 372 | } |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 373 | discoverers.computeIfAbsent(deviceId, k -> new LinkDiscovery(device, context)); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 377 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 378 | /** |
| 379 | * Processes device events. |
| 380 | */ |
| 381 | private class InternalDeviceListener implements DeviceListener { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 382 | @Override |
| 383 | public void event(DeviceEvent event) { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 384 | LinkDiscovery ld; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 385 | Device device = event.subject(); |
alshabib | acd9183 | 2014-10-17 14:38:41 -0700 | [diff] [blame] | 386 | Port port = event.port(); |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 387 | if (device == null) { |
| 388 | log.error("Device is null."); |
| 389 | return; |
| 390 | } |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 391 | log.trace("{} {} {}", event.type(), event.subject(), event); |
Yuta HIGUCHI | d19f670 | 2014-10-31 15:23:25 -0700 | [diff] [blame] | 392 | final DeviceId deviceId = device.id(); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 393 | switch (event.type()) { |
| 394 | case DEVICE_ADDED: |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 395 | case DEVICE_UPDATED: |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 396 | synchronized (discoverers) { |
| 397 | ld = discoverers.get(deviceId); |
| 398 | if (ld == null) { |
| 399 | if (rules.isSuppressed(device)) { |
| 400 | log.debug("LinkDiscovery from {} disabled by configuration", device.id()); |
| 401 | return; |
| 402 | } |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 403 | log.debug("Device added ({}) {}", event.type(), deviceId); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 404 | discoverers.put(deviceId, new LinkDiscovery(device, context)); |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 405 | } else { |
| 406 | if (ld.isStopped()) { |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 407 | log.debug("Device restarted ({}) {}", event.type(), deviceId); |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 408 | ld.start(); |
| 409 | } |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 410 | } |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 411 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 412 | break; |
| 413 | case PORT_ADDED: |
| 414 | case PORT_UPDATED: |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 415 | if (port.isEnabled()) { |
Yuta HIGUCHI | d19f670 | 2014-10-31 15:23:25 -0700 | [diff] [blame] | 416 | ld = discoverers.get(deviceId); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 417 | if (ld == null) { |
| 418 | return; |
| 419 | } |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 420 | if (rules.isSuppressed(port)) { |
| 421 | log.debug("LinkDiscovery from {}@{} disabled by configuration", |
| 422 | port.number(), device.id()); |
| 423 | return; |
| 424 | } |
Yuta HIGUCHI | 00b476f | 2014-10-25 21:33:07 -0700 | [diff] [blame] | 425 | if (!port.number().isLogical()) { |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 426 | log.debug("Port added {}", port); |
Yuta HIGUCHI | 00b476f | 2014-10-25 21:33:07 -0700 | [diff] [blame] | 427 | ld.addPort(port); |
| 428 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 429 | } else { |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 430 | log.debug("Port down {}", port); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 431 | ConnectPoint point = new ConnectPoint(deviceId, port.number()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 432 | providerService.linksVanished(point); |
| 433 | } |
| 434 | break; |
| 435 | case PORT_REMOVED: |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 436 | log.debug("Port removed {}", port); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 437 | ConnectPoint point = new ConnectPoint(deviceId, port.number()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 438 | providerService.linksVanished(point); |
alshabib | 4785eec | 2014-12-04 16:45:45 -0800 | [diff] [blame] | 439 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 440 | break; |
| 441 | case DEVICE_REMOVED: |
| 442 | case DEVICE_SUSPENDED: |
Yuta HIGUCHI | d19f670 | 2014-10-31 15:23:25 -0700 | [diff] [blame] | 443 | log.debug("Device removed {}", deviceId); |
| 444 | ld = discoverers.get(deviceId); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 445 | if (ld == null) { |
| 446 | return; |
| 447 | } |
| 448 | ld.stop(); |
Yuta HIGUCHI | d19f670 | 2014-10-31 15:23:25 -0700 | [diff] [blame] | 449 | providerService.linksVanished(deviceId); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 450 | break; |
| 451 | case DEVICE_AVAILABILITY_CHANGED: |
Yuta HIGUCHI | d19f670 | 2014-10-31 15:23:25 -0700 | [diff] [blame] | 452 | ld = discoverers.get(deviceId); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 453 | if (ld == null) { |
| 454 | return; |
| 455 | } |
Yuta HIGUCHI | d19f670 | 2014-10-31 15:23:25 -0700 | [diff] [blame] | 456 | if (deviceService.isAvailable(deviceId)) { |
| 457 | log.debug("Device up {}", deviceId); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 458 | ld.start(); |
| 459 | } else { |
Yuta HIGUCHI | d19f670 | 2014-10-31 15:23:25 -0700 | [diff] [blame] | 460 | providerService.linksVanished(deviceId); |
| 461 | log.debug("Device down {}", deviceId); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 462 | ld.stop(); |
| 463 | } |
| 464 | break; |
Jonathan Hart | 9de692c | 2015-04-23 11:45:47 -0700 | [diff] [blame] | 465 | case PORT_STATS_UPDATED: |
| 466 | break; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 467 | default: |
| 468 | log.debug("Unknown event {}", event); |
| 469 | } |
| 470 | } |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 471 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 472 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 473 | /** |
| 474 | * Processes incoming packets. |
| 475 | */ |
| 476 | private class InternalPacketProcessor implements PacketProcessor { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 477 | @Override |
| 478 | public void process(PacketContext context) { |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame^] | 479 | if (context == null || context.isHandled()) { |
alshabib | 4a179dc | 2014-10-17 17:17:01 -0700 | [diff] [blame] | 480 | return; |
| 481 | } |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame^] | 482 | |
| 483 | Ethernet eth = context.inPacket().parsed(); |
| 484 | if (eth == null || (eth.getEtherType() != TYPE_LLDP && eth.getEtherType() != TYPE_BSN)) { |
| 485 | return; |
| 486 | } |
| 487 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 488 | LinkDiscovery ld = discoverers.get(context.inPacket().receivedFrom().deviceId()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 489 | if (ld == null) { |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | if (ld.handleLLDP(context)) { |
| 494 | context.block(); |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 499 | /** |
| 500 | * Auxiliary task to keep device ports up to date. |
| 501 | */ |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 502 | private final class SyncDeviceInfoTask implements Runnable { |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 503 | @Override |
| 504 | public void run() { |
| 505 | if (Thread.currentThread().isInterrupted()) { |
| 506 | log.info("Interrupted, quitting"); |
| 507 | return; |
| 508 | } |
| 509 | // check what deviceService sees, to see if we are missing anything |
| 510 | try { |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 511 | for (Device dev : deviceService.getDevices()) { |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 512 | if (rules.isSuppressed(dev)) { |
| 513 | continue; |
| 514 | } |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 515 | DeviceId did = dev.id(); |
| 516 | synchronized (discoverers) { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 517 | LinkDiscovery ld = discoverers |
| 518 | .computeIfAbsent(did, k -> new LinkDiscovery(dev, context)); |
| 519 | addPorts(ld, did); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | } catch (Exception e) { |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 523 | // Catch all exceptions to avoid task being suppressed |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 524 | log.error("Exception thrown during synchronization process", e); |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 529 | /** |
| 530 | * Auxiliary task for pruning stale links. |
| 531 | */ |
| 532 | private class LinkPrunerTask implements Runnable { |
| 533 | @Override |
| 534 | public void run() { |
| 535 | if (Thread.currentThread().isInterrupted()) { |
| 536 | log.info("Interrupted, quitting"); |
| 537 | return; |
| 538 | } |
| 539 | |
| 540 | try { |
| 541 | // TODO: There is still a slight possibility of mastership |
| 542 | // change occurring right with link going stale. This will |
| 543 | // result in the stale link not being pruned. |
| 544 | Maps.filterEntries(linkTimes, e -> { |
| 545 | if (!masterService.isLocalMaster(e.getKey().dst().deviceId())) { |
| 546 | return true; |
| 547 | } |
| 548 | if (isStale(e.getValue())) { |
| 549 | providerService.linkVanished(new DefaultLinkDescription(e.getKey().src(), |
| 550 | e.getKey().dst(), |
| 551 | DIRECT)); |
| 552 | return true; |
| 553 | } |
| 554 | return false; |
| 555 | }).clear(); |
| 556 | |
| 557 | } catch (Exception e) { |
| 558 | // Catch all exceptions to avoid task being suppressed |
| 559 | log.error("Exception thrown during link pruning process", e); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | private boolean isStale(long lastSeen) { |
| 564 | return lastSeen < System.currentTimeMillis() - staleLinkAge; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * Provides processing context for the device link discovery helpers. |
| 570 | */ |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 571 | private class InternalDiscoveryContext implements DiscoveryContext { |
| 572 | @Override |
| 573 | public MastershipService mastershipService() { |
| 574 | return masterService; |
| 575 | } |
| 576 | |
| 577 | @Override |
| 578 | public LinkProviderService providerService() { |
| 579 | return providerService; |
| 580 | } |
| 581 | |
| 582 | @Override |
| 583 | public PacketService packetService() { |
| 584 | return packetService; |
| 585 | } |
| 586 | |
| 587 | @Override |
| 588 | public long probeRate() { |
| 589 | return probeRate; |
| 590 | } |
| 591 | |
| 592 | @Override |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 593 | public boolean useBDDP() { |
| 594 | return useBDDP; |
| 595 | } |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 596 | |
| 597 | @Override |
| 598 | public void touchLink(LinkKey key) { |
| 599 | linkTimes.put(key, System.currentTimeMillis()); |
| 600 | } |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 601 | } |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 602 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 603 | } |