Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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 | |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 18 | import java.util.Dictionary; |
| 19 | import java.util.EnumSet; |
Jon Hall | 125c3f2 | 2017-08-09 13:46:28 -0700 | [diff] [blame] | 20 | import java.util.LinkedList; |
| 21 | import java.util.List; |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 22 | import java.util.Map; |
| 23 | import java.util.Optional; |
| 24 | import java.util.Properties; |
| 25 | import java.util.Set; |
| 26 | import java.util.concurrent.ConcurrentHashMap; |
| 27 | import java.util.concurrent.ExecutorService; |
| 28 | import java.util.concurrent.ScheduledExecutorService; |
| 29 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 30 | import org.apache.felix.scr.annotations.Activate; |
| 31 | import org.apache.felix.scr.annotations.Component; |
| 32 | import org.apache.felix.scr.annotations.Deactivate; |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 33 | import org.apache.felix.scr.annotations.Modified; |
| 34 | import org.apache.felix.scr.annotations.Property; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 35 | import org.apache.felix.scr.annotations.Reference; |
| 36 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 37 | import org.onlab.packet.Ethernet; |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 38 | import org.onosproject.cfg.ComponentConfigService; |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 39 | import org.onosproject.cluster.ClusterMetadataService; |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 40 | import org.onosproject.cluster.ClusterService; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 41 | import org.onosproject.core.ApplicationId; |
| 42 | import org.onosproject.core.CoreService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 43 | import org.onosproject.mastership.MastershipEvent; |
| 44 | import org.onosproject.mastership.MastershipListener; |
| 45 | import org.onosproject.mastership.MastershipService; |
| 46 | import org.onosproject.net.ConnectPoint; |
| 47 | import org.onosproject.net.Device; |
| 48 | import org.onosproject.net.DeviceId; |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 49 | import org.onosproject.net.LinkKey; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 50 | import org.onosproject.net.Port; |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 51 | import org.onosproject.net.config.ConfigFactory; |
| 52 | import org.onosproject.net.config.NetworkConfigEvent; |
| 53 | import org.onosproject.net.config.NetworkConfigListener; |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 54 | import org.onosproject.net.config.NetworkConfigRegistry; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 55 | import org.onosproject.net.device.DeviceEvent; |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 56 | import org.onosproject.net.device.DeviceEvent.Type; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 57 | import org.onosproject.net.device.DeviceListener; |
| 58 | import org.onosproject.net.device.DeviceService; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 59 | import org.onosproject.net.flow.DefaultTrafficSelector; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 60 | import org.onosproject.net.flow.TrafficSelector; |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 61 | import org.onosproject.net.link.DefaultLinkDescription; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 62 | import org.onosproject.net.link.LinkProviderRegistry; |
| 63 | import org.onosproject.net.link.LinkProviderService; |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 64 | import org.onosproject.net.link.LinkService; |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 65 | import org.onosproject.net.link.ProbedLinkProvider; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 66 | import org.onosproject.net.packet.PacketContext; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 67 | import org.onosproject.net.packet.PacketPriority; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 68 | import org.onosproject.net.packet.PacketProcessor; |
| 69 | import org.onosproject.net.packet.PacketService; |
| 70 | import org.onosproject.net.provider.AbstractProvider; |
| 71 | import org.onosproject.net.provider.ProviderId; |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 72 | import org.onosproject.provider.lldpcommon.LinkDiscovery; |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 73 | import org.onosproject.provider.lldpcommon.LinkDiscoveryContext; |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 74 | import org.osgi.service.component.ComponentContext; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 75 | import org.slf4j.Logger; |
| 76 | |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 77 | import com.google.common.collect.ImmutableMap; |
| 78 | import com.google.common.collect.ImmutableSet; |
| 79 | import com.google.common.collect.Maps; |
Marc De Leenheer | 0bfc2a1 | 2016-02-02 22:46:27 -0800 | [diff] [blame] | 80 | |
| 81 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 82 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
| 83 | import static java.util.concurrent.TimeUnit.SECONDS; |
| 84 | import static org.onlab.packet.Ethernet.TYPE_BSN; |
| 85 | import static org.onlab.packet.Ethernet.TYPE_LLDP; |
| 86 | import static org.onlab.util.Tools.get; |
| 87 | import static org.onlab.util.Tools.groupedThreads; |
Marc De Leenheer | 0bfc2a1 | 2016-02-02 22:46:27 -0800 | [diff] [blame] | 88 | import static org.onosproject.net.Link.Type.DIRECT; |
| 89 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
| 90 | import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY; |
| 91 | import static org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY; |
| 92 | import static org.slf4j.LoggerFactory.getLogger; |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 93 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 94 | /** |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 95 | * Provider which uses LLDP and BDDP packets to detect network infrastructure links. |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 96 | */ |
| 97 | @Component(immediate = true) |
Ayaka Koshibe | 4822922 | 2016-05-16 18:04:26 -0700 | [diff] [blame] | 98 | public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProvider { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 99 | |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 100 | private static final String PROVIDER_NAME = "org.onosproject.provider.lldp"; |
| 101 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 102 | private static final String FORMAT = |
| 103 | "Settings: enabled={}, useBDDP={}, probeRate={}, " + |
Samuel Jero | 31e16f5 | 2018-09-21 10:34:28 -0400 | [diff] [blame] | 104 | "staleLinkAge={}, maxLLDPage={}"; |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 105 | |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 106 | // When a Device/Port has this annotation, do not send out LLDP/BDDP |
| 107 | public static final String NO_LLDP = "no-lldp"; |
| 108 | |
Thomas Vachuska | aad8b1d | 2015-12-11 10:36:53 -0800 | [diff] [blame] | 109 | private static final int MAX_RETRIES = 5; |
| 110 | private static final int RETRY_DELAY = 1_000; // millis |
| 111 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 112 | private final Logger log = getLogger(getClass()); |
| 113 | |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 114 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 115 | protected CoreService coreService; |
| 116 | |
| 117 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 118 | protected LinkProviderRegistry providerRegistry; |
| 119 | |
| 120 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 121 | protected DeviceService deviceService; |
| 122 | |
| 123 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 124 | protected LinkService linkService; |
| 125 | |
| 126 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 127 | protected PacketService packetService; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 128 | |
alshabib | 875d626 | 2014-10-17 16:19:40 -0700 | [diff] [blame] | 129 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 130 | protected MastershipService masterService; |
| 131 | |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 132 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 133 | protected ComponentConfigService cfgService; |
| 134 | |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 135 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 136 | protected ClusterService clusterService; |
| 137 | |
| 138 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 139 | protected NetworkConfigRegistry cfgRegistry; |
| 140 | |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 141 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 142 | protected ClusterMetadataService clusterMetadataService; |
| 143 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 144 | private LinkProviderService providerService; |
| 145 | |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 146 | private ScheduledExecutorService executor; |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 147 | protected ExecutorService eventExecutor; |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 148 | |
Ray Milkey | e80e18f | 2016-06-02 16:44:14 -0700 | [diff] [blame] | 149 | private boolean shuttingDown = false; |
| 150 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 151 | // TODO: Add sanity checking for the configurable params based on the delays |
| 152 | private static final long DEVICE_SYNC_DELAY = 5; |
| 153 | private static final long LINK_PRUNER_DELAY = 3; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 154 | |
| 155 | private static final String PROP_ENABLED = "enabled"; |
| 156 | @Property(name = PROP_ENABLED, boolValue = true, |
| 157 | label = "If false, link discovery is disabled") |
| 158 | private boolean enabled = false; |
| 159 | |
| 160 | private static final String PROP_USE_BDDP = "useBDDP"; |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 161 | @Property(name = PROP_USE_BDDP, boolValue = true, |
| 162 | label = "Use BDDP for link discovery") |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 163 | private boolean useBddp = true; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 164 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 165 | private static final String PROP_PROBE_RATE = "probeRate"; |
Thomas Vachuska | 9e51fd0 | 2016-01-04 16:51:28 -0800 | [diff] [blame] | 166 | private static final int DEFAULT_PROBE_RATE = 3000; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 167 | @Property(name = PROP_PROBE_RATE, intValue = DEFAULT_PROBE_RATE, |
| 168 | label = "LLDP and BDDP probe rate specified in millis") |
| 169 | private int probeRate = DEFAULT_PROBE_RATE; |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 170 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 171 | private static final String PROP_STALE_LINK_AGE = "staleLinkAge"; |
Thomas Vachuska | 9e51fd0 | 2016-01-04 16:51:28 -0800 | [diff] [blame] | 172 | private static final int DEFAULT_STALE_LINK_AGE = 10000; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 173 | @Property(name = PROP_STALE_LINK_AGE, intValue = DEFAULT_STALE_LINK_AGE, |
| 174 | label = "Number of millis beyond which links will be considered stale") |
| 175 | private int staleLinkAge = DEFAULT_STALE_LINK_AGE; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 176 | |
Samuel Jero | 31e16f5 | 2018-09-21 10:34:28 -0400 | [diff] [blame] | 177 | private static final String PROP_DISCOVERY_DELAY = "maxLLDPAge"; |
| 178 | private static final int DEFAULT_DISCOVERY_DELAY = 1000; |
| 179 | @Property(name = PROP_DISCOVERY_DELAY, intValue = DEFAULT_DISCOVERY_DELAY, |
| 180 | label = "Number of millis beyond which an LLDP packet will not be accepted") |
| 181 | private int maxDiscoveryDelayMs = DEFAULT_DISCOVERY_DELAY; |
| 182 | |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 183 | private final LinkDiscoveryContext context = new InternalDiscoveryContext(); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 184 | private final InternalRoleListener roleListener = new InternalRoleListener(); |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 185 | private final InternalDeviceListener deviceListener = new InternalDeviceListener(); |
| 186 | private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor(); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 187 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 188 | // Device link discovery helpers. |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 189 | protected final Map<DeviceId, LinkDiscovery> discoverers = new ConcurrentHashMap<>(); |
| 190 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 191 | // Most recent time a tracked link was seen; links are tracked if their |
| 192 | // destination connection point is mastered by this controller instance. |
| 193 | private final Map<LinkKey, Long> linkTimes = Maps.newConcurrentMap(); |
| 194 | |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 195 | private ApplicationId appId; |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 196 | |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 197 | static final SuppressionRules DEFAULT_RULES |
Yuta HIGUCHI | 09697d0 | 2017-03-03 16:53:39 -0800 | [diff] [blame] | 198 | = new SuppressionRules(EnumSet.of(Device.Type.ROADM, |
| 199 | Device.Type.FIBER_SWITCH, |
| 200 | Device.Type.OPTICAL_AMPLIFIER, |
| 201 | Device.Type.OTN), |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 202 | ImmutableMap.of(NO_LLDP, SuppressionRules.ANY_VALUE)); |
| 203 | |
| 204 | private SuppressionRules rules = LldpLinkProvider.DEFAULT_RULES; |
| 205 | |
| 206 | public static final String CONFIG_KEY = "suppression"; |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 207 | public static final String FEATURE_NAME = "linkDiscovery"; |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 208 | |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 209 | private final Set<ConfigFactory<?, ?>> factories = ImmutableSet.of( |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 210 | new ConfigFactory<ApplicationId, SuppressionConfig>(APP_SUBJECT_FACTORY, |
| 211 | SuppressionConfig.class, |
| 212 | CONFIG_KEY) { |
| 213 | @Override |
| 214 | public SuppressionConfig createConfig() { |
| 215 | return new SuppressionConfig(); |
| 216 | } |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 217 | }, |
| 218 | new ConfigFactory<DeviceId, LinkDiscoveryFromDevice>(DEVICE_SUBJECT_FACTORY, |
| 219 | LinkDiscoveryFromDevice.class, FEATURE_NAME) { |
| 220 | @Override |
| 221 | public LinkDiscoveryFromDevice createConfig() { |
| 222 | return new LinkDiscoveryFromDevice(); |
| 223 | } |
| 224 | }, |
| 225 | new ConfigFactory<ConnectPoint, LinkDiscoveryFromPort>(CONNECT_POINT_SUBJECT_FACTORY, |
| 226 | LinkDiscoveryFromPort.class, FEATURE_NAME) { |
| 227 | @Override |
| 228 | public LinkDiscoveryFromPort createConfig() { |
| 229 | return new LinkDiscoveryFromPort(); |
| 230 | } |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 231 | } |
| 232 | ); |
| 233 | |
| 234 | private final InternalConfigListener cfgListener = new InternalConfigListener(); |
| 235 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 236 | /** |
| 237 | * Creates an OpenFlow link provider. |
| 238 | */ |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 239 | public LldpLinkProvider() { |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 240 | super(new ProviderId("lldp", PROVIDER_NAME)); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Sho SHIMIZU | 9efeb81 | 2016-08-18 09:29:20 -0700 | [diff] [blame] | 243 | private String buildSrcMac() { |
Ayaka Koshibe | 4822922 | 2016-05-16 18:04:26 -0700 | [diff] [blame] | 244 | String defMac = ProbedLinkProvider.defaultMac(); |
Ray Milkey | 55f513f | 2017-12-01 15:58:21 -0800 | [diff] [blame] | 245 | if (clusterMetadataService == null) { |
| 246 | log.debug("No cluster metadata service is available. Using default value {}", defMac); |
| 247 | return defMac; |
| 248 | } |
| 249 | |
| 250 | String srcMac = ProbedLinkProvider.fingerprintMac(clusterMetadataService.getClusterMetadata()); |
Ayaka Koshibe | 4822922 | 2016-05-16 18:04:26 -0700 | [diff] [blame] | 251 | if (srcMac.equals(defMac)) { |
| 252 | log.warn("Couldn't generate fingerprint. Using default value {}", defMac); |
| 253 | return defMac; |
| 254 | } |
| 255 | log.trace("Generated MAC address {}", srcMac); |
| 256 | return srcMac; |
| 257 | } |
| 258 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 259 | @Activate |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 260 | public void activate(ComponentContext context) { |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 261 | eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/linkevents", "events-%d", log)); |
Ray Milkey | e80e18f | 2016-06-02 16:44:14 -0700 | [diff] [blame] | 262 | shuttingDown = false; |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 263 | cfgService.registerProperties(getClass()); |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 264 | appId = coreService.registerApplication(PROVIDER_NAME); |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 265 | |
| 266 | cfgRegistry.addListener(cfgListener); |
| 267 | factories.forEach(cfgRegistry::registerConfigFactory); |
| 268 | |
Madan Jampani | c637188 | 2016-06-03 21:30:17 -0700 | [diff] [blame] | 269 | SuppressionConfig cfg = cfgRegistry.getConfig(appId, SuppressionConfig.class); |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 270 | if (cfg == null) { |
| 271 | // If no configuration is found, register default. |
Madan Jampani | c637188 | 2016-06-03 21:30:17 -0700 | [diff] [blame] | 272 | cfg = this.setDefaultSuppressionConfig(); |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 273 | } |
| 274 | cfgListener.reconfigureSuppressionRules(cfg); |
| 275 | |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 276 | modified(context); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 277 | log.info("Started"); |
| 278 | } |
| 279 | |
Thomas Vachuska | aad8b1d | 2015-12-11 10:36:53 -0800 | [diff] [blame] | 280 | private SuppressionConfig setDefaultSuppressionConfig() { |
| 281 | SuppressionConfig cfg = cfgRegistry.addConfig(appId, SuppressionConfig.class); |
| 282 | cfg.deviceTypes(DEFAULT_RULES.getSuppressedDeviceType()) |
| 283 | .annotation(DEFAULT_RULES.getSuppressedAnnotation()) |
| 284 | .apply(); |
| 285 | return cfg; |
| 286 | } |
| 287 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 288 | @Deactivate |
| 289 | public void deactivate() { |
Ray Milkey | e80e18f | 2016-06-02 16:44:14 -0700 | [diff] [blame] | 290 | shuttingDown = true; |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 291 | cfgRegistry.removeListener(cfgListener); |
| 292 | factories.forEach(cfgRegistry::unregisterConfigFactory); |
| 293 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 294 | cfgService.unregisterProperties(getClass(), false); |
| 295 | disable(); |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 296 | eventExecutor.shutdownNow(); |
| 297 | eventExecutor = null; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 298 | log.info("Stopped"); |
| 299 | } |
| 300 | |
| 301 | @Modified |
| 302 | public void modified(ComponentContext context) { |
| 303 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 304 | |
| 305 | boolean newEnabled, newUseBddp; |
Samuel Jero | 31e16f5 | 2018-09-21 10:34:28 -0400 | [diff] [blame] | 306 | int newProbeRate, newStaleLinkAge, newDiscoveryDelay; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 307 | try { |
| 308 | String s = get(properties, PROP_ENABLED); |
| 309 | newEnabled = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim()); |
| 310 | |
| 311 | s = get(properties, PROP_USE_BDDP); |
| 312 | newUseBddp = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim()); |
| 313 | |
| 314 | s = get(properties, PROP_PROBE_RATE); |
| 315 | newProbeRate = isNullOrEmpty(s) ? probeRate : Integer.parseInt(s.trim()); |
| 316 | |
| 317 | s = get(properties, PROP_STALE_LINK_AGE); |
| 318 | newStaleLinkAge = isNullOrEmpty(s) ? staleLinkAge : Integer.parseInt(s.trim()); |
| 319 | |
Samuel Jero | 31e16f5 | 2018-09-21 10:34:28 -0400 | [diff] [blame] | 320 | s = get(properties, PROP_DISCOVERY_DELAY); |
| 321 | newDiscoveryDelay = isNullOrEmpty(s) ? maxDiscoveryDelayMs : Integer.parseInt(s.trim()); |
| 322 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 323 | } catch (NumberFormatException e) { |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 324 | log.warn("Component configuration had invalid values", e); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 325 | newEnabled = enabled; |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 326 | newUseBddp = useBddp; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 327 | newProbeRate = probeRate; |
| 328 | newStaleLinkAge = staleLinkAge; |
Samuel Jero | 31e16f5 | 2018-09-21 10:34:28 -0400 | [diff] [blame] | 329 | newDiscoveryDelay = maxDiscoveryDelayMs; |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 330 | } |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 331 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 332 | boolean wasEnabled = enabled; |
| 333 | |
| 334 | enabled = newEnabled; |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 335 | useBddp = newUseBddp; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 336 | probeRate = newProbeRate; |
| 337 | staleLinkAge = newStaleLinkAge; |
Samuel Jero | 31e16f5 | 2018-09-21 10:34:28 -0400 | [diff] [blame] | 338 | maxDiscoveryDelayMs = newDiscoveryDelay; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 339 | |
| 340 | if (!wasEnabled && enabled) { |
| 341 | enable(); |
| 342 | } else if (wasEnabled && !enabled) { |
| 343 | disable(); |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 344 | } else { |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 345 | if (enabled) { |
| 346 | // update all discovery helper state |
| 347 | loadDevices(); |
| 348 | } |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Samuel Jero | 31e16f5 | 2018-09-21 10:34:28 -0400 | [diff] [blame] | 351 | log.info(FORMAT, enabled, useBddp, probeRate, staleLinkAge, maxDiscoveryDelayMs); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 354 | /** |
| 355 | * Enables link discovery processing. |
| 356 | */ |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 357 | private void enable() { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 358 | providerService = providerRegistry.register(this); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 359 | masterService.addListener(roleListener); |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 360 | deviceService.addListener(deviceListener); |
| 361 | packetService.addProcessor(packetProcessor, PacketProcessor.advisor(0)); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 362 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 363 | loadDevices(); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 364 | |
HIGUCHI Yuta | d9e0105 | 2016-04-14 09:31:42 -0700 | [diff] [blame] | 365 | executor = newSingleThreadScheduledExecutor(groupedThreads("onos/link", "discovery-%d", log)); |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 366 | executor.scheduleAtFixedRate(new SyncDeviceInfoTask(), |
| 367 | DEVICE_SYNC_DELAY, DEVICE_SYNC_DELAY, SECONDS); |
| 368 | executor.scheduleAtFixedRate(new LinkPrunerTask(), |
| 369 | LINK_PRUNER_DELAY, LINK_PRUNER_DELAY, SECONDS); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 370 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 371 | requestIntercepts(); |
| 372 | } |
| 373 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 374 | /** |
| 375 | * Disables link discovery processing. |
| 376 | */ |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 377 | private void disable() { |
| 378 | withdrawIntercepts(); |
| 379 | |
| 380 | providerRegistry.unregister(this); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 381 | masterService.removeListener(roleListener); |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 382 | deviceService.removeListener(deviceListener); |
| 383 | packetService.removeProcessor(packetProcessor); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 384 | |
| 385 | if (executor != null) { |
| 386 | executor.shutdownNow(); |
| 387 | } |
| 388 | discoverers.values().forEach(LinkDiscovery::stop); |
| 389 | discoverers.clear(); |
Jon Hall | 125c3f2 | 2017-08-09 13:46:28 -0700 | [diff] [blame] | 390 | linkTimes.clear(); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 391 | |
| 392 | providerService = null; |
| 393 | } |
| 394 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 395 | /** |
| 396 | * Loads available devices and registers their ports to be probed. |
| 397 | */ |
| 398 | private void loadDevices() { |
Ray Milkey | 0f87d48 | 2016-07-06 11:49:19 -0700 | [diff] [blame] | 399 | if (!enabled || deviceService == null) { |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 400 | return; |
| 401 | } |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 402 | deviceService.getAvailableDevices() |
| 403 | .forEach(d -> updateDevice(d) |
| 404 | .ifPresent(ld -> updatePorts(ld, d.id()))); |
| 405 | } |
| 406 | |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 407 | private boolean isBlacklisted(DeviceId did) { |
| 408 | LinkDiscoveryFromDevice cfg = cfgRegistry.getConfig(did, LinkDiscoveryFromDevice.class); |
| 409 | if (cfg == null) { |
| 410 | return false; |
| 411 | } |
| 412 | return !cfg.enabled(); |
| 413 | } |
| 414 | |
| 415 | private boolean isBlacklisted(ConnectPoint cp) { |
| 416 | // if parent device is blacklisted, so is the port |
| 417 | if (isBlacklisted(cp.deviceId())) { |
| 418 | return true; |
| 419 | } |
| 420 | LinkDiscoveryFromPort cfg = cfgRegistry.getConfig(cp, LinkDiscoveryFromPort.class); |
| 421 | if (cfg == null) { |
| 422 | return false; |
| 423 | } |
| 424 | return !cfg.enabled(); |
| 425 | } |
| 426 | |
| 427 | private boolean isBlacklisted(Port port) { |
| 428 | return isBlacklisted(new ConnectPoint(port.element().id(), port.number())); |
| 429 | } |
| 430 | |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 431 | /** |
| 432 | * Updates discovery helper for specified device. |
| 433 | * |
| 434 | * Adds and starts a discovery helper for specified device if enabled, |
| 435 | * calls {@link #removeDevice(DeviceId)} otherwise. |
| 436 | * |
| 437 | * @param device device to add |
| 438 | * @return discovery helper if discovery is enabled for the device |
| 439 | */ |
| 440 | private Optional<LinkDiscovery> updateDevice(Device device) { |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 441 | if (device == null) { |
| 442 | return Optional.empty(); |
| 443 | } |
Jon Hall | 125c3f2 | 2017-08-09 13:46:28 -0700 | [diff] [blame] | 444 | if (!masterService.isLocalMaster(device.id())) { |
| 445 | // Reset the last seen time for all links to this device |
| 446 | // then stop discovery for this device |
| 447 | List<LinkKey> updateLinks = new LinkedList<>(); |
| 448 | linkTimes.forEach((link, time) -> { |
| 449 | if (link.dst().deviceId().equals(device.id())) { |
| 450 | updateLinks.add(link); |
| 451 | } |
| 452 | }); |
| 453 | updateLinks.forEach(link -> linkTimes.remove(link)); |
| 454 | removeDevice(device.id()); |
| 455 | return Optional.empty(); |
| 456 | } |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 457 | if (rules.isSuppressed(device) || isBlacklisted(device.id())) { |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 458 | log.trace("LinkDiscovery from {} disabled by configuration", device.id()); |
| 459 | removeDevice(device.id()); |
| 460 | return Optional.empty(); |
| 461 | } |
Ayaka Koshibe | 3ddb7b2 | 2015-12-10 17:32:59 -0800 | [diff] [blame] | 462 | |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 463 | LinkDiscovery ld = discoverers.computeIfAbsent(device.id(), |
| 464 | did -> new LinkDiscovery(device, context)); |
| 465 | if (ld.isStopped()) { |
| 466 | ld.start(); |
| 467 | } |
| 468 | return Optional.of(ld); |
| 469 | } |
| 470 | |
| 471 | /** |
| 472 | * Removes after stopping discovery helper for specified device. |
| 473 | * @param deviceId device to remove |
| 474 | */ |
| 475 | private void removeDevice(final DeviceId deviceId) { |
| 476 | discoverers.computeIfPresent(deviceId, (did, ld) -> { |
| 477 | ld.stop(); |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 478 | return null; |
| 479 | }); |
| 480 | |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Updates ports of the specified device to the specified discovery helper. |
| 485 | */ |
| 486 | private void updatePorts(LinkDiscovery discoverer, DeviceId deviceId) { |
| 487 | deviceService.getPorts(deviceId).forEach(p -> updatePort(discoverer, p)); |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * Updates discovery helper state of the specified port. |
| 492 | * |
| 493 | * Adds a port to the discovery helper if up and discovery is enabled, |
| 494 | * or calls {@link #removePort(Port)} otherwise. |
| 495 | */ |
| 496 | private void updatePort(LinkDiscovery discoverer, Port port) { |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 497 | if (port == null) { |
| 498 | return; |
| 499 | } |
HIGUCHI Yuta | b853b3f | 2015-11-17 18:43:20 -0800 | [diff] [blame] | 500 | if (port.number().isLogical()) { |
| 501 | // silently ignore logical ports |
| 502 | return; |
| 503 | } |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 504 | |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 505 | if (rules.isSuppressed(port) || isBlacklisted(port)) { |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 506 | log.trace("LinkDiscovery from {} disabled by configuration", port); |
| 507 | removePort(port); |
| 508 | return; |
| 509 | } |
| 510 | |
| 511 | // check if enabled and turn off discovery? |
| 512 | if (!port.isEnabled()) { |
| 513 | removePort(port); |
| 514 | return; |
| 515 | } |
| 516 | |
HIGUCHI Yuta | b853b3f | 2015-11-17 18:43:20 -0800 | [diff] [blame] | 517 | discoverer.addPort(port); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 520 | /** |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 521 | * Removes a port from the specified discovery helper. |
| 522 | * @param port the port |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 523 | */ |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 524 | private void removePort(Port port) { |
| 525 | if (port.element() instanceof Device) { |
| 526 | Device d = (Device) port.element(); |
| 527 | LinkDiscovery ld = discoverers.get(d.id()); |
| 528 | if (ld != null) { |
| 529 | ld.removePort(port.number()); |
Jonathan Hart | 45066bc | 2015-07-28 11:18:34 -0700 | [diff] [blame] | 530 | } |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 531 | } else { |
| 532 | log.warn("Attempted to remove non-Device port", port); |
Jonathan Hart | 45066bc | 2015-07-28 11:18:34 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 536 | /** |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 537 | * Requests packet intercepts. |
Charles M.C. Chan | e148de8 | 2015-05-06 12:38:21 +0800 | [diff] [blame] | 538 | */ |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 539 | private void requestIntercepts() { |
| 540 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame] | 541 | selector.matchEthType(TYPE_LLDP); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 542 | packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 543 | |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame] | 544 | selector.matchEthType(TYPE_BSN); |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 545 | if (useBddp) { |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 546 | packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); |
| 547 | } else { |
| 548 | packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 552 | /** |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 553 | * Withdraws packet intercepts. |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 554 | */ |
| 555 | private void withdrawIntercepts() { |
| 556 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame] | 557 | selector.matchEthType(TYPE_LLDP); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 558 | packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame] | 559 | selector.matchEthType(TYPE_BSN); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 560 | packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); |
| 561 | } |
| 562 | |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 563 | protected SuppressionRules rules() { |
| 564 | return rules; |
| 565 | } |
| 566 | |
| 567 | protected void updateRules(SuppressionRules newRules) { |
| 568 | if (!rules.equals(newRules)) { |
| 569 | rules = newRules; |
| 570 | loadDevices(); |
| 571 | } |
| 572 | } |
| 573 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 574 | /** |
| 575 | * Processes device mastership role changes. |
| 576 | */ |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 577 | private class InternalRoleListener implements MastershipListener { |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 578 | @Override |
| 579 | public void event(MastershipEvent event) { |
Jordan Halterman | 9d982a5 | 2017-12-11 15:27:37 -0800 | [diff] [blame] | 580 | if (event.type() == MastershipEvent.Type.MASTER_CHANGED) { |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 581 | // only need new master events |
Jon Hall | 7a8bfc6 | 2016-05-26 17:59:04 -0700 | [diff] [blame] | 582 | eventExecutor.execute(() -> { |
| 583 | DeviceId deviceId = event.subject(); |
| 584 | Device device = deviceService.getDevice(deviceId); |
| 585 | if (device == null) { |
| 586 | log.debug("Device {} doesn't exist, or isn't there yet", deviceId); |
| 587 | return; |
| 588 | } |
Jordan Halterman | 9d982a5 | 2017-12-11 15:27:37 -0800 | [diff] [blame] | 589 | updateDevice(device).ifPresent(ld -> updatePorts(ld, device.id())); |
Jon Hall | 7a8bfc6 | 2016-05-26 17:59:04 -0700 | [diff] [blame] | 590 | }); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 591 | } |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 592 | } |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 593 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 594 | |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 595 | private class DeviceEventProcessor implements Runnable { |
| 596 | |
| 597 | DeviceEvent event; |
| 598 | |
| 599 | DeviceEventProcessor(DeviceEvent event) { |
| 600 | this.event = event; |
| 601 | } |
| 602 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 603 | @Override |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 604 | public void run() { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 605 | Device device = event.subject(); |
alshabib | acd9183 | 2014-10-17 14:38:41 -0700 | [diff] [blame] | 606 | Port port = event.port(); |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 607 | if (device == null) { |
| 608 | log.error("Device is null."); |
| 609 | return; |
| 610 | } |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 611 | log.trace("{} {} {}", event.type(), event.subject(), event); |
Yuta HIGUCHI | d19f670 | 2014-10-31 15:23:25 -0700 | [diff] [blame] | 612 | final DeviceId deviceId = device.id(); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 613 | switch (event.type()) { |
| 614 | case DEVICE_ADDED: |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 615 | case DEVICE_UPDATED: |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 616 | updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId)); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 617 | break; |
| 618 | case PORT_ADDED: |
| 619 | case PORT_UPDATED: |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 620 | if (port.isEnabled()) { |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 621 | updateDevice(device).ifPresent(ld -> updatePort(ld, port)); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 622 | } else { |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 623 | log.debug("Port down {}", port); |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 624 | removePort(port); |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 625 | providerService.linksVanished(new ConnectPoint(port.element().id(), |
| 626 | port.number())); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 627 | } |
| 628 | break; |
| 629 | case PORT_REMOVED: |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 630 | log.debug("Port removed {}", port); |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 631 | removePort(port); |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 632 | providerService.linksVanished(new ConnectPoint(port.element().id(), |
| 633 | port.number())); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 634 | break; |
| 635 | case DEVICE_REMOVED: |
| 636 | case DEVICE_SUSPENDED: |
Yuta HIGUCHI | d19f670 | 2014-10-31 15:23:25 -0700 | [diff] [blame] | 637 | log.debug("Device removed {}", deviceId); |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 638 | removeDevice(deviceId); |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 639 | providerService.linksVanished(deviceId); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 640 | break; |
| 641 | case DEVICE_AVAILABILITY_CHANGED: |
Yuta HIGUCHI | d19f670 | 2014-10-31 15:23:25 -0700 | [diff] [blame] | 642 | if (deviceService.isAvailable(deviceId)) { |
| 643 | log.debug("Device up {}", deviceId); |
alshabib | e3af265 | 2015-12-01 23:05:34 -0800 | [diff] [blame] | 644 | updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId)); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 645 | } else { |
Yuta HIGUCHI | d19f670 | 2014-10-31 15:23:25 -0700 | [diff] [blame] | 646 | log.debug("Device down {}", deviceId); |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 647 | removeDevice(deviceId); |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 648 | providerService.linksVanished(deviceId); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 649 | } |
| 650 | break; |
Jonathan Hart | 9de692c | 2015-04-23 11:45:47 -0700 | [diff] [blame] | 651 | case PORT_STATS_UPDATED: |
| 652 | break; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 653 | default: |
| 654 | log.debug("Unknown event {}", event); |
| 655 | } |
| 656 | } |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 657 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 658 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 659 | /** |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 660 | * Processes device events. |
| 661 | */ |
| 662 | private class InternalDeviceListener implements DeviceListener { |
| 663 | @Override |
| 664 | public void event(DeviceEvent event) { |
| 665 | if (event.type() == Type.PORT_STATS_UPDATED) { |
| 666 | return; |
| 667 | } |
| 668 | |
| 669 | Runnable deviceEventProcessor = new DeviceEventProcessor(event); |
| 670 | |
| 671 | eventExecutor.execute(deviceEventProcessor); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | /** |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 676 | * Processes incoming packets. |
| 677 | */ |
| 678 | private class InternalPacketProcessor implements PacketProcessor { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 679 | @Override |
| 680 | public void process(PacketContext context) { |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame] | 681 | if (context == null || context.isHandled()) { |
alshabib | 4a179dc | 2014-10-17 17:17:01 -0700 | [diff] [blame] | 682 | return; |
| 683 | } |
Thomas Vachuska | 347cc87 | 2015-09-23 10:25:29 -0700 | [diff] [blame] | 684 | |
| 685 | Ethernet eth = context.inPacket().parsed(); |
| 686 | if (eth == null || (eth.getEtherType() != TYPE_LLDP && eth.getEtherType() != TYPE_BSN)) { |
| 687 | return; |
| 688 | } |
| 689 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 690 | LinkDiscovery ld = discoverers.get(context.inPacket().receivedFrom().deviceId()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 691 | if (ld == null) { |
| 692 | return; |
| 693 | } |
| 694 | |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 695 | if (ld.handleLldp(context)) { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 696 | context.block(); |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 701 | /** |
| 702 | * Auxiliary task to keep device ports up to date. |
| 703 | */ |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 704 | private final class SyncDeviceInfoTask implements Runnable { |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 705 | @Override |
| 706 | public void run() { |
| 707 | if (Thread.currentThread().isInterrupted()) { |
| 708 | log.info("Interrupted, quitting"); |
| 709 | return; |
| 710 | } |
| 711 | // check what deviceService sees, to see if we are missing anything |
| 712 | try { |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 713 | loadDevices(); |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 714 | } catch (Exception e) { |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 715 | // Catch all exceptions to avoid task being suppressed |
Ayaka Koshibe | ccfa94c | 2014-11-20 11:15:52 -0800 | [diff] [blame] | 716 | log.error("Exception thrown during synchronization process", e); |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 721 | /** |
| 722 | * Auxiliary task for pruning stale links. |
| 723 | */ |
| 724 | private class LinkPrunerTask implements Runnable { |
| 725 | @Override |
| 726 | public void run() { |
| 727 | if (Thread.currentThread().isInterrupted()) { |
| 728 | log.info("Interrupted, quitting"); |
| 729 | return; |
| 730 | } |
| 731 | |
| 732 | try { |
| 733 | // TODO: There is still a slight possibility of mastership |
| 734 | // change occurring right with link going stale. This will |
| 735 | // result in the stale link not being pruned. |
| 736 | Maps.filterEntries(linkTimes, e -> { |
| 737 | if (!masterService.isLocalMaster(e.getKey().dst().deviceId())) { |
| 738 | return true; |
| 739 | } |
| 740 | if (isStale(e.getValue())) { |
| 741 | providerService.linkVanished(new DefaultLinkDescription(e.getKey().src(), |
| 742 | e.getKey().dst(), |
| 743 | DIRECT)); |
| 744 | return true; |
| 745 | } |
| 746 | return false; |
| 747 | }).clear(); |
| 748 | |
| 749 | } catch (Exception e) { |
| 750 | // Catch all exceptions to avoid task being suppressed |
Ray Milkey | e80e18f | 2016-06-02 16:44:14 -0700 | [diff] [blame] | 751 | if (!shuttingDown) { |
| 752 | // Error condition |
| 753 | log.error("Exception thrown during link pruning process", e); |
| 754 | } else { |
| 755 | // Provider is shutting down, the error can be ignored |
| 756 | log.trace("Shutting down, ignoring error", e); |
| 757 | } |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
| 761 | private boolean isStale(long lastSeen) { |
| 762 | return lastSeen < System.currentTimeMillis() - staleLinkAge; |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /** |
| 767 | * Provides processing context for the device link discovery helpers. |
| 768 | */ |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 769 | private class InternalDiscoveryContext implements LinkDiscoveryContext { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 770 | @Override |
| 771 | public MastershipService mastershipService() { |
| 772 | return masterService; |
| 773 | } |
| 774 | |
| 775 | @Override |
| 776 | public LinkProviderService providerService() { |
| 777 | return providerService; |
| 778 | } |
| 779 | |
| 780 | @Override |
| 781 | public PacketService packetService() { |
| 782 | return packetService; |
| 783 | } |
| 784 | |
| 785 | @Override |
| 786 | public long probeRate() { |
| 787 | return probeRate; |
| 788 | } |
| 789 | |
| 790 | @Override |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 791 | public boolean useBddp() { |
| 792 | return useBddp; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 793 | } |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 794 | |
| 795 | @Override |
| 796 | public void touchLink(LinkKey key) { |
| 797 | linkTimes.put(key, System.currentTimeMillis()); |
| 798 | } |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 799 | |
| 800 | @Override |
DongRyeol Cha | ce65cc0 | 2018-07-23 15:02:28 +0900 | [diff] [blame^] | 801 | public void setTtl(LinkKey key, short ttl) { |
| 802 | linkTimes.put(key, System.currentTimeMillis() - staleLinkAge + SECONDS.toMillis(ttl)); |
| 803 | } |
| 804 | |
| 805 | @Override |
Ayaka Koshibe | 4822922 | 2016-05-16 18:04:26 -0700 | [diff] [blame] | 806 | public DeviceService deviceService() { |
| 807 | return deviceService; |
Ayaka Koshibe | 3ddb7b2 | 2015-12-10 17:32:59 -0800 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | @Override |
Ayaka Koshibe | 4822922 | 2016-05-16 18:04:26 -0700 | [diff] [blame] | 811 | public String fingerprint() { |
| 812 | return buildSrcMac(); |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 813 | } |
Samuel Jero | 31e16f5 | 2018-09-21 10:34:28 -0400 | [diff] [blame] | 814 | |
| 815 | @Override |
| 816 | public String lldpSecret() { |
| 817 | return clusterMetadataService.getClusterMetadata().getClusterSecret(); |
| 818 | } |
| 819 | |
| 820 | @Override |
| 821 | public long maxDiscoveryDelay() { |
| 822 | return maxDiscoveryDelayMs; |
| 823 | } |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 824 | } |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 825 | |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 826 | static final EnumSet<NetworkConfigEvent.Type> CONFIG_CHANGED |
| 827 | = EnumSet.of(NetworkConfigEvent.Type.CONFIG_ADDED, |
| 828 | NetworkConfigEvent.Type.CONFIG_UPDATED, |
| 829 | NetworkConfigEvent.Type.CONFIG_REMOVED); |
| 830 | |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 831 | private class InternalConfigListener implements NetworkConfigListener { |
| 832 | |
| 833 | private synchronized void reconfigureSuppressionRules(SuppressionConfig cfg) { |
| 834 | if (cfg == null) { |
Ray Milkey | 0a8ee91 | 2016-06-13 09:58:12 -0700 | [diff] [blame] | 835 | log.debug("Suppression Config is null."); |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 836 | return; |
| 837 | } |
| 838 | |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 839 | SuppressionRules newRules = new SuppressionRules(cfg.deviceTypes(), |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 840 | cfg.annotation()); |
| 841 | |
| 842 | updateRules(newRules); |
| 843 | } |
| 844 | |
Jon Hall | 125c3f2 | 2017-08-09 13:46:28 -0700 | [diff] [blame] | 845 | private boolean isRelevantDeviceEvent(NetworkConfigEvent event) { |
| 846 | return event.configClass() == LinkDiscoveryFromDevice.class && |
| 847 | CONFIG_CHANGED.contains(event.type()); |
| 848 | } |
| 849 | |
| 850 | private boolean isRelevantPortEvent(NetworkConfigEvent event) { |
| 851 | return event.configClass() == LinkDiscoveryFromPort.class && |
| 852 | CONFIG_CHANGED.contains(event.type()); |
| 853 | } |
| 854 | |
| 855 | private boolean isRelevantSuppressionEvent(NetworkConfigEvent event) { |
| 856 | return (event.configClass().equals(SuppressionConfig.class) && |
| 857 | (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || |
| 858 | event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)); |
| 859 | } |
| 860 | |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 861 | @Override |
| 862 | public void event(NetworkConfigEvent event) { |
Ray Milkey | d9bbde8 | 2016-06-09 11:35:00 -0700 | [diff] [blame] | 863 | eventExecutor.execute(() -> { |
Jon Hall | 125c3f2 | 2017-08-09 13:46:28 -0700 | [diff] [blame] | 864 | if (isRelevantDeviceEvent(event)) { |
Thomas Vachuska | b5f6f52 | 2016-03-01 13:52:10 -0800 | [diff] [blame] | 865 | if (event.subject() instanceof DeviceId) { |
| 866 | final DeviceId did = (DeviceId) event.subject(); |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 867 | Device device = deviceService.getDevice(did); |
Thomas Vachuska | b5f6f52 | 2016-03-01 13:52:10 -0800 | [diff] [blame] | 868 | updateDevice(device).ifPresent(ld -> updatePorts(ld, did)); |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 869 | } |
Jon Hall | 125c3f2 | 2017-08-09 13:46:28 -0700 | [diff] [blame] | 870 | } else if (isRelevantPortEvent(event)) { |
Thomas Vachuska | b5f6f52 | 2016-03-01 13:52:10 -0800 | [diff] [blame] | 871 | if (event.subject() instanceof ConnectPoint) { |
| 872 | ConnectPoint cp = (ConnectPoint) event.subject(); |
| 873 | if (cp.elementId() instanceof DeviceId) { |
| 874 | final DeviceId did = (DeviceId) cp.elementId(); |
| 875 | Device device = deviceService.getDevice(did); |
| 876 | Port port = deviceService.getPort(did, cp.port()); |
| 877 | updateDevice(device).ifPresent(ld -> updatePort(ld, port)); |
| 878 | } |
| 879 | } |
Jon Hall | 125c3f2 | 2017-08-09 13:46:28 -0700 | [diff] [blame] | 880 | } else if (isRelevantSuppressionEvent(event)) { |
Thomas Vachuska | b5f6f52 | 2016-03-01 13:52:10 -0800 | [diff] [blame] | 881 | SuppressionConfig cfg = cfgRegistry.getConfig(appId, SuppressionConfig.class); |
| 882 | reconfigureSuppressionRules(cfg); |
| 883 | log.trace("Network config reconfigured"); |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 884 | } |
Thomas Vachuska | b5f6f52 | 2016-03-01 13:52:10 -0800 | [diff] [blame] | 885 | }); |
Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 886 | } |
| 887 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 888 | } |