blob: fe5cda9973d507d133aa9a787616cdbdc93b72ad [file] [log] [blame]
Sanjay Se8dcfee2015-04-23 10:07:08 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Sanjay Se8dcfee2015-04-23 10:07:08 +05303 *
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 */
andreaeb70a942015-10-16 21:34:46 -070016
Sanjay Se8dcfee2015-04-23 10:07:08 +053017package org.onosproject.provider.netconf.device.impl;
18
Michele Santuari00cc1f72016-09-08 17:05:24 +020019import com.google.common.base.Objects;
andreaeb70a942015-10-16 21:34:46 -070020import com.google.common.base.Preconditions;
Andrea Campanella42e7b862018-09-21 11:56:48 +020021import com.google.common.util.concurrent.Striped;
David K. Bainbridge56e90232018-12-18 23:25:08 -080022import org.apache.commons.lang3.tuple.Triple;
Sanjay Se8dcfee2015-04-23 10:07:08 +053023import org.onlab.packet.ChassisId;
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -070024import org.onlab.util.Tools;
25import org.onosproject.cfg.ComponentConfigService;
andreaeb70a942015-10-16 21:34:46 -070026import org.onosproject.core.ApplicationId;
27import org.onosproject.core.CoreService;
Andrea Campanella7e6200a2016-03-21 09:48:40 -070028import org.onosproject.mastership.MastershipService;
Marc De Leenheerb0d131c2016-03-01 20:34:59 -080029import org.onosproject.net.AnnotationKeys;
andreaeb70a942015-10-16 21:34:46 -070030import org.onosproject.net.DefaultAnnotations;
Sanjay Se8dcfee2015-04-23 10:07:08 +053031import org.onosproject.net.Device;
32import org.onosproject.net.DeviceId;
33import org.onosproject.net.MastershipRole;
Ray Milkey02710432018-02-13 17:08:28 -080034import org.onosproject.net.Port;
Saurav Dasa2d37502016-03-25 17:50:40 -070035import org.onosproject.net.PortNumber;
andreaeb70a942015-10-16 21:34:46 -070036import org.onosproject.net.SparseAnnotations;
Ray Milkey02710432018-02-13 17:08:28 -080037import org.onosproject.net.behaviour.PortAdmin;
andreaeb70a942015-10-16 21:34:46 -070038import org.onosproject.net.config.ConfigFactory;
39import org.onosproject.net.config.NetworkConfigEvent;
40import org.onosproject.net.config.NetworkConfigListener;
41import org.onosproject.net.config.NetworkConfigRegistry;
Andrea Campanella34cf65c2017-04-12 13:51:32 +020042import org.onosproject.net.config.basics.SubjectFactories;
Sanjay Se8dcfee2015-04-23 10:07:08 +053043import org.onosproject.net.device.DefaultDeviceDescription;
Andrea Campanella32813682017-10-23 15:29:24 +020044import org.onosproject.net.device.DefaultPortDescription;
Sanjay Se8dcfee2015-04-23 10:07:08 +053045import org.onosproject.net.device.DeviceDescription;
Andrea Campanella6c71a052016-04-22 11:56:31 -070046import org.onosproject.net.device.DeviceDescriptionDiscovery;
Andrea Campanella7e6200a2016-03-21 09:48:40 -070047import org.onosproject.net.device.DeviceEvent;
48import org.onosproject.net.device.DeviceListener;
Sanjay Se8dcfee2015-04-23 10:07:08 +053049import org.onosproject.net.device.DeviceProvider;
50import org.onosproject.net.device.DeviceProviderRegistry;
51import org.onosproject.net.device.DeviceProviderService;
Aaron Kruglikov17b4c852016-01-15 16:37:04 -080052import org.onosproject.net.device.DeviceService;
Andrea Campanellac3627842017-04-04 18:06:54 +020053import org.onosproject.net.device.PortStatistics;
Gaurav Agrawaldab4d772017-03-29 15:15:13 +053054import org.onosproject.net.device.PortStatisticsDiscovery;
Andrea Campanella7e6200a2016-03-21 09:48:40 -070055import org.onosproject.net.key.DeviceKey;
56import org.onosproject.net.key.DeviceKeyAdminService;
57import org.onosproject.net.key.DeviceKeyId;
Sanjay Se8dcfee2015-04-23 10:07:08 +053058import org.onosproject.net.provider.AbstractProvider;
59import org.onosproject.net.provider.ProviderId;
andreaeb70a942015-10-16 21:34:46 -070060import org.onosproject.netconf.NetconfController;
Yuta HIGUCHI3a50b0d2017-07-10 11:11:54 -070061import org.onosproject.netconf.NetconfDevice;
andreaeb70a942015-10-16 21:34:46 -070062import org.onosproject.netconf.NetconfDeviceListener;
Andrea Campanella8b1cb672016-01-25 13:58:58 -080063import org.onosproject.netconf.NetconfException;
Yuta HIGUCHIb6e0e912017-05-18 20:13:52 -070064import org.onosproject.netconf.config.NetconfDeviceConfig;
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -070065import org.osgi.service.component.ComponentContext;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070066import org.osgi.service.component.annotations.Activate;
67import org.osgi.service.component.annotations.Component;
68import org.osgi.service.component.annotations.Deactivate;
69import org.osgi.service.component.annotations.Modified;
70import org.osgi.service.component.annotations.Reference;
71import org.osgi.service.component.annotations.ReferenceCardinality;
Sanjay Se8dcfee2015-04-23 10:07:08 +053072import org.slf4j.Logger;
73
Andrea Campanella087ceb92015-12-07 09:58:34 -080074import java.io.IOException;
Andrea Campanella42e7b862018-09-21 11:56:48 +020075import java.net.InetSocketAddress;
Andrea Campanella7e6200a2016-03-21 09:48:40 -070076import java.net.Socket;
77import java.net.URI;
78import java.net.URISyntaxException;
Andrea Campanellac3627842017-04-04 18:06:54 +020079import java.util.Collection;
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -070080import java.util.Dictionary;
mskala832d0472017-06-09 16:31:42 +020081import java.util.Map;
Yuta HIGUCHI3a50b0d2017-07-10 11:11:54 -070082import java.util.Optional;
Andrea Campanella34cf65c2017-04-12 13:51:32 +020083import java.util.Set;
Andrea Campanella32813682017-10-23 15:29:24 +020084import java.util.concurrent.CompletableFuture;
mskala832d0472017-06-09 16:31:42 +020085import java.util.concurrent.ConcurrentHashMap;
Andrea Campanella5c999e22016-03-01 15:12:53 -080086import java.util.concurrent.ExecutorService;
87import java.util.concurrent.Executors;
helenyrwufd296b62016-06-22 17:43:02 -070088import java.util.concurrent.ScheduledExecutorService;
89import java.util.concurrent.ScheduledFuture;
90import java.util.concurrent.TimeUnit;
mskala832d0472017-06-09 16:31:42 +020091import java.util.concurrent.atomic.AtomicInteger;
Andrea Campanella42e7b862018-09-21 11:56:48 +020092import java.util.concurrent.locks.Lock;
93import java.util.function.Supplier;
andreaeb70a942015-10-16 21:34:46 -070094
Yuta HIGUCHI1624df12016-07-21 16:54:33 -070095import static java.util.concurrent.Executors.newScheduledThreadPool;
Andrea Campanella5c999e22016-03-01 15:12:53 -080096import static org.onlab.util.Tools.groupedThreads;
Thomas Vachuska4167c3f2018-10-16 07:16:31 -070097import static org.onosproject.provider.netconf.device.impl.OsgiPropertyConstants.*;
David K. Bainbridge56e90232018-12-18 23:25:08 -080098import static org.onosproject.netconf.NetconfDeviceInfo.extractIpPortPath;
andreaeb70a942015-10-16 21:34:46 -070099import static org.slf4j.LoggerFactory.getLogger;
100
Sanjay Se8dcfee2015-04-23 10:07:08 +0530101/**
andreaeb70a942015-10-16 21:34:46 -0700102 * Provider which uses an NETCONF controller to detect device.
Sanjay Se8dcfee2015-04-23 10:07:08 +0530103 */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700104@Component(immediate = true,
105 property = {
106 POLL_FREQUENCY_SECONDS_DEFAULT + ":Integer=" + POLL_FREQUENCY_SECONDS_DEFAULT,
107 MAX_RETRIES + ":Integer=" + MAX_RETRIES_DEFAULT,
108 })
Sanjay Se8dcfee2015-04-23 10:07:08 +0530109public class NetconfDeviceProvider extends AbstractProvider
110 implements DeviceProvider {
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700111
andreaeb70a942015-10-16 21:34:46 -0700112 private final Logger log = getLogger(getClass());
Sanjay Se8dcfee2015-04-23 10:07:08 +0530113
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700114 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Sanjay Se8dcfee2015-04-23 10:07:08 +0530115 protected DeviceProviderRegistry providerRegistry;
116
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700117 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Andrea Campanella101417d2015-12-11 17:58:07 -0800118 protected NetconfController controller;
Sanjay Se8dcfee2015-04-23 10:07:08 +0530119
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700120 @Reference(cardinality = ReferenceCardinality.MANDATORY)
andreaeb70a942015-10-16 21:34:46 -0700121 protected NetworkConfigRegistry cfgService;
Sanjay Se8dcfee2015-04-23 10:07:08 +0530122
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700123 @Reference(cardinality = ReferenceCardinality.MANDATORY)
andreaeb70a942015-10-16 21:34:46 -0700124 protected CoreService coreService;
Thomas Vachuskad6811712015-04-29 21:37:04 -0700125
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700126 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700127 protected DeviceService deviceService;
Aaron Kruglikov17b4c852016-01-15 16:37:04 -0800128
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700129 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700130 protected DeviceKeyAdminService deviceKeyAdminService;
131
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700132 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700133 protected MastershipService mastershipService;
134
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700135 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -0700136 protected ComponentConfigService componentConfigService;
137
138
Michele Santuari576f09c2016-09-28 14:20:00 +0200139 protected static final String APP_NAME = "org.onosproject.netconf";
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200140 protected static final String SCHEME_NAME = "netconf";
Andrea Campanella101417d2015-12-11 17:58:07 -0800141 private static final String DEVICE_PROVIDER_PACKAGE = "org.onosproject.netconf.provider.device";
142 private static final String UNKNOWN = "unknown";
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700143 protected static final String ISNULL = "NetconfDeviceInfo is null";
144 private static final String IPADDRESS = "ipaddress";
145 private static final String NETCONF = "netconf";
146 private static final String PORT = "port";
David K. Bainbridge56e90232018-12-18 23:25:08 -0800147 private static final String PATH = "path";
helenyrwufd296b62016-06-22 17:43:02 -0700148 private static final int CORE_POOL_SIZE = 10;
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -0700149
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700150 /** Configure poll frequency for port status and statistics; default is 30 sec. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700151 private int pollFrequency = POLL_FREQUENCY_SECONDS_DEFAULT;
Sanjay Se8dcfee2015-04-23 10:07:08 +0530152
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700153 /** Configure maximum allowed number of retries for obtaining list of ports; default is 5 times. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700154 private int maxRetries = MAX_RETRIES_DEFAULT;
mskala832d0472017-06-09 16:31:42 +0200155
Michal Mach26a90fa2017-06-07 11:12:46 +0200156 protected ExecutorService executor =
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700157 Executors.newFixedThreadPool(5, groupedThreads("onos/netconfdeviceprovider",
158 "device-installer-%d", log));
Yuta HIGUCHI1624df12016-07-21 16:54:33 -0700159 protected ScheduledExecutorService connectionExecutor
160 = newScheduledThreadPool(CORE_POOL_SIZE,
161 groupedThreads("onos/netconfdeviceprovider",
162 "connection-executor-%d", log));
Andrea Campanella5c999e22016-03-01 15:12:53 -0800163
Michele Santuari576f09c2016-09-28 14:20:00 +0200164 protected DeviceProviderService providerService;
andreaeb70a942015-10-16 21:34:46 -0700165 private NetconfDeviceListener innerNodeListener = new InnerNetconfDeviceListener();
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700166 private InternalDeviceListener deviceListener = new InternalDeviceListener();
mskala832d0472017-06-09 16:31:42 +0200167 private final Map<DeviceId, AtomicInteger> retriedPortDiscoveryMap = new ConcurrentHashMap<>();
Michele Santuari576f09c2016-09-28 14:20:00 +0200168 protected ScheduledFuture<?> scheduledTask;
Sanjay Se8dcfee2015-04-23 10:07:08 +0530169
Ray Milkey02710432018-02-13 17:08:28 -0800170 protected final ConfigFactory factory =
Yuta HIGUCHIb6e0e912017-05-18 20:13:52 -0700171 // TODO consider moving Config registration to NETCONF ctl bundle
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200172 new ConfigFactory<DeviceId, NetconfDeviceConfig>(
173 SubjectFactories.DEVICE_SUBJECT_FACTORY,
Yuta HIGUCHIb6e0e912017-05-18 20:13:52 -0700174 NetconfDeviceConfig.class, NetconfDeviceConfig.CONFIG_KEY) {
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200175 @Override
176 public NetconfDeviceConfig createConfig() {
177 return new NetconfDeviceConfig();
178 }
Ray Milkey02710432018-02-13 17:08:28 -0800179 };
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200180
Michele Santuari576f09c2016-09-28 14:20:00 +0200181 protected final NetworkConfigListener cfgListener = new InternalNetworkConfigListener();
andreaeb70a942015-10-16 21:34:46 -0700182 private ApplicationId appId;
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700183 private boolean active;
Andrea Campanella42e7b862018-09-21 11:56:48 +0200184 private final Striped<Lock> deviceLocks = Striped.lock(30);
Sanjay Se8dcfee2015-04-23 10:07:08 +0530185
Sanjay Se8dcfee2015-04-23 10:07:08 +0530186
187 @Activate
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -0700188 public void activate(ComponentContext context) {
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700189 active = true;
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -0700190 componentConfigService.registerProperties(getClass());
Sanjay Se8dcfee2015-04-23 10:07:08 +0530191 providerService = providerRegistry.register(this);
Andrea Campanella101417d2015-12-11 17:58:07 -0800192 appId = coreService.registerApplication(APP_NAME);
Ray Milkey02710432018-02-13 17:08:28 -0800193 cfgService.registerConfigFactory(factory);
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700194 cfgService.addListener(cfgListener);
andreaeb70a942015-10-16 21:34:46 -0700195 controller.addDeviceListener(innerNodeListener);
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700196 deviceService.addListener(deviceListener);
Andrea Campanella7d8449b2016-03-02 10:16:42 -0800197 executor.execute(NetconfDeviceProvider.this::connectDevices);
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -0700198 modified(context);
Thomas Vachuskad6811712015-04-29 21:37:04 -0700199 log.info("Started");
Sanjay Se8dcfee2015-04-23 10:07:08 +0530200 }
201
andreaeb70a942015-10-16 21:34:46 -0700202
Sanjay Se8dcfee2015-04-23 10:07:08 +0530203 @Deactivate
andreaeb70a942015-10-16 21:34:46 -0700204 public void deactivate() {
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -0700205 componentConfigService.unregisterProperties(getClass(), false);
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700206 deviceService.removeListener(deviceListener);
207 active = false;
208 controller.getNetconfDevices().forEach(id -> {
209 deviceKeyAdminService.removeKey(DeviceKeyId.deviceKeyId(id.toString()));
210 controller.disconnectDevice(id, true);
211 });
Andrea Campanella86294db2016-03-07 11:42:49 -0800212 controller.removeDeviceListener(innerNodeListener);
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700213 deviceService.removeListener(deviceListener);
Sanjay Se8dcfee2015-04-23 10:07:08 +0530214 providerRegistry.unregister(this);
215 providerService = null;
mskala832d0472017-06-09 16:31:42 +0200216 retriedPortDiscoveryMap.clear();
Ray Milkey02710432018-02-13 17:08:28 -0800217 cfgService.unregisterConfigFactory(factory);
helenyrwufd296b62016-06-22 17:43:02 -0700218 scheduledTask.cancel(true);
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700219 executor.shutdown();
Sanjay Seb5eebb2015-04-24 15:44:50 +0530220 log.info("Stopped");
Sanjay Se8dcfee2015-04-23 10:07:08 +0530221 }
222
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -0700223
224 @Modified
225 public void modified(ComponentContext context) {
226 if (context != null) {
227 Dictionary<?, ?> properties = context.getProperties();
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700228 pollFrequency = Tools.getIntegerProperty(properties, POLL_FREQUENCY_SECONDS,
229 POLL_FREQUENCY_SECONDS_DEFAULT);
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -0700230 log.info("Configured. Poll frequency is configured to {} seconds", pollFrequency);
mskala832d0472017-06-09 16:31:42 +0200231
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700232 maxRetries = Tools.getIntegerProperty(properties, MAX_RETRIES, MAX_RETRIES_DEFAULT);
mskala832d0472017-06-09 16:31:42 +0200233 log.info("Configured. Number of retries is configured to {} times", maxRetries);
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -0700234 }
235 if (scheduledTask != null) {
236 scheduledTask.cancel(false);
237 }
238 scheduledTask = schedulePolling();
239 }
240
andreaeb70a942015-10-16 21:34:46 -0700241 public NetconfDeviceProvider() {
Andrea Campanella101417d2015-12-11 17:58:07 -0800242 super(new ProviderId(SCHEME_NAME, DEVICE_PROVIDER_PACKAGE));
Sanjay Se8dcfee2015-04-23 10:07:08 +0530243 }
244
helenyrwufd296b62016-06-22 17:43:02 -0700245 // Checks connection to devices in the config file
246 // every DEFAULT_POLL_FREQUENCY_SECONDS seconds.
247 private ScheduledFuture schedulePolling() {
Yuta HIGUCHIc2b82e32017-03-10 14:33:41 -0800248 return connectionExecutor.scheduleAtFixedRate(exceptionSafe(this::checkAndUpdateDevices),
Thomas Vachuskaf3aaa8d2017-03-31 10:43:58 -0700249 pollFrequency / 10,
250 pollFrequency, TimeUnit.SECONDS);
helenyrwufd296b62016-06-22 17:43:02 -0700251 }
252
Yuta HIGUCHIc2b82e32017-03-10 14:33:41 -0800253 private Runnable exceptionSafe(Runnable runnable) {
254 return new Runnable() {
255
256 @Override
257 public void run() {
258 try {
259 runnable.run();
260 } catch (Exception e) {
261 log.error("Unhandled Exception", e);
262 }
263 }
264 };
265 }
266
Sanjay Se8dcfee2015-04-23 10:07:08 +0530267 @Override
268 public void triggerProbe(DeviceId deviceId) {
andreaeb70a942015-10-16 21:34:46 -0700269 // TODO: This will be implemented later.
Yuta HIGUCHIe4cb8cf2017-05-01 22:18:28 -0700270 log.debug("Should be triggering probe on device {}", deviceId);
Sanjay Se8dcfee2015-04-23 10:07:08 +0530271 }
272
273 @Override
274 public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700275 if (active) {
276 switch (newRole) {
277 case MASTER:
Andrea Campanella42e7b862018-09-21 11:56:48 +0200278 withDeviceLock(
279 () -> initiateConnection(deviceId, newRole), deviceId).run();
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700280 log.debug("Accepting mastership role change to {} for device {}", newRole, deviceId);
281 break;
282 case STANDBY:
283 controller.disconnectDevice(deviceId, false);
284 providerService.receivedRoleReply(deviceId, newRole, MastershipRole.STANDBY);
285 //else no-op
286 break;
287 case NONE:
288 controller.disconnectDevice(deviceId, false);
289 providerService.receivedRoleReply(deviceId, newRole, MastershipRole.NONE);
290 break;
291 default:
292 log.error("Unimplemented Mastership state : {}", newRole);
293
294 }
295 }
Sanjay Se8dcfee2015-04-23 10:07:08 +0530296 }
297
298 @Override
299 public boolean isReachable(DeviceId deviceId) {
Yuta HIGUCHI3a50b0d2017-07-10 11:11:54 -0700300
301 boolean sessionExists =
302 Optional.ofNullable(controller.getDevicesMap().get(deviceId))
303 .map(NetconfDevice::isActive)
304 .orElse(false);
305 if (sessionExists) {
306 return true;
307 }
308
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700309 //FIXME this is a workaround util device state is shared
310 // between controller instances.
311 Device device = deviceService.getDevice(deviceId);
312 String ip;
313 int port;
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700314 if (device != null) {
315 ip = device.annotations().value(IPADDRESS);
316 port = Integer.parseInt(device.annotations().value(PORT));
317 } else {
David K. Bainbridge56e90232018-12-18 23:25:08 -0800318 Triple<String, Integer, Optional<String>> info = extractIpPortPath(deviceId);
319 ip = info.getLeft();
320 port = info.getMiddle();
Sanjay Se8dcfee2015-04-23 10:07:08 +0530321 }
Yuta HIGUCHI3a50b0d2017-07-10 11:11:54 -0700322 // FIXME just opening TCP session probably is not the appropriate
323 // method to test reachability.
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700324 //test connection to device opening a socket to it.
Yuta HIGUCHI3a50b0d2017-07-10 11:11:54 -0700325 log.debug("Testing reachability for {}:{}", ip, port);
Andrea Campanella42e7b862018-09-21 11:56:48 +0200326 Socket socket = new Socket();
327 try {
328 socket.connect(new InetSocketAddress(ip, port), 1000);
Yuta HIGUCHI0454d702017-03-17 10:08:38 -0700329 log.debug("rechability of {}, {}, {}", deviceId, socket.isConnected(), !socket.isClosed());
Andrea Campanella42e7b862018-09-21 11:56:48 +0200330 boolean isConnected = socket.isConnected() && !socket.isClosed();
331 socket.close();
332 return isConnected;
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700333 } catch (IOException e) {
334 log.info("Device {} is not reachable", deviceId);
Yuta HIGUCHI3a50b0d2017-07-10 11:11:54 -0700335 log.debug(" error details", e);
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700336 return false;
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700337 }
Sanjay Se8dcfee2015-04-23 10:07:08 +0530338 }
339
Saurav Dasa2d37502016-03-25 17:50:40 -0700340 @Override
341 public void changePortState(DeviceId deviceId, PortNumber portNumber,
342 boolean enable) {
Andrea Campanella32813682017-10-23 15:29:24 +0200343 Device device = deviceService.getDevice(deviceId);
344 if (mastershipService.isLocalMaster(deviceId)) {
345 if (device.is(PortAdmin.class)) {
346 PortAdmin portAdmin =
347 device.as(PortAdmin.class);
348 CompletableFuture<Boolean> modified;
349 if (enable) {
350 modified = portAdmin.enable(portNumber);
351 } else {
352 modified = portAdmin.disable(portNumber);
353 }
354 modified.thenAccept(result -> {
355 if (result) {
356 Port port = deviceService.getPort(deviceId, portNumber);
357 //rebuilding port description with admin state changed.
358 providerService.portStatusChanged(deviceId,
Yuta HIGUCHI53e47962018-03-01 23:50:48 -0800359 DefaultPortDescription.builder()
360 .withPortNumber(portNumber)
361 .isEnabled(enable)
362 .isRemoved(false)
363 .type(port.type())
364 .portSpeed(port.portSpeed())
365 .annotations((SparseAnnotations) port.annotations())
366 .build());
Andrea Campanella32813682017-10-23 15:29:24 +0200367 } else {
368 log.warn("Your device {} port {} status can't be changed to {}",
369 deviceId, portNumber, enable);
370 }
371 });
372 } else {
373 log.warn("Device {} does not support Port Admin", deviceId);
374 }
375 } else {
376 log.debug("Not master but {}, not changing port state", mastershipService.getLocalRole(deviceId));
377 }
Saurav Dasa2d37502016-03-25 17:50:40 -0700378 }
379
Thomas Vachuska5b38dc02018-05-10 15:24:40 -0700380 @Override
381 public void triggerDisconnect(DeviceId deviceId) {
382 log.debug("Forcing disconnect for device {}", deviceId);
383 controller.disconnectDevice(deviceId, true);
384 }
385
andreaeb70a942015-10-16 21:34:46 -0700386 private class InnerNetconfDeviceListener implements NetconfDeviceListener {
Sanjay Se8dcfee2015-04-23 10:07:08 +0530387
Andrea Campanella101417d2015-12-11 17:58:07 -0800388
andreaeb70a942015-10-16 21:34:46 -0700389 @Override
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700390 public void deviceAdded(DeviceId deviceId) {
391 //no-op
392 log.debug("Netconf device {} added to Netconf subController", deviceId);
Sanjay Se8dcfee2015-04-23 10:07:08 +0530393 }
394
395 @Override
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700396 public void deviceRemoved(DeviceId deviceId) {
397 Preconditions.checkNotNull(deviceId, ISNULL);
helenyrwufd296b62016-06-22 17:43:02 -0700398
399 if (deviceService.getDevice(deviceId) != null) {
400 providerService.deviceDisconnected(deviceId);
mskala832d0472017-06-09 16:31:42 +0200401 retriedPortDiscoveryMap.remove(deviceId);
helenyrwufd296b62016-06-22 17:43:02 -0700402 log.debug("Netconf device {} removed from Netconf subController", deviceId);
403 } else {
404 log.warn("Netconf device {} does not exist in the store, " +
Vidyashree Ramad89a1532017-03-30 15:13:52 +0530405 "it may already have been removed", deviceId);
helenyrwufd296b62016-06-22 17:43:02 -0700406 }
andreaeb70a942015-10-16 21:34:46 -0700407 }
408 }
409
andreaeb70a942015-10-16 21:34:46 -0700410 private void connectDevices() {
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200411 Set<DeviceId> deviceSubjects =
412 cfgService.getSubjects(DeviceId.class, NetconfDeviceConfig.class);
413 deviceSubjects.forEach(deviceId -> {
Yuta HIGUCHIb6e0e912017-05-18 20:13:52 -0700414 connectDevice(cfgService.getConfig(deviceId, NetconfDeviceConfig.class));
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200415 });
helenyrwufd296b62016-06-22 17:43:02 -0700416 }
417
Yuta HIGUCHIb6e0e912017-05-18 20:13:52 -0700418
419 private void connectDevice(NetconfDeviceConfig config) {
420 if (config == null) {
421 return;
422 }
423 DeviceId deviceId = config.subject();
424 if (!deviceId.uri().getScheme().equals(SCHEME_NAME)) {
425 // not under my scheme, skipping
426 log.trace("{} not my scheme, skipping", deviceId);
427 return;
428 }
Andrea Campanella42e7b862018-09-21 11:56:48 +0200429 if (!isReachable(deviceId)) {
430 log.warn("Can't connect to device {}", deviceId);
431 return;
432 }
Yuta HIGUCHIb6e0e912017-05-18 20:13:52 -0700433 DeviceDescription deviceDescription = createDeviceRepresentation(deviceId, config);
David K. Bainbridge56e90232018-12-18 23:25:08 -0800434 log.debug("Connecting NETCONF device {}, on {}:{}{} with username {}",
435 deviceId, config.ip(), config.port(),
436 (config.path().isPresent() ? "/" + config.path().get() : ""),
437 config.username());
Yuta HIGUCHIb6e0e912017-05-18 20:13:52 -0700438 storeDeviceKey(config.sshKey(), config.username(), config.password(), deviceId);
Andrea Campanella105736e2017-11-23 12:52:43 +0100439 retriedPortDiscoveryMap.put(deviceId, new AtomicInteger(0));
Yuta HIGUCHIb6e0e912017-05-18 20:13:52 -0700440 if (deviceService.getDevice(deviceId) == null) {
441 providerService.deviceConnected(deviceId, deviceDescription);
442 }
Yuta HIGUCHIb6e0e912017-05-18 20:13:52 -0700443 }
444
Andrea Campanella105736e2017-11-23 12:52:43 +0100445 private void checkAndUpdateDevice(DeviceId deviceId, DeviceDescription deviceDescription, boolean newlyConnected) {
Vidyashree Ramad89a1532017-03-30 15:13:52 +0530446 Device device = deviceService.getDevice(deviceId);
447 if (device == null) {
Andrea Campanella105736e2017-11-23 12:52:43 +0100448 log.debug("Device {} has not been added to store, since it's not reachable", deviceId);
449 return;
450 }
451 boolean isReachable = isReachable(deviceId);
452 if (!isReachable && deviceService.isAvailable(deviceId)) {
453 providerService.deviceDisconnected(deviceId);
454 return;
Andrea Campanella42e7b862018-09-21 11:56:48 +0200455 } else if (newlyConnected && mastershipService.isLocalMaster(deviceId)) {
Andrea Campanella105736e2017-11-23 12:52:43 +0100456 updateDeviceDescription(deviceId, deviceDescription, device);
457 }
458 if (isReachable && deviceService.isAvailable(deviceId) &&
459 mastershipService.isLocalMaster(deviceId)) {
460 //if ports are not discovered, retry the discovery
David K. Bainbridgee6a00f02018-11-07 11:43:43 -0800461 AtomicInteger count = retriedPortDiscoveryMap.get(deviceId);
Andrea Campanella105736e2017-11-23 12:52:43 +0100462 if (deviceService.getPorts(deviceId).isEmpty() &&
David K. Bainbridgee6a00f02018-11-07 11:43:43 -0800463 count != null && count.getAndIncrement() < maxRetries) {
Andrea Campanella105736e2017-11-23 12:52:43 +0100464 discoverPorts(deviceId);
465 }
466 updatePortStatistics(device);
467 }
468 }
469
470 private void updateDeviceDescription(DeviceId deviceId, DeviceDescription deviceDescription, Device device) {
471 if (device.is(DeviceDescriptionDiscovery.class)) {
472 if (mastershipService.isLocalMaster(deviceId)) {
473 DeviceDescriptionDiscovery deviceDescriptionDiscovery =
474 device.as(DeviceDescriptionDiscovery.class);
475 DeviceDescription updatedDeviceDescription =
476 deviceDescriptionDiscovery.discoverDeviceDetails();
477 if (updatedDeviceDescription != null &&
478 !descriptionEquals(device, updatedDeviceDescription)) {
Vidyashree Ramad89a1532017-03-30 15:13:52 +0530479 providerService.deviceConnected(
480 deviceId, new DefaultDeviceDescription(
Andrea Campanella105736e2017-11-23 12:52:43 +0100481 updatedDeviceDescription, true,
482 updatedDeviceDescription.annotations()));
Ray Milkey33306ba2018-09-20 13:27:25 -0700483 } else if (updatedDeviceDescription == null) {
Andrea Campanella105736e2017-11-23 12:52:43 +0100484 providerService.deviceConnected(
485 deviceId, new DefaultDeviceDescription(
486 deviceDescription, true,
487 deviceDescription.annotations()));
Konstantinos Kanonakis4d67dd82016-08-05 12:18:52 -0500488 }
helenyrwufd296b62016-06-22 17:43:02 -0700489 }
Andrea Campanella105736e2017-11-23 12:52:43 +0100490 } else {
491 log.warn("No DeviceDescriptionDiscovery behaviour for device {} " +
492 "using DefaultDeviceDescription", deviceId);
493 providerService.deviceConnected(
494 deviceId, new DefaultDeviceDescription(
495 deviceDescription, true, deviceDescription.annotations()));
helenyrwufd296b62016-06-22 17:43:02 -0700496 }
497 }
498
Vidyashree Ramad89a1532017-03-30 15:13:52 +0530499 private void updatePortStatistics(Device device) {
500 if (device.is(PortStatisticsDiscovery.class)) {
501 PortStatisticsDiscovery d = device.as(PortStatisticsDiscovery.class);
Andrea Campanellac3627842017-04-04 18:06:54 +0200502 Collection<PortStatistics> portStatistics = d.discoverPortStatistics();
503 if (portStatistics != null) {
504 providerService.updatePortStatistics(device.id(),
505 portStatistics);
506 }
Vidyashree Ramad89a1532017-03-30 15:13:52 +0530507 } else {
Yuta HIGUCHIe4cb8cf2017-05-01 22:18:28 -0700508 log.debug("No port statistics getter behaviour for device {}",
509 device.id());
Vidyashree Ramad89a1532017-03-30 15:13:52 +0530510 }
511 }
512
Michele Santuari00cc1f72016-09-08 17:05:24 +0200513 private boolean descriptionEquals(Device device, DeviceDescription updatedDeviceDescription) {
Yuta HIGUCHIf381fc72017-01-03 10:39:36 -0800514 return Objects.equal(device.id().uri(), updatedDeviceDescription.deviceUri())
Michele Santuari00cc1f72016-09-08 17:05:24 +0200515 && Objects.equal(device.type(), updatedDeviceDescription.type())
516 && Objects.equal(device.manufacturer(), updatedDeviceDescription.manufacturer())
517 && Objects.equal(device.hwVersion(), updatedDeviceDescription.hwVersion())
518 && Objects.equal(device.swVersion(), updatedDeviceDescription.swVersion())
519 && Objects.equal(device.serialNumber(), updatedDeviceDescription.serialNumber())
520 && Objects.equal(device.chassisId(), updatedDeviceDescription.chassisId())
521 && Objects.equal(device.annotations(), updatedDeviceDescription.annotations());
522 }
523
helenyrwufd296b62016-06-22 17:43:02 -0700524 private void checkAndUpdateDevices() {
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200525 Set<DeviceId> deviceSubjects =
526 cfgService.getSubjects(DeviceId.class, NetconfDeviceConfig.class);
527 deviceSubjects.forEach(deviceId -> {
528 NetconfDeviceConfig config =
529 cfgService.getConfig(deviceId, NetconfDeviceConfig.class);
530 DeviceDescription deviceDescription = createDeviceRepresentation(deviceId, config);
531 storeDeviceKey(config.sshKey(), config.username(), config.password(), deviceId);
Andrea Campanella105736e2017-11-23 12:52:43 +0100532 checkAndUpdateDevice(deviceId, deviceDescription, false);
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200533 });
andreaeb70a942015-10-16 21:34:46 -0700534 }
Sanjay Se8dcfee2015-04-23 10:07:08 +0530535
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200536 private DeviceDescription createDeviceRepresentation(DeviceId deviceId, NetconfDeviceConfig config) {
537 Preconditions.checkNotNull(deviceId, ISNULL);
538 //Netconf configuration object
539 ChassisId cid = new ChassisId();
540 String ipAddress = config.ip().toString();
David K. Bainbridge56e90232018-12-18 23:25:08 -0800541 DefaultAnnotations.Builder annotations = DefaultAnnotations.builder()
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200542 .set(IPADDRESS, ipAddress)
543 .set(PORT, String.valueOf(config.port()))
544 .set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase())
David K. Bainbridge56e90232018-12-18 23:25:08 -0800545 .set(AnnotationKeys.PROVIDER_MARK_ONLINE, String.valueOf(true));
546 if (config.path().isPresent()) {
547 annotations.set(PATH, config.path().get());
548 }
549
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200550 return new DefaultDeviceDescription(
551 deviceId.uri(),
552 Device.Type.SWITCH,
553 UNKNOWN, UNKNOWN,
554 UNKNOWN, UNKNOWN,
555 cid, false,
David K. Bainbridge56e90232018-12-18 23:25:08 -0800556 annotations.build());
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200557 }
558
559 private void storeDeviceKey(String sshKey, String username, String password, DeviceId deviceId) {
560 if (sshKey.equals("")) {
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -0600561 deviceKeyAdminService.addKey(
562 DeviceKey.createDeviceKeyUsingUsernamePassword(
563 DeviceKeyId.deviceKeyId(deviceId.toString()),
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200564 null, username, password));
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -0600565 } else {
566 deviceKeyAdminService.addKey(
567 DeviceKey.createDeviceKeyUsingSshKey(
568 DeviceKeyId.deviceKeyId(deviceId.toString()),
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200569 null, username, password,
570 sshKey));
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -0600571 }
572 }
573
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700574 private void initiateConnection(DeviceId deviceId, MastershipRole newRole) {
575 try {
576 if (isReachable(deviceId)) {
Andrea Campanella42e7b862018-09-21 11:56:48 +0200577 NetconfDevice device = controller.connectDevice(deviceId);
578 if (device != null) {
579 providerService.receivedRoleReply(deviceId, newRole, MastershipRole.MASTER);
580 } else {
581 providerService.receivedRoleReply(deviceId, newRole, MastershipRole.NONE);
582 }
583
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700584 }
585 } catch (Exception e) {
586 if (deviceService.getDevice(deviceId) != null) {
587 providerService.deviceDisconnected(deviceId);
588 }
589 deviceKeyAdminService.removeKey(DeviceKeyId.deviceKeyId(deviceId.toString()));
Ray Milkey986a47a2018-01-25 11:38:51 -0800590 throw new IllegalStateException(new NetconfException(
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200591 "Can't connect to NETCONF device " + deviceId, e));
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700592
593 }
594 }
595
596 private void discoverPorts(DeviceId deviceId) {
597 Device device = deviceService.getDevice(deviceId);
Andrea Campanella6c71a052016-04-22 11:56:31 -0700598 //TODO remove when PortDiscovery is removed from master
Ray Milkey640fedd2018-02-08 09:02:26 -0800599 if (device.is(DeviceDescriptionDiscovery.class)) {
Andrea Campanella6c71a052016-04-22 11:56:31 -0700600 DeviceDescriptionDiscovery deviceDescriptionDiscovery =
601 device.as(DeviceDescriptionDiscovery.class);
602 providerService.updatePorts(deviceId,
603 deviceDescriptionDiscovery.discoverPortDetails());
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700604 } else {
605 log.warn("No portGetter behaviour for device {}", deviceId);
606 }
Gaurav Agrawaldab4d772017-03-29 15:15:13 +0530607
608 // Port statistics discovery
Vidyashree Ramad89a1532017-03-30 15:13:52 +0530609 updatePortStatistics(device);
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700610 }
611
612 /**
613 * Return the DeviceId about the device containing the URI.
614 *
Andrea Campanella6c71a052016-04-22 11:56:31 -0700615 * @param ip IP address
Ray Milkeyd4334db2016-04-05 17:39:44 -0700616 * @param port port number
David K. Bainbridge56e90232018-12-18 23:25:08 -0800617 * @param path path aspect
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700618 * @return DeviceId
619 */
David K. Bainbridge56e90232018-12-18 23:25:08 -0800620 public DeviceId getDeviceId(String ip, int port, Optional<String> path) {
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700621 try {
David K. Bainbridge56e90232018-12-18 23:25:08 -0800622 return DeviceId.deviceId(new URI(NETCONF, ip + ":" + port +
623 (path.isPresent() ? "/" + path : ""), null));
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700624 } catch (URISyntaxException e) {
625 throw new IllegalArgumentException("Unable to build deviceID for device "
David K. Bainbridge56e90232018-12-18 23:25:08 -0800626 + ip + ":" + port + (path.isPresent() ? "/" + path : ""), e);
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700627 }
628 }
629
Andrea Campanella42e7b862018-09-21 11:56:48 +0200630 private <U> U withDeviceLock(Supplier<U> task, DeviceId deviceId) {
631 final Lock lock = deviceLocks.get(deviceId);
632 lock.lock();
633 try {
634 return task.get();
635 } finally {
636 lock.unlock();
637 }
638 }
639
640 private Runnable withDeviceLock(Runnable task, DeviceId deviceId) {
641 // Wrapper of withDeviceLock(Supplier, ...) for void tasks.
642 return () -> withDeviceLock(() -> {
643 task.run();
644 return null;
645 }, deviceId);
646 }
647
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700648 /**
649 * Listener for configuration events.
650 */
andreaeb70a942015-10-16 21:34:46 -0700651 private class InternalNetworkConfigListener implements NetworkConfigListener {
Sanjay Se8dcfee2015-04-23 10:07:08 +0530652
andreaeb70a942015-10-16 21:34:46 -0700653 @Override
654 public void event(NetworkConfigEvent event) {
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200655 if (event.configClass().equals(NetconfDeviceConfig.class)) {
Yuta HIGUCHIb6e0e912017-05-18 20:13:52 -0700656 executor.execute(() -> connectDevice((NetconfDeviceConfig) event.config().get()));
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200657 } else {
658 log.warn("Injecting device via this Json is deprecated, " +
659 "please put configuration under devices/ as shown in the wiki");
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200660 }
661
Sanjay Se8dcfee2015-04-23 10:07:08 +0530662 }
663
andreaeb70a942015-10-16 21:34:46 -0700664 @Override
665 public boolean isRelevant(NetworkConfigEvent event) {
Ray Milkey02710432018-02-13 17:08:28 -0800666 return (event.configClass().equals(NetconfDeviceConfig.class)) &&
andreaeb70a942015-10-16 21:34:46 -0700667 (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
668 event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED);
Sanjay Se8dcfee2015-04-23 10:07:08 +0530669 }
670 }
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700671
672 /**
673 * Listener for core device events.
674 */
675 private class InternalDeviceListener implements DeviceListener {
676 @Override
677 public void event(DeviceEvent event) {
Andrea Campanella36f1df92018-10-01 14:54:01 +0200678 Device device = event.subject();
679 DeviceId deviceId = device.id();
Andrea Campanella42e7b862018-09-21 11:56:48 +0200680 if (event.type() == DeviceEvent.Type.DEVICE_ADDED && !deviceService.isAvailable(event.subject().id())) {
681 try {
Andrea Campanella36f1df92018-10-01 14:54:01 +0200682 DeviceDescription description = new DefaultDeviceDescription(deviceId.uri(), device.type(),
683 device.manufacturer(), device.hwVersion(), device.swVersion(),
684 device.serialNumber(), device.chassisId(),
685 (SparseAnnotations) device.annotations());
686 checkAndUpdateDevice(deviceId, description, true);
Andrea Campanella42e7b862018-09-21 11:56:48 +0200687 } catch (Exception e) {
688 log.error("Unhandled exception checking {}", deviceId, e);
689 }
690 }
691 if (deviceService.isAvailable(event.subject().id())) {
692 executor.execute(() -> discoverPorts(event.subject().id()));
693 }
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700694 }
695
696 @Override
697 public boolean isRelevant(DeviceEvent event) {
Andrea Campanella42e7b862018-09-21 11:56:48 +0200698 if (event.type() != DeviceEvent.Type.DEVICE_ADDED &&
699 event.type() != DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED) {
Thomas Vachuska5b38dc02018-05-10 15:24:40 -0700700 return false;
701 }
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700702 if (mastershipService.getMasterFor(event.subject().id()) == null) {
703 return true;
704 }
Andrea Campanella968f93f2017-06-08 11:09:28 +0200705 return (SCHEME_NAME.equalsIgnoreCase(event.subject().annotations().value(AnnotationKeys.PROTOCOL)) ||
706 (SCHEME_NAME.equalsIgnoreCase(event.subject().id().uri().getScheme()))) &&
Michele Santuari576f09c2016-09-28 14:20:00 +0200707 mastershipService.isLocalMaster(event.subject().id());
Andrea Campanella7e6200a2016-03-21 09:48:40 -0700708 }
709 }
Sanjay Se8dcfee2015-04-23 10:07:08 +0530710}