Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 16 | |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 17 | package org.onosproject.provider.netconf.device.impl; |
| 18 | |
Michele Santuari | 00cc1f7 | 2016-09-08 17:05:24 +0200 | [diff] [blame] | 19 | import com.google.common.base.Objects; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 20 | import com.google.common.base.Preconditions; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Modified; |
| 25 | import org.apache.felix.scr.annotations.Property; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 26 | import org.apache.felix.scr.annotations.Reference; |
| 27 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 28 | import org.onlab.packet.ChassisId; |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 29 | import org.onlab.util.Tools; |
| 30 | import org.onosproject.cfg.ComponentConfigService; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 31 | import org.onosproject.core.ApplicationId; |
| 32 | import org.onosproject.core.CoreService; |
| 33 | import org.onosproject.incubator.net.config.basics.ConfigException; |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 34 | import org.onosproject.mastership.MastershipService; |
Marc De Leenheer | b0d131c | 2016-03-01 20:34:59 -0800 | [diff] [blame] | 35 | import org.onosproject.net.AnnotationKeys; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 36 | import org.onosproject.net.DefaultAnnotations; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 37 | import org.onosproject.net.Device; |
| 38 | import org.onosproject.net.DeviceId; |
| 39 | import org.onosproject.net.MastershipRole; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 40 | import org.onosproject.net.PortNumber; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 41 | import org.onosproject.net.SparseAnnotations; |
Aaron Kruglikov | 17b4c85 | 2016-01-15 16:37:04 -0800 | [diff] [blame] | 42 | import org.onosproject.net.behaviour.PortDiscovery; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 43 | import org.onosproject.net.config.ConfigFactory; |
| 44 | import org.onosproject.net.config.NetworkConfigEvent; |
| 45 | import org.onosproject.net.config.NetworkConfigListener; |
| 46 | import org.onosproject.net.config.NetworkConfigRegistry; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 47 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 48 | import org.onosproject.net.device.DeviceDescription; |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 49 | import org.onosproject.net.device.DeviceDescriptionDiscovery; |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 50 | import org.onosproject.net.device.DeviceEvent; |
| 51 | import org.onosproject.net.device.DeviceListener; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 52 | import org.onosproject.net.device.DeviceProvider; |
| 53 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 54 | import org.onosproject.net.device.DeviceProviderService; |
Aaron Kruglikov | 17b4c85 | 2016-01-15 16:37:04 -0800 | [diff] [blame] | 55 | import org.onosproject.net.device.DeviceService; |
Gaurav Agrawal | dab4d77 | 2017-03-29 15:15:13 +0530 | [diff] [blame] | 56 | import org.onosproject.net.device.PortStatisticsDiscovery; |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 57 | import org.onosproject.net.key.DeviceKey; |
| 58 | import org.onosproject.net.key.DeviceKeyAdminService; |
| 59 | import org.onosproject.net.key.DeviceKeyId; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 60 | import org.onosproject.net.provider.AbstractProvider; |
| 61 | import org.onosproject.net.provider.ProviderId; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 62 | import org.onosproject.netconf.NetconfController; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 63 | import org.onosproject.netconf.NetconfDeviceListener; |
Andrea Campanella | 8b1cb67 | 2016-01-25 13:58:58 -0800 | [diff] [blame] | 64 | import org.onosproject.netconf.NetconfException; |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 65 | import org.osgi.service.component.ComponentContext; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 66 | import org.slf4j.Logger; |
| 67 | |
Andrea Campanella | 087ceb9 | 2015-12-07 09:58:34 -0800 | [diff] [blame] | 68 | import java.io.IOException; |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 69 | import java.net.Socket; |
| 70 | import java.net.URI; |
| 71 | import java.net.URISyntaxException; |
| 72 | import java.util.Arrays; |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 73 | import java.util.Dictionary; |
Andrea Campanella | 5c999e2 | 2016-03-01 15:12:53 -0800 | [diff] [blame] | 74 | import java.util.concurrent.ExecutorService; |
| 75 | import java.util.concurrent.Executors; |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 76 | import java.util.concurrent.ScheduledExecutorService; |
| 77 | import java.util.concurrent.ScheduledFuture; |
| 78 | import java.util.concurrent.TimeUnit; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 79 | |
Yuta HIGUCHI | 1624df1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 80 | import static java.util.concurrent.Executors.newScheduledThreadPool; |
Andrea Campanella | 5c999e2 | 2016-03-01 15:12:53 -0800 | [diff] [blame] | 81 | import static org.onlab.util.Tools.groupedThreads; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 82 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
| 83 | import static org.slf4j.LoggerFactory.getLogger; |
| 84 | |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 85 | /** |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 86 | * Provider which uses an NETCONF controller to detect device. |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 87 | */ |
| 88 | @Component(immediate = true) |
| 89 | public class NetconfDeviceProvider extends AbstractProvider |
| 90 | implements DeviceProvider { |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 91 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 92 | private final Logger log = getLogger(getClass()); |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 93 | |
| 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 95 | protected DeviceProviderRegistry providerRegistry; |
| 96 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 97 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 98 | protected NetconfController controller; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 99 | |
| 100 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 101 | protected NetworkConfigRegistry cfgService; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 102 | |
Thomas Vachuska | d681171 | 2015-04-29 21:37:04 -0700 | [diff] [blame] | 103 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 104 | protected CoreService coreService; |
Thomas Vachuska | d681171 | 2015-04-29 21:37:04 -0700 | [diff] [blame] | 105 | |
Aaron Kruglikov | 17b4c85 | 2016-01-15 16:37:04 -0800 | [diff] [blame] | 106 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 107 | protected DeviceService deviceService; |
Aaron Kruglikov | 17b4c85 | 2016-01-15 16:37:04 -0800 | [diff] [blame] | 108 | |
| 109 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 110 | protected DeviceKeyAdminService deviceKeyAdminService; |
| 111 | |
| 112 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 113 | protected MastershipService mastershipService; |
| 114 | |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 115 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 116 | protected ComponentConfigService componentConfigService; |
| 117 | |
| 118 | |
| 119 | |
Michele Santuari | 576f09c | 2016-09-28 14:20:00 +0200 | [diff] [blame] | 120 | protected static final String APP_NAME = "org.onosproject.netconf"; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 121 | private static final String SCHEME_NAME = "netconf"; |
| 122 | private static final String DEVICE_PROVIDER_PACKAGE = "org.onosproject.netconf.provider.device"; |
| 123 | private static final String UNKNOWN = "unknown"; |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 124 | protected static final String ISNULL = "NetconfDeviceInfo is null"; |
| 125 | private static final String IPADDRESS = "ipaddress"; |
| 126 | private static final String NETCONF = "netconf"; |
| 127 | private static final String PORT = "port"; |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 128 | private static final int CORE_POOL_SIZE = 10; |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 129 | |
Thomas Vachuska | db29dcf | 2017-03-31 11:26:19 -0700 | [diff] [blame^] | 130 | private static final int DEFAULT_POLL_FREQUENCY_SECONDS = 30; |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 131 | @Property(name = "pollFrequency", intValue = DEFAULT_POLL_FREQUENCY_SECONDS, |
| 132 | label = "Configure poll frequency for port status and statistics; " + |
Thomas Vachuska | db29dcf | 2017-03-31 11:26:19 -0700 | [diff] [blame^] | 133 | "default is 30 sec") |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 134 | private int pollFrequency = DEFAULT_POLL_FREQUENCY_SECONDS; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 135 | |
Michele Santuari | 576f09c | 2016-09-28 14:20:00 +0200 | [diff] [blame] | 136 | protected final ExecutorService executor = |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 137 | Executors.newFixedThreadPool(5, groupedThreads("onos/netconfdeviceprovider", |
| 138 | "device-installer-%d", log)); |
Yuta HIGUCHI | 1624df1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 139 | protected ScheduledExecutorService connectionExecutor |
| 140 | = newScheduledThreadPool(CORE_POOL_SIZE, |
| 141 | groupedThreads("onos/netconfdeviceprovider", |
| 142 | "connection-executor-%d", log)); |
Andrea Campanella | 5c999e2 | 2016-03-01 15:12:53 -0800 | [diff] [blame] | 143 | |
Michele Santuari | 576f09c | 2016-09-28 14:20:00 +0200 | [diff] [blame] | 144 | protected DeviceProviderService providerService; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 145 | private NetconfDeviceListener innerNodeListener = new InnerNetconfDeviceListener(); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 146 | private InternalDeviceListener deviceListener = new InternalDeviceListener(); |
Michele Santuari | 576f09c | 2016-09-28 14:20:00 +0200 | [diff] [blame] | 147 | protected ScheduledFuture<?> scheduledTask; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 148 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 149 | private final ConfigFactory factory = |
| 150 | new ConfigFactory<ApplicationId, NetconfProviderConfig>(APP_SUBJECT_FACTORY, |
| 151 | NetconfProviderConfig.class, |
| 152 | "devices", |
| 153 | true) { |
| 154 | @Override |
| 155 | public NetconfProviderConfig createConfig() { |
| 156 | return new NetconfProviderConfig(); |
| 157 | } |
| 158 | }; |
Michele Santuari | 576f09c | 2016-09-28 14:20:00 +0200 | [diff] [blame] | 159 | protected final NetworkConfigListener cfgListener = new InternalNetworkConfigListener(); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 160 | private ApplicationId appId; |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 161 | private boolean active; |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 162 | |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 163 | |
| 164 | @Activate |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 165 | public void activate(ComponentContext context) { |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 166 | active = true; |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 167 | componentConfigService.registerProperties(getClass()); |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 168 | providerService = providerRegistry.register(this); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 169 | appId = coreService.registerApplication(APP_NAME); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 170 | cfgService.registerConfigFactory(factory); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 171 | cfgService.addListener(cfgListener); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 172 | controller.addDeviceListener(innerNodeListener); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 173 | deviceService.addListener(deviceListener); |
Andrea Campanella | 7d8449b | 2016-03-02 10:16:42 -0800 | [diff] [blame] | 174 | executor.execute(NetconfDeviceProvider.this::connectDevices); |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 175 | modified(context); |
Thomas Vachuska | d681171 | 2015-04-29 21:37:04 -0700 | [diff] [blame] | 176 | log.info("Started"); |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 177 | } |
| 178 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 179 | |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 180 | @Deactivate |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 181 | public void deactivate() { |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 182 | componentConfigService.unregisterProperties(getClass(), false); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 183 | deviceService.removeListener(deviceListener); |
| 184 | active = false; |
| 185 | controller.getNetconfDevices().forEach(id -> { |
| 186 | deviceKeyAdminService.removeKey(DeviceKeyId.deviceKeyId(id.toString())); |
| 187 | controller.disconnectDevice(id, true); |
| 188 | }); |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 189 | controller.removeDeviceListener(innerNodeListener); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 190 | deviceService.removeListener(deviceListener); |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 191 | providerRegistry.unregister(this); |
| 192 | providerService = null; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 193 | cfgService.unregisterConfigFactory(factory); |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 194 | scheduledTask.cancel(true); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 195 | executor.shutdown(); |
Sanjay S | eb5eebb | 2015-04-24 15:44:50 +0530 | [diff] [blame] | 196 | log.info("Stopped"); |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 197 | } |
| 198 | |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 199 | |
| 200 | @Modified |
| 201 | public void modified(ComponentContext context) { |
| 202 | if (context != null) { |
| 203 | Dictionary<?, ?> properties = context.getProperties(); |
| 204 | pollFrequency = Tools.getIntegerProperty(properties, "pollFrequency", |
| 205 | DEFAULT_POLL_FREQUENCY_SECONDS); |
| 206 | log.info("Configured. Poll frequency is configured to {} seconds", pollFrequency); |
| 207 | } |
| 208 | if (scheduledTask != null) { |
| 209 | scheduledTask.cancel(false); |
| 210 | } |
| 211 | scheduledTask = schedulePolling(); |
| 212 | } |
| 213 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 214 | public NetconfDeviceProvider() { |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 215 | super(new ProviderId(SCHEME_NAME, DEVICE_PROVIDER_PACKAGE)); |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 216 | } |
| 217 | |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 218 | // Checks connection to devices in the config file |
| 219 | // every DEFAULT_POLL_FREQUENCY_SECONDS seconds. |
| 220 | private ScheduledFuture schedulePolling() { |
Yuta HIGUCHI | c2b82e3 | 2017-03-10 14:33:41 -0800 | [diff] [blame] | 221 | return connectionExecutor.scheduleAtFixedRate(exceptionSafe(this::checkAndUpdateDevices), |
Thomas Vachuska | f3aaa8d | 2017-03-31 10:43:58 -0700 | [diff] [blame] | 222 | pollFrequency / 10, |
| 223 | pollFrequency, TimeUnit.SECONDS); |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Yuta HIGUCHI | c2b82e3 | 2017-03-10 14:33:41 -0800 | [diff] [blame] | 226 | private Runnable exceptionSafe(Runnable runnable) { |
| 227 | return new Runnable() { |
| 228 | |
| 229 | @Override |
| 230 | public void run() { |
| 231 | try { |
| 232 | runnable.run(); |
| 233 | } catch (Exception e) { |
| 234 | log.error("Unhandled Exception", e); |
| 235 | } |
| 236 | } |
| 237 | }; |
| 238 | } |
| 239 | |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 240 | @Override |
| 241 | public void triggerProbe(DeviceId deviceId) { |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 242 | // TODO: This will be implemented later. |
| 243 | log.info("Triggering probe on device {}", deviceId); |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | @Override |
| 247 | public void roleChanged(DeviceId deviceId, MastershipRole newRole) { |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 248 | if (active) { |
| 249 | switch (newRole) { |
| 250 | case MASTER: |
| 251 | initiateConnection(deviceId, newRole); |
| 252 | log.debug("Accepting mastership role change to {} for device {}", newRole, deviceId); |
| 253 | break; |
| 254 | case STANDBY: |
| 255 | controller.disconnectDevice(deviceId, false); |
| 256 | providerService.receivedRoleReply(deviceId, newRole, MastershipRole.STANDBY); |
| 257 | //else no-op |
| 258 | break; |
| 259 | case NONE: |
| 260 | controller.disconnectDevice(deviceId, false); |
| 261 | providerService.receivedRoleReply(deviceId, newRole, MastershipRole.NONE); |
| 262 | break; |
| 263 | default: |
| 264 | log.error("Unimplemented Mastership state : {}", newRole); |
| 265 | |
| 266 | } |
| 267 | } |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | @Override |
| 271 | public boolean isReachable(DeviceId deviceId) { |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 272 | //FIXME this is a workaround util device state is shared |
| 273 | // between controller instances. |
| 274 | Device device = deviceService.getDevice(deviceId); |
| 275 | String ip; |
| 276 | int port; |
| 277 | Socket socket = null; |
| 278 | if (device != null) { |
| 279 | ip = device.annotations().value(IPADDRESS); |
| 280 | port = Integer.parseInt(device.annotations().value(PORT)); |
| 281 | } else { |
| 282 | String[] info = deviceId.toString().split(":"); |
| 283 | if (info.length == 3) { |
| 284 | ip = info[1]; |
| 285 | port = Integer.parseInt(info[2]); |
| 286 | } else { |
| 287 | ip = Arrays.asList(info).stream().filter(el -> !el.equals(info[0]) |
| 288 | && !el.equals(info[info.length - 1])) |
| 289 | .reduce((t, u) -> t + ":" + u) |
| 290 | .get(); |
| 291 | log.debug("ip v6 {}", ip); |
| 292 | port = Integer.parseInt(info[info.length - 1]); |
| 293 | } |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 294 | } |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 295 | //test connection to device opening a socket to it. |
| 296 | try { |
| 297 | socket = new Socket(ip, port); |
Yuta HIGUCHI | 0454d70 | 2017-03-17 10:08:38 -0700 | [diff] [blame] | 298 | log.debug("rechability of {}, {}, {}", deviceId, socket.isConnected(), !socket.isClosed()); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 299 | return socket.isConnected() && !socket.isClosed(); |
| 300 | } catch (IOException e) { |
| 301 | log.info("Device {} is not reachable", deviceId); |
| 302 | return false; |
| 303 | } finally { |
| 304 | if (socket != null) { |
| 305 | try { |
| 306 | socket.close(); |
| 307 | } catch (IOException e) { |
| 308 | log.debug("Test Socket failed {} ", deviceId); |
| 309 | return false; |
| 310 | } |
| 311 | } |
| 312 | } |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 313 | } |
| 314 | |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 315 | @Override |
| 316 | public void changePortState(DeviceId deviceId, PortNumber portNumber, |
| 317 | boolean enable) { |
| 318 | // TODO if required |
| 319 | } |
| 320 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 321 | private class InnerNetconfDeviceListener implements NetconfDeviceListener { |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 322 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 323 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 324 | @Override |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 325 | public void deviceAdded(DeviceId deviceId) { |
| 326 | //no-op |
| 327 | log.debug("Netconf device {} added to Netconf subController", deviceId); |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | @Override |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 331 | public void deviceRemoved(DeviceId deviceId) { |
| 332 | Preconditions.checkNotNull(deviceId, ISNULL); |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 333 | |
| 334 | if (deviceService.getDevice(deviceId) != null) { |
| 335 | providerService.deviceDisconnected(deviceId); |
| 336 | log.debug("Netconf device {} removed from Netconf subController", deviceId); |
| 337 | } else { |
| 338 | log.warn("Netconf device {} does not exist in the store, " + |
Vidyashree Rama | d89a153 | 2017-03-30 15:13:52 +0530 | [diff] [blame] | 339 | "it may already have been removed", deviceId); |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 340 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 344 | private void connectDevices() { |
| 345 | NetconfProviderConfig cfg = cfgService.getConfig(appId, NetconfProviderConfig.class); |
| 346 | if (cfg != null) { |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 347 | try { |
Sho SHIMIZU | a09e1bb | 2016-08-01 14:25:25 -0700 | [diff] [blame] | 348 | cfg.getDevicesAddresses().forEach(addr -> { |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 349 | DeviceId deviceId = getDeviceId(addr.ip().toString(), addr.port()); |
| 350 | Preconditions.checkNotNull(deviceId, ISNULL); |
| 351 | //Netconf configuration object |
| 352 | ChassisId cid = new ChassisId(); |
| 353 | String ipAddress = addr.ip().toString(); |
| 354 | SparseAnnotations annotations = DefaultAnnotations.builder() |
| 355 | .set(IPADDRESS, ipAddress) |
| 356 | .set(PORT, String.valueOf(addr.port())) |
| 357 | .set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase()) |
| 358 | .build(); |
| 359 | DeviceDescription deviceDescription = new DefaultDeviceDescription( |
| 360 | deviceId.uri(), |
| 361 | Device.Type.SWITCH, |
| 362 | UNKNOWN, UNKNOWN, |
| 363 | UNKNOWN, UNKNOWN, |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 364 | cid, false, |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 365 | annotations); |
Himanshu Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 366 | storeDeviceKey(addr, deviceId); |
| 367 | |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 368 | if (deviceService.getDevice(deviceId) == null) { |
| 369 | providerService.deviceConnected(deviceId, deviceDescription); |
| 370 | } |
Yuta HIGUCHI | c2b82e3 | 2017-03-10 14:33:41 -0800 | [diff] [blame] | 371 | try { |
| 372 | checkAndUpdateDevice(deviceId, deviceDescription); |
| 373 | } catch (Exception e) { |
| 374 | log.error("Unhandled exception checking {}", deviceId, e); |
| 375 | } |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 376 | }); |
| 377 | } catch (ConfigException e) { |
| 378 | log.error("Cannot read config error " + e); |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | private void checkAndUpdateDevice(DeviceId deviceId, DeviceDescription deviceDescription) { |
Vidyashree Rama | d89a153 | 2017-03-30 15:13:52 +0530 | [diff] [blame] | 384 | Device device = deviceService.getDevice(deviceId); |
| 385 | if (device == null) { |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 386 | log.warn("Device {} has not been added to store, " + |
| 387 | "maybe due to a problem in connectivity", deviceId); |
| 388 | } else { |
| 389 | boolean isReachable = isReachable(deviceId); |
| 390 | if (isReachable && !deviceService.isAvailable(deviceId)) { |
Konstantinos Kanonakis | 4d67dd8 | 2016-08-05 12:18:52 -0500 | [diff] [blame] | 391 | if (device.is(DeviceDescriptionDiscovery.class)) { |
| 392 | if (mastershipService.isLocalMaster(deviceId)) { |
| 393 | DeviceDescriptionDiscovery deviceDescriptionDiscovery = |
| 394 | device.as(DeviceDescriptionDiscovery.class); |
Michele Santuari | 00cc1f7 | 2016-09-08 17:05:24 +0200 | [diff] [blame] | 395 | DeviceDescription updatedDeviceDescription = deviceDescriptionDiscovery.discoverDeviceDetails(); |
| 396 | if (updatedDeviceDescription != null && |
| 397 | !descriptionEquals(device, updatedDeviceDescription)) { |
| 398 | providerService.deviceConnected( |
| 399 | deviceId, new DefaultDeviceDescription( |
| 400 | updatedDeviceDescription, true, updatedDeviceDescription.annotations())); |
Michele Santuari | 576f09c | 2016-09-28 14:20:00 +0200 | [diff] [blame] | 401 | } else if (updatedDeviceDescription == null) { |
| 402 | providerService.deviceConnected( |
| 403 | deviceId, new DefaultDeviceDescription( |
| 404 | deviceDescription, true, deviceDescription.annotations())); |
Michele Santuari | 00cc1f7 | 2016-09-08 17:05:24 +0200 | [diff] [blame] | 405 | } |
| 406 | //if ports are not discovered, retry the discovery |
| 407 | if (deviceService.getPorts(deviceId).isEmpty()) { |
| 408 | discoverPorts(deviceId); |
| 409 | } |
Konstantinos Kanonakis | 4d67dd8 | 2016-08-05 12:18:52 -0500 | [diff] [blame] | 410 | } |
| 411 | } else { |
Michele Santuari | 576f09c | 2016-09-28 14:20:00 +0200 | [diff] [blame] | 412 | log.warn("No DeviceDescriptionDiscovery behaviour for device {} " + |
| 413 | "using DefaultDeviceDescription", deviceId); |
Vidyashree Rama | d89a153 | 2017-03-30 15:13:52 +0530 | [diff] [blame] | 414 | providerService.deviceConnected( |
| 415 | deviceId, new DefaultDeviceDescription( |
Michele Santuari | 576f09c | 2016-09-28 14:20:00 +0200 | [diff] [blame] | 416 | deviceDescription, true, deviceDescription.annotations())); |
Konstantinos Kanonakis | 4d67dd8 | 2016-08-05 12:18:52 -0500 | [diff] [blame] | 417 | } |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 418 | } else if (!isReachable && deviceService.isAvailable(deviceId)) { |
| 419 | providerService.deviceDisconnected(deviceId); |
Vidyashree Rama | d89a153 | 2017-03-30 15:13:52 +0530 | [diff] [blame] | 420 | } else if (isReachable && deviceService.isAvailable(deviceId)) { |
| 421 | updatePortStatistics(device); |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | } |
| 425 | |
Vidyashree Rama | d89a153 | 2017-03-30 15:13:52 +0530 | [diff] [blame] | 426 | private void updatePortStatistics(Device device) { |
| 427 | if (device.is(PortStatisticsDiscovery.class)) { |
| 428 | PortStatisticsDiscovery d = device.as(PortStatisticsDiscovery.class); |
| 429 | providerService.updatePortStatistics(device.id(), |
| 430 | d.discoverPortStatistics()); |
| 431 | } else { |
| 432 | log.warn("No port statistics getter behaviour for device {}", |
| 433 | device.id()); |
| 434 | } |
| 435 | } |
| 436 | |
Michele Santuari | 00cc1f7 | 2016-09-08 17:05:24 +0200 | [diff] [blame] | 437 | private boolean descriptionEquals(Device device, DeviceDescription updatedDeviceDescription) { |
Yuta HIGUCHI | f381fc7 | 2017-01-03 10:39:36 -0800 | [diff] [blame] | 438 | return Objects.equal(device.id().uri(), updatedDeviceDescription.deviceUri()) |
Michele Santuari | 00cc1f7 | 2016-09-08 17:05:24 +0200 | [diff] [blame] | 439 | && Objects.equal(device.type(), updatedDeviceDescription.type()) |
| 440 | && Objects.equal(device.manufacturer(), updatedDeviceDescription.manufacturer()) |
| 441 | && Objects.equal(device.hwVersion(), updatedDeviceDescription.hwVersion()) |
| 442 | && Objects.equal(device.swVersion(), updatedDeviceDescription.swVersion()) |
| 443 | && Objects.equal(device.serialNumber(), updatedDeviceDescription.serialNumber()) |
| 444 | && Objects.equal(device.chassisId(), updatedDeviceDescription.chassisId()) |
| 445 | && Objects.equal(device.annotations(), updatedDeviceDescription.annotations()); |
| 446 | } |
| 447 | |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 448 | private void checkAndUpdateDevices() { |
| 449 | NetconfProviderConfig cfg = cfgService.getConfig(appId, NetconfProviderConfig.class); |
| 450 | if (cfg != null) { |
| 451 | log.info("Checking connection to devices in configuration"); |
| 452 | try { |
Sho SHIMIZU | a09e1bb | 2016-08-01 14:25:25 -0700 | [diff] [blame] | 453 | cfg.getDevicesAddresses().forEach(addr -> { |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 454 | DeviceId deviceId = getDeviceId(addr.ip().toString(), addr.port()); |
| 455 | Preconditions.checkNotNull(deviceId, ISNULL); |
| 456 | //Netconf configuration object |
| 457 | ChassisId cid = new ChassisId(); |
| 458 | String ipAddress = addr.ip().toString(); |
| 459 | SparseAnnotations annotations = DefaultAnnotations.builder() |
| 460 | .set(IPADDRESS, ipAddress) |
| 461 | .set(PORT, String.valueOf(addr.port())) |
| 462 | .set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase()) |
| 463 | .build(); |
| 464 | DeviceDescription deviceDescription = new DefaultDeviceDescription( |
| 465 | deviceId.uri(), |
| 466 | Device.Type.SWITCH, |
| 467 | UNKNOWN, UNKNOWN, |
| 468 | UNKNOWN, UNKNOWN, |
| 469 | cid, false, |
| 470 | annotations); |
Himanshu Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 471 | storeDeviceKey(addr, deviceId); |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 472 | checkAndUpdateDevice(deviceId, deviceDescription); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 473 | }); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 474 | } catch (ConfigException e) { |
| 475 | log.error("Cannot read config error " + e); |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 476 | } |
| 477 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 478 | } |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 479 | |
Himanshu Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 480 | private void storeDeviceKey(NetconfProviderConfig.NetconfDeviceAddress addr, DeviceId deviceId) { |
| 481 | if (addr.sshkey().equals("")) { |
| 482 | deviceKeyAdminService.addKey( |
| 483 | DeviceKey.createDeviceKeyUsingUsernamePassword( |
| 484 | DeviceKeyId.deviceKeyId(deviceId.toString()), |
| 485 | null, addr.name(), addr.password())); |
| 486 | } else { |
| 487 | deviceKeyAdminService.addKey( |
| 488 | DeviceKey.createDeviceKeyUsingSshKey( |
| 489 | DeviceKeyId.deviceKeyId(deviceId.toString()), |
| 490 | null, addr.name(), addr.password(), addr.sshkey())); |
| 491 | } |
| 492 | } |
| 493 | |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 494 | private void initiateConnection(DeviceId deviceId, MastershipRole newRole) { |
| 495 | try { |
| 496 | if (isReachable(deviceId)) { |
| 497 | controller.connectDevice(deviceId); |
| 498 | providerService.receivedRoleReply(deviceId, newRole, MastershipRole.MASTER); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 499 | } |
| 500 | } catch (Exception e) { |
| 501 | if (deviceService.getDevice(deviceId) != null) { |
| 502 | providerService.deviceDisconnected(deviceId); |
| 503 | } |
| 504 | deviceKeyAdminService.removeKey(DeviceKeyId.deviceKeyId(deviceId.toString())); |
| 505 | throw new RuntimeException(new NetconfException( |
| 506 | "Can't connect to NETCONF " + "device on " + deviceId + ":" + deviceId, e)); |
| 507 | |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | private void discoverPorts(DeviceId deviceId) { |
| 512 | Device device = deviceService.getDevice(deviceId); |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 513 | //TODO remove when PortDiscovery is removed from master |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 514 | if (device.is(PortDiscovery.class)) { |
| 515 | PortDiscovery portConfig = device.as(PortDiscovery.class); |
| 516 | providerService.updatePorts(deviceId, |
| 517 | portConfig.getPorts()); |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 518 | } else if (device.is(DeviceDescriptionDiscovery.class)) { |
| 519 | DeviceDescriptionDiscovery deviceDescriptionDiscovery = |
| 520 | device.as(DeviceDescriptionDiscovery.class); |
| 521 | providerService.updatePorts(deviceId, |
| 522 | deviceDescriptionDiscovery.discoverPortDetails()); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 523 | } else { |
| 524 | log.warn("No portGetter behaviour for device {}", deviceId); |
| 525 | } |
Gaurav Agrawal | dab4d77 | 2017-03-29 15:15:13 +0530 | [diff] [blame] | 526 | |
| 527 | // Port statistics discovery |
Vidyashree Rama | d89a153 | 2017-03-30 15:13:52 +0530 | [diff] [blame] | 528 | updatePortStatistics(device); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Return the DeviceId about the device containing the URI. |
| 533 | * |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 534 | * @param ip IP address |
Ray Milkey | d4334db | 2016-04-05 17:39:44 -0700 | [diff] [blame] | 535 | * @param port port number |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 536 | * @return DeviceId |
| 537 | */ |
| 538 | public DeviceId getDeviceId(String ip, int port) { |
| 539 | try { |
| 540 | return DeviceId.deviceId(new URI(NETCONF, ip + ":" + port, null)); |
| 541 | } catch (URISyntaxException e) { |
| 542 | throw new IllegalArgumentException("Unable to build deviceID for device " |
| 543 | + ip + ":" + port, e); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * Listener for configuration events. |
| 549 | */ |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 550 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 551 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 552 | |
| 553 | @Override |
| 554 | public void event(NetworkConfigEvent event) { |
Andrea Campanella | 90f044f | 2016-03-02 09:14:57 -0800 | [diff] [blame] | 555 | executor.execute(NetconfDeviceProvider.this::connectDevices); |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 556 | } |
| 557 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 558 | @Override |
| 559 | public boolean isRelevant(NetworkConfigEvent event) { |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 560 | return event.configClass().equals(NetconfProviderConfig.class) && |
| 561 | (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || |
| 562 | event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED); |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 563 | } |
| 564 | } |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 565 | |
| 566 | /** |
| 567 | * Listener for core device events. |
| 568 | */ |
| 569 | private class InternalDeviceListener implements DeviceListener { |
| 570 | @Override |
| 571 | public void event(DeviceEvent event) { |
| 572 | if ((event.type() == DeviceEvent.Type.DEVICE_ADDED)) { |
| 573 | executor.execute(() -> discoverPorts(event.subject().id())); |
| 574 | } else if ((event.type() == DeviceEvent.Type.DEVICE_REMOVED)) { |
| 575 | log.debug("removing device {}", event.subject().id()); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 576 | controller.disconnectDevice(event.subject().id(), true); |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | @Override |
| 581 | public boolean isRelevant(DeviceEvent event) { |
| 582 | if (mastershipService.getMasterFor(event.subject().id()) == null) { |
| 583 | return true; |
| 584 | } |
Yuta HIGUCHI | 8c6a7e8 | 2017-03-14 18:35:43 -0700 | [diff] [blame] | 585 | return SCHEME_NAME.toUpperCase() |
| 586 | .equals(event.subject().annotations().value(AnnotationKeys.PROTOCOL)) && |
Michele Santuari | 576f09c | 2016-09-28 14:20:00 +0200 | [diff] [blame] | 587 | mastershipService.isLocalMaster(event.subject().id()); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 588 | } |
| 589 | } |
Sanjay S | e8dcfee | 2015-04-23 10:07:08 +0530 | [diff] [blame] | 590 | } |