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