blob: 4ee9a00e0065875fc37771838b6226b0df4a73f7 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.device.impl;
tomd3097b02014-08-26 10:40:29 -070017
Yafit Hadara9a73de2015-09-06 13:52:52 +030018import static com.google.common.base.Preconditions.checkNotNull;
19import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
20import static org.onlab.util.Tools.groupedThreads;
Thomas Vachuskafa8aa2f2015-10-13 11:56:59 -070021import static org.onlab.util.Tools.nullIsNotFound;
Yafit Hadara9a73de2015-09-06 13:52:52 +030022import static org.onosproject.net.MastershipRole.MASTER;
23import static org.onosproject.net.MastershipRole.NONE;
24import static org.onosproject.net.MastershipRole.STANDBY;
25import static org.onosproject.security.AppGuard.checkPermission;
26import static org.onosproject.security.AppPermission.Type.DEVICE_READ;
27import static org.slf4j.LoggerFactory.getLogger;
28
29import java.util.Collection;
30import java.util.HashSet;
31import java.util.List;
32import java.util.Objects;
33import java.util.Set;
34import java.util.concurrent.CompletableFuture;
35import java.util.concurrent.ExecutionException;
36import java.util.concurrent.ScheduledExecutorService;
37import java.util.concurrent.TimeUnit;
38import java.util.stream.Collectors;
Madan Jampani565a66a2015-07-25 17:01:13 -070039
tomd3097b02014-08-26 10:40:29 -070040import org.apache.felix.scr.annotations.Activate;
41import org.apache.felix.scr.annotations.Component;
42import org.apache.felix.scr.annotations.Deactivate;
tom5f38b3a2014-08-27 23:50:54 -070043import org.apache.felix.scr.annotations.Reference;
44import org.apache.felix.scr.annotations.ReferenceCardinality;
tomd3097b02014-08-26 10:40:29 -070045import org.apache.felix.scr.annotations.Service;
Brian O'Connorabafb502014-12-02 22:26:20 -080046import org.onosproject.cluster.ClusterService;
47import org.onosproject.cluster.NodeId;
Brian O'Connorabafb502014-12-02 22:26:20 -080048import org.onosproject.mastership.MastershipEvent;
49import org.onosproject.mastership.MastershipListener;
50import org.onosproject.mastership.MastershipService;
51import org.onosproject.mastership.MastershipTerm;
52import org.onosproject.mastership.MastershipTermService;
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -070053import org.onosproject.net.ConnectPoint;
Brian O'Connorabafb502014-12-02 22:26:20 -080054import org.onosproject.net.Device;
samuel738dfaf2015-07-11 11:08:57 +080055import org.onosproject.net.Device.Type;
Brian O'Connorabafb502014-12-02 22:26:20 -080056import org.onosproject.net.DeviceId;
57import org.onosproject.net.MastershipRole;
58import org.onosproject.net.Port;
59import org.onosproject.net.PortNumber;
Yafit Hadara9a73de2015-09-06 13:52:52 +030060import org.onosproject.net.config.NetworkConfigEvent;
61import org.onosproject.net.config.NetworkConfigListener;
62import org.onosproject.net.config.NetworkConfigService;
63import org.onosproject.net.config.basics.BasicDeviceConfig;
64import org.onosproject.net.config.basics.OpticalPortConfig;
Brian O'Connorabafb502014-12-02 22:26:20 -080065import org.onosproject.net.device.DefaultDeviceDescription;
66import org.onosproject.net.device.DefaultPortDescription;
67import org.onosproject.net.device.DeviceAdminService;
Brian O'Connorabafb502014-12-02 22:26:20 -080068import org.onosproject.net.device.DeviceDescription;
69import org.onosproject.net.device.DeviceEvent;
70import org.onosproject.net.device.DeviceListener;
71import org.onosproject.net.device.DeviceProvider;
72import org.onosproject.net.device.DeviceProviderRegistry;
73import org.onosproject.net.device.DeviceProviderService;
74import org.onosproject.net.device.DeviceService;
75import org.onosproject.net.device.DeviceStore;
76import org.onosproject.net.device.DeviceStoreDelegate;
77import org.onosproject.net.device.PortDescription;
sangho538108b2015-04-08 14:29:20 -070078import org.onosproject.net.device.PortStatistics;
Yafit Hadara9a73de2015-09-06 13:52:52 +030079import org.onosproject.net.provider.AbstractListenerProviderRegistry;
Brian O'Connorabafb502014-12-02 22:26:20 -080080import org.onosproject.net.provider.AbstractProviderService;
tomd3097b02014-08-26 10:40:29 -070081import org.slf4j.Logger;
tomd3097b02014-08-26 10:40:29 -070082
Yafit Hadara9a73de2015-09-06 13:52:52 +030083import com.google.common.util.concurrent.Futures;
Jonathan Hart2f669362015-02-11 16:19:20 -080084
tomd3097b02014-08-26 10:40:29 -070085/**
tome4729872014-09-23 00:37:37 -070086 * Provides implementation of the device SB & NB APIs.
tomd3097b02014-08-26 10:40:29 -070087 */
88@Component(immediate = true)
89@Service
tom41a2c5f2014-09-19 09:20:35 -070090public class DeviceManager
Thomas Vachuska42e8cce2015-07-29 19:25:18 -070091 extends AbstractListenerProviderRegistry<DeviceEvent, DeviceListener, DeviceProvider, DeviceProviderService>
Thomas Vachuskad16ce182014-10-29 17:25:29 -070092 implements DeviceService, DeviceAdminService, DeviceProviderRegistry {
tom32f66842014-08-27 19:27:47 -070093
tome5ec3fd2014-09-04 15:18:06 -070094 private static final String DEVICE_ID_NULL = "Device ID cannot be null";
95 private static final String PORT_NUMBER_NULL = "Port number cannot be null";
96 private static final String DEVICE_DESCRIPTION_NULL = "Device description cannot be null";
97 private static final String PORT_DESCRIPTION_NULL = "Port description cannot be null";
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -070098 private static final String PORT_DESC_LIST_NULL = "Port description list cannot be null";
tomd3097b02014-08-26 10:40:29 -070099
tom5f38b3a2014-08-27 23:50:54 -0700100 private final Logger log = getLogger(getClass());
tomd3097b02014-08-26 10:40:29 -0700101
alshabib339a3d92014-09-26 17:54:32 -0700102 private final DeviceStoreDelegate delegate = new InternalStoreDelegate();
tomf80c9722014-09-24 14:49:18 -0700103
tomc78acee2014-09-24 15:16:55 -0700104 private final MastershipListener mastershipListener = new InternalMastershipListener();
Madan Jampanide003d92015-05-11 17:14:20 -0700105 private NodeId localNodeId;
tomb41d1ac2014-09-24 01:51:24 -0700106
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800107 private ScheduledExecutorService backgroundService;
108
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700109 private final NetworkConfigListener networkConfigListener = new InternalNetworkConfigListener();
110
tom41a2c5f2014-09-19 09:20:35 -0700111 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
112 protected DeviceStore store;
tomd3097b02014-08-26 10:40:29 -0700113
tom5f38b3a2014-08-27 23:50:54 -0700114 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
tomb41d1ac2014-09-24 01:51:24 -0700115 protected ClusterService clusterService;
116
117 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Ayaka Koshibea7f044e2014-09-23 16:56:20 -0700118 protected MastershipService mastershipService;
119
Yuta HIGUCHIbcac4992014-11-22 19:27:57 -0800120 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Ayaka Koshibe3de43ca2014-09-26 16:40:23 -0700121 protected MastershipTermService termService;
122
Madan Jampani61056bc2014-09-27 09:07:26 -0700123 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700124 protected NetworkConfigService networkConfigService;
125
tomd3097b02014-08-26 10:40:29 -0700126 @Activate
127 public void activate() {
samuele1fa7322015-07-14 16:35:16 +0800128 backgroundService = newSingleThreadScheduledExecutor(groupedThreads("onos/device", "manager-background"));
Madan Jampanide003d92015-05-11 17:14:20 -0700129 localNodeId = clusterService.getLocalNode().id();
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800130
tomf80c9722014-09-24 14:49:18 -0700131 store.setDelegate(delegate);
tom96dfcab2014-08-28 09:26:03 -0700132 eventDispatcher.addSink(DeviceEvent.class, listenerRegistry);
tomb41d1ac2014-09-24 01:51:24 -0700133 mastershipService.addListener(mastershipListener);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700134 networkConfigService.addListener(networkConfigListener);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800135
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700136 backgroundService.scheduleWithFixedDelay(() -> {
137 try {
138 mastershipCheck();
139 } catch (Exception e) {
140 log.error("Exception thrown during integrity check", e);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800141 }
142 }, 1, 1, TimeUnit.MINUTES);
tomd3097b02014-08-26 10:40:29 -0700143 log.info("Started");
144 }
145
146 @Deactivate
147 public void deactivate() {
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800148 backgroundService.shutdown();
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700149 networkConfigService.removeListener(networkConfigListener);
tomf80c9722014-09-24 14:49:18 -0700150 store.unsetDelegate(delegate);
tomb41d1ac2014-09-24 01:51:24 -0700151 mastershipService.removeListener(mastershipListener);
tom5f38b3a2014-08-27 23:50:54 -0700152 eventDispatcher.removeSink(DeviceEvent.class);
tomd3097b02014-08-26 10:40:29 -0700153 log.info("Stopped");
154 }
155
156 @Override
tomad2d2092014-09-06 23:24:20 -0700157 public int getDeviceCount() {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900158 checkPermission(DEVICE_READ);
tomad2d2092014-09-06 23:24:20 -0700159 return store.getDeviceCount();
tomd3097b02014-08-26 10:40:29 -0700160 }
161
162 @Override
tom32f66842014-08-27 19:27:47 -0700163 public Iterable<Device> getDevices() {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900164 checkPermission(DEVICE_READ);
tome5ec3fd2014-09-04 15:18:06 -0700165 return store.getDevices();
tomd3097b02014-08-26 10:40:29 -0700166 }
167
tom32f66842014-08-27 19:27:47 -0700168 @Override
Yuta HIGUCHIf1f2ac02014-11-26 14:02:22 -0800169 public Iterable<Device> getAvailableDevices() {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900170 checkPermission(DEVICE_READ);
Yuta HIGUCHIf1f2ac02014-11-26 14:02:22 -0800171 return store.getAvailableDevices();
172 }
173
174 @Override
tom32f66842014-08-27 19:27:47 -0700175 public Device getDevice(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900176 checkPermission(DEVICE_READ);
tom32f66842014-08-27 19:27:47 -0700177 checkNotNull(deviceId, DEVICE_ID_NULL);
tom132b58a2014-08-28 16:11:28 -0700178 return store.getDevice(deviceId);
tom32f66842014-08-27 19:27:47 -0700179 }
180
181 @Override
tomad2d2092014-09-06 23:24:20 -0700182 public MastershipRole getRole(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900183 checkPermission(DEVICE_READ);
tomad2d2092014-09-06 23:24:20 -0700184 checkNotNull(deviceId, DEVICE_ID_NULL);
tomb41d1ac2014-09-24 01:51:24 -0700185 return mastershipService.getLocalRole(deviceId);
tomad2d2092014-09-06 23:24:20 -0700186 }
187
188 @Override
tom32f66842014-08-27 19:27:47 -0700189 public List<Port> getPorts(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900190 checkPermission(DEVICE_READ);
tom32f66842014-08-27 19:27:47 -0700191 checkNotNull(deviceId, DEVICE_ID_NULL);
tom132b58a2014-08-28 16:11:28 -0700192 return store.getPorts(deviceId);
tom32f66842014-08-27 19:27:47 -0700193 }
194
195 @Override
sangho538108b2015-04-08 14:29:20 -0700196 public List<PortStatistics> getPortStatistics(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900197 checkPermission(DEVICE_READ);
sangho538108b2015-04-08 14:29:20 -0700198 checkNotNull(deviceId, DEVICE_ID_NULL);
199 return store.getPortStatistics(deviceId);
200 }
201
202 @Override
Dusan Pajin11ff4a82015-08-20 18:03:05 +0200203 public List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900204 checkPermission(DEVICE_READ);
Dusan Pajin11ff4a82015-08-20 18:03:05 +0200205 checkNotNull(deviceId, DEVICE_ID_NULL);
206 return store.getPortDeltaStatistics(deviceId);
207 }
208
209 @Override
tom32f66842014-08-27 19:27:47 -0700210 public Port getPort(DeviceId deviceId, PortNumber portNumber) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900211 checkPermission(DEVICE_READ);
tom32f66842014-08-27 19:27:47 -0700212 checkNotNull(deviceId, DEVICE_ID_NULL);
213 checkNotNull(portNumber, PORT_NUMBER_NULL);
tom132b58a2014-08-28 16:11:28 -0700214 return store.getPort(deviceId, portNumber);
tom32f66842014-08-27 19:27:47 -0700215 }
216
217 @Override
tomff7eb7c2014-09-08 12:49:03 -0700218 public boolean isAvailable(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900219 checkPermission(DEVICE_READ);
Changhoon Yoon541ef712015-05-23 17:18:34 +0900220
tomff7eb7c2014-09-08 12:49:03 -0700221 checkNotNull(deviceId, DEVICE_ID_NULL);
222 return store.isAvailable(deviceId);
223 }
224
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700225 // Check a device for control channel connectivity.
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700226 private boolean isReachable(DeviceId deviceId) {
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800227 if (deviceId == null) {
228 return false;
229 }
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700230 DeviceProvider provider = getProvider(deviceId);
231 if (provider != null) {
232 return provider.isReachable(deviceId);
233 } else {
Yuta HIGUCHI72669c42014-11-13 14:48:17 -0800234 log.debug("Provider not found for {}", deviceId);
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700235 return false;
236 }
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700237 }
238
tome5ec3fd2014-09-04 15:18:06 -0700239 @Override
240 public void removeDevice(DeviceId deviceId) {
241 checkNotNull(deviceId, DEVICE_ID_NULL);
242 DeviceEvent event = store.removeDevice(deviceId);
tom0efbb1d2014-09-09 11:54:28 -0700243 if (event != null) {
244 log.info("Device {} administratively removed", deviceId);
245 post(event);
246 }
tome5ec3fd2014-09-04 15:18:06 -0700247 }
248
tom7869ad92014-09-09 14:32:08 -0700249 @Override
samuele1fa7322015-07-14 16:35:16 +0800250 protected DeviceProviderService createProviderService(
251 DeviceProvider provider) {
tom7869ad92014-09-09 14:32:08 -0700252 return new InternalDeviceProviderService(provider);
253 }
254
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800255 /**
256 * Checks if all the reachable devices have a valid mastership role.
257 */
258 private void mastershipCheck() {
259 log.debug("Checking mastership");
260 for (Device device : getDevices()) {
261 final DeviceId deviceId = device.id();
Jonathan Hart2f669362015-02-11 16:19:20 -0800262 log.trace("Checking device {}", deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800263
264 if (!isReachable(deviceId)) {
265 continue;
266 }
267
268 if (mastershipService.getLocalRole(deviceId) != NONE) {
269 continue;
270 }
271
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700272 log.info("{} is reachable but did not have a valid role, reasserting", deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800273
274 // isReachable but was not MASTER or STANDBY, get a role and apply
275 // Note: NONE triggers request to MastershipService
276 reassertRole(deviceId, NONE);
277 }
278 }
279
tomd3097b02014-08-26 10:40:29 -0700280 // Personalized device provider service issued to the supplied provider.
tomdc361b62014-09-09 20:36:52 -0700281 private class InternalDeviceProviderService
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700282 extends AbstractProviderService<DeviceProvider>
283 implements DeviceProviderService {
tomd3097b02014-08-26 10:40:29 -0700284
tomcfde0622014-09-09 11:02:42 -0700285 InternalDeviceProviderService(DeviceProvider provider) {
tomd3097b02014-08-26 10:40:29 -0700286 super(provider);
287 }
288
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700289 /**
290 * Apply role in reaction to provider event.
291 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700292 * @param deviceId device identifier
293 * @param newRole new role to apply to the device
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700294 * @return true if the request was sent to provider
295 */
296 private boolean applyRole(DeviceId deviceId, MastershipRole newRole) {
297
298 if (newRole.equals(MastershipRole.NONE)) {
samuele1fa7322015-07-14 16:35:16 +0800299 //no-op
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700300 return true;
301 }
302
303 DeviceProvider provider = provider();
304 if (provider == null) {
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700305 log.warn("Provider for {} was not found. Cannot apply role {}",
306 deviceId, newRole);
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700307 return false;
308 }
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700309 provider.roleChanged(deviceId, newRole);
310 // not triggering probe when triggered by provider service event
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700311
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700312 return true;
313 }
314
tomd3097b02014-08-26 10:40:29 -0700315 @Override
alshabibb7b40632014-09-28 21:30:00 -0700316 public void deviceConnected(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700317 DeviceDescription deviceDescription) {
tom32f66842014-08-27 19:27:47 -0700318 checkNotNull(deviceId, DEVICE_ID_NULL);
319 checkNotNull(deviceDescription, DEVICE_DESCRIPTION_NULL);
tomeadbb462014-09-07 16:10:19 -0700320 checkValidity();
Yuta HIGUCHI24b2e2a2014-10-07 15:53:57 -0700321
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700322 BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class);
323 if (!isAllowed(cfg)) {
324 log.warn("Device {} is not allowed", deviceId);
325 return;
326 }
327 // Generate updated description and establish my Role
328 deviceDescription = BasicDeviceOperator.combine(cfg, deviceDescription);
Madan Jampani565a66a2015-07-25 17:01:13 -0700329 Futures.getUnchecked(mastershipService.requestRoleFor(deviceId)
330 .thenAccept(role -> {
331 log.info("Local role is {} for {}", role, deviceId);
332 applyRole(deviceId, role);
333 }));
HIGUCHI Yuta11530fb2015-05-27 13:10:20 -0700334
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700335 DeviceEvent event = store.createOrUpdateDevice(provider().id(), deviceId,
336 deviceDescription);
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700337 log.info("Device {} connected", deviceId);
tom80c0e5e2014-09-08 18:08:58 -0700338 if (event != null) {
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700339 log.trace("event: {} {}", event.type(), event);
tom568581d2014-09-08 20:13:36 -0700340 post(event);
tom80c0e5e2014-09-08 18:08:58 -0700341 }
tomd3097b02014-08-26 10:40:29 -0700342 }
343
344 @Override
345 public void deviceDisconnected(DeviceId deviceId) {
tom32f66842014-08-27 19:27:47 -0700346 checkNotNull(deviceId, DEVICE_ID_NULL);
tomeadbb462014-09-07 16:10:19 -0700347 checkValidity();
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700348
Yuta HIGUCHI2d3cd312014-10-31 11:38:04 -0700349 log.info("Device {} disconnected from this node", deviceId);
Ayaka Koshibed9f693e2014-09-29 18:04:54 -0700350
alshabibafc514a2014-12-01 14:44:05 -0800351 List<Port> ports = store.getPorts(deviceId);
Yafit Hadara9a73de2015-09-06 13:52:52 +0300352 final Device device = getDevice(deviceId);
353
354 List<PortDescription> descs = ports.stream().map(
355 port -> (!(Device.Type.ROADM.equals(device.type()))) ?
356 new DefaultPortDescription(port.number(), false,
357 port.type(), port.portSpeed()) :
358 OpticalPortOperator.descriptionOf(port, false)
359 ).collect(Collectors.toList());
360
alshabibafc514a2014-12-01 14:44:05 -0800361 store.updatePorts(this.provider().id(), deviceId, descs);
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700362 try {
Madan Jampani565a66a2015-07-25 17:01:13 -0700363 if (mastershipService.isLocalMaster(deviceId)) {
Thomas Vachuska5f429d62015-05-28 15:34:36 -0700364 post(store.markOffline(deviceId));
365 }
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700366 } catch (IllegalStateException e) {
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700367 log.warn("Failed to mark {} offline", deviceId);
368 // only the MASTER should be marking off-line in normal cases,
samuele1fa7322015-07-14 16:35:16 +0800369 // but if I was the last STANDBY connection, etc. and no one else
370 // was there to mark the device offline, this instance may need to
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700371 // temporarily request for Master Role and mark offline.
372
samuele1fa7322015-07-14 16:35:16 +0800373 //there are times when this node will correctly have mastership, BUT
374 //that isn't reflected in the ClockManager before the device disconnects.
375 //we want to let go of the device anyways, so make sure this happens.
Yuta HIGUCHI0722fb22014-10-19 01:16:33 -0700376
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700377 // FIXME: Store semantics leaking out as IllegalStateException.
samuele1fa7322015-07-14 16:35:16 +0800378 // Consider revising store API to handle this scenario.
379 CompletableFuture<MastershipRole> roleFuture = mastershipService.requestRoleFor(deviceId);
Madan Jampanide003d92015-05-11 17:14:20 -0700380 roleFuture.whenComplete((role, error) -> {
samuele1fa7322015-07-14 16:35:16 +0800381 MastershipTerm term = termService.getMastershipTerm(deviceId);
382 // TODO: Move this type of check inside device clock manager, etc.
383 if (term != null && localNodeId.equals(term.master())) {
384 log.info("Retry marking {} offline", deviceId);
samuele1fa7322015-07-14 16:35:16 +0800385 post(store.markOffline(deviceId));
386 } else {
387 log.info("Failed again marking {} offline. {}", deviceId, role);
388 }
389 });
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700390 } finally {
Madan Jampanic6e574f2015-05-29 13:41:52 -0700391 try {
samuele1fa7322015-07-14 16:35:16 +0800392 //relinquish master role and ability to be backup.
Madan Jampanic6e574f2015-05-29 13:41:52 -0700393 mastershipService.relinquishMastership(deviceId).get();
394 } catch (InterruptedException e) {
samuele1fa7322015-07-14 16:35:16 +0800395 log.warn("Interrupted while reliquishing role for {}", deviceId);
Madan Jampanic6e574f2015-05-29 13:41:52 -0700396 Thread.currentThread().interrupt();
397 } catch (ExecutionException e) {
samuele1fa7322015-07-14 16:35:16 +0800398 log.error("Exception thrown while relinquishing role for {}", deviceId, e);
Madan Jampanic6e574f2015-05-29 13:41:52 -0700399 }
tom0efbb1d2014-09-09 11:54:28 -0700400 }
tomd3097b02014-08-26 10:40:29 -0700401 }
402
403 @Override
alshabibb7b40632014-09-28 21:30:00 -0700404 public void updatePorts(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700405 List<PortDescription> portDescriptions) {
tom32f66842014-08-27 19:27:47 -0700406 checkNotNull(deviceId, DEVICE_ID_NULL);
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700407 checkNotNull(portDescriptions, PORT_DESC_LIST_NULL);
tomeadbb462014-09-07 16:10:19 -0700408 checkValidity();
Madan Jampani565a66a2015-07-25 17:01:13 -0700409 if (!mastershipService.isLocalMaster(deviceId)) {
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700410 // Never been a master for this device
411 // any update will be ignored.
samuele1fa7322015-07-14 16:35:16 +0800412 log.trace("Ignoring {} port updates on standby node. {}", deviceId, portDescriptions);
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700413 return;
414 }
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700415 portDescriptions = portDescriptions.stream()
416 .map(e -> consolidate(deviceId, e))
417 .collect(Collectors.toList());
Yuta HIGUCHI5f6739c2014-10-01 14:04:01 -0700418 List<DeviceEvent> events = store.updatePorts(this.provider().id(),
samuele1fa7322015-07-14 16:35:16 +0800419 deviceId, portDescriptions);
tom32f66842014-08-27 19:27:47 -0700420 for (DeviceEvent event : events) {
421 post(event);
422 }
tomd3097b02014-08-26 10:40:29 -0700423 }
424
425 @Override
alshabibb7b40632014-09-28 21:30:00 -0700426 public void portStatusChanged(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700427 PortDescription portDescription) {
tom32f66842014-08-27 19:27:47 -0700428 checkNotNull(deviceId, DEVICE_ID_NULL);
429 checkNotNull(portDescription, PORT_DESCRIPTION_NULL);
tomeadbb462014-09-07 16:10:19 -0700430 checkValidity();
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700431
Madan Jampani565a66a2015-07-25 17:01:13 -0700432 if (!mastershipService.isLocalMaster(deviceId)) {
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700433 // Never been a master for this device
434 // any update will be ignored.
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700435 log.trace("Ignoring {} port update on standby node. {}", deviceId,
436 portDescription);
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700437 return;
438 }
Thomas Vachuskafa8aa2f2015-10-13 11:56:59 -0700439 Device device = nullIsNotFound(getDevice(deviceId), "Device not found");
Yafit Hadara9a73de2015-09-06 13:52:52 +0300440 if ((Device.Type.ROADM.equals(device.type()))) {
441 Port port = getPort(deviceId, portDescription.portNumber());
442 portDescription = OpticalPortOperator.descriptionOf(port, portDescription.isEnabled());
443 }
444
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700445 portDescription = consolidate(deviceId, portDescription);
samuele1fa7322015-07-14 16:35:16 +0800446 final DeviceEvent event = store.updatePortStatus(this.provider().id(),
447 deviceId, portDescription);
tomff7eb7c2014-09-08 12:49:03 -0700448 if (event != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700449 log.info("Device {} port {} status changed", deviceId, event.port().number());
tom0efbb1d2014-09-09 11:54:28 -0700450 post(event);
tomff7eb7c2014-09-08 12:49:03 -0700451 }
tomd3097b02014-08-26 10:40:29 -0700452 }
tom3f2bbd72014-09-24 12:07:58 -0700453
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700454 // merges the appropriate PortConfig with the description.
455 private PortDescription consolidate(DeviceId did, PortDescription desc) {
456 switch (desc.type()) {
457 case COPPER:
458 case VIRTUAL:
459 return desc;
460 default:
461 OpticalPortConfig opc = networkConfigService.getConfig(
462 new ConnectPoint(did, desc.portNumber()), OpticalPortConfig.class);
463 return OpticalPortOperator.combine(opc, desc);
464 }
465 }
466
tom3f2bbd72014-09-24 12:07:58 -0700467 @Override
samuele1fa7322015-07-14 16:35:16 +0800468 public void receivedRoleReply(DeviceId deviceId, MastershipRole requested,
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700469 MastershipRole response) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700470 // Several things can happen here:
471 // 1. request and response match
472 // 2. request and response don't match
473 // 3. MastershipRole and requested match (and 1 or 2 are true)
474 // 4. MastershipRole and requested don't match (and 1 or 2 are true)
475 //
476 // 2, 4, and 3 with case 2 are failure modes.
477
tom3f2bbd72014-09-24 12:07:58 -0700478 // FIXME: implement response to this notification
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700479
Madan Jampanif2af7712015-05-29 18:43:52 -0700480 log.debug("got reply to a role request for {}: asked for {}, and got {}",
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700481 deviceId, requested, response);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700482
483 if (requested == null && response == null) {
samuele1fa7322015-07-14 16:35:16 +0800484 // something was off with DeviceProvider, maybe check channel too?
485 log.warn("Failed to assert role [{}] onto Device {}", requested, deviceId);
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700486 mastershipService.relinquishMastership(deviceId);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700487 return;
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700488 }
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700489
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700490 if (Objects.equals(requested, response)) {
samuele1fa7322015-07-14 16:35:16 +0800491 if (Objects.equals(requested, mastershipService.getLocalRole(deviceId))) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700492 return;
493 } else {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800494 log.warn("Role mismatch on {}. set to {}, but store demands {}",
495 deviceId, response, mastershipService.getLocalRole(deviceId));
496 // roleManager got the device to comply, but doesn't agree with
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700497 // the store; use the store's view, then try to reassert.
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800498 backgroundService.submit(() -> reassertRole(deviceId, mastershipService.getLocalRole(deviceId)));
499 return;
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700500 }
501 } else {
502 // we didn't get back what we asked for. Reelect someone else.
samuele1fa7322015-07-14 16:35:16 +0800503 log.warn("Failed to assert role [{}] onto Device {}", response, deviceId);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700504 if (response == MastershipRole.MASTER) {
505 mastershipService.relinquishMastership(deviceId);
506 // TODO: Shouldn't we be triggering event?
samuele1fa7322015-07-14 16:35:16 +0800507 //final Device device = getDevice(deviceId);
508 //post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device));
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700509 }
510 }
tom3f2bbd72014-09-24 12:07:58 -0700511 }
sangho538108b2015-04-08 14:29:20 -0700512
513 @Override
samuele1fa7322015-07-14 16:35:16 +0800514 public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
sangho538108b2015-04-08 14:29:20 -0700515 checkNotNull(deviceId, DEVICE_ID_NULL);
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700516 checkNotNull(portStatistics, "Port statistics list cannot be null");
sangho538108b2015-04-08 14:29:20 -0700517 checkValidity();
518
samuele1fa7322015-07-14 16:35:16 +0800519 DeviceEvent event = store.updatePortStatistics(this.provider().id(),
520 deviceId, portStatistics);
sangho538108b2015-04-08 14:29:20 -0700521 post(event);
522 }
tomd3097b02014-08-26 10:40:29 -0700523 }
tom32f66842014-08-27 19:27:47 -0700524
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700525 // by default allowed, otherwise check flag
526 private boolean isAllowed(BasicDeviceConfig cfg) {
527 return (cfg == null || cfg.isAllowed());
528 }
529
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800530 // Applies the specified role to the device; ignores NONE
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700531
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800532 /**
533 * Apply role to device and send probe if MASTER.
534 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700535 * @param deviceId device identifier
536 * @param newRole new role to apply to the device
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800537 * @return true if the request was sent to provider
538 */
539 private boolean applyRoleAndProbe(DeviceId deviceId, MastershipRole newRole) {
540 if (newRole.equals(MastershipRole.NONE)) {
samuele1fa7322015-07-14 16:35:16 +0800541 //no-op
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700542 return true;
543 }
Ayaka Koshibe317245a2014-10-29 00:34:43 -0700544
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800545 DeviceProvider provider = getProvider(deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800546 if (provider == null) {
samuele1fa7322015-07-14 16:35:16 +0800547 log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800548 return false;
549 }
550 provider.roleChanged(deviceId, newRole);
551
552 if (newRole.equals(MastershipRole.MASTER)) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800553 log.debug("sent TriggerProbe({})", deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800554 // only trigger event when request was sent to provider
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800555 provider.triggerProbe(deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800556 }
557 return true;
558 }
559
560 /**
561 * Reaasert role for specified device connected to this node.
562 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700563 * @param did device identifier
564 * @param nextRole role to apply. If NONE is specified,
565 * it will ask mastership service for a role and apply it.
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800566 */
samuele1fa7322015-07-14 16:35:16 +0800567 private void reassertRole(final DeviceId did,
568 final MastershipRole nextRole) {
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800569
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800570 MastershipRole myNextRole = nextRole;
571 if (myNextRole == NONE) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800572 try {
573 mastershipService.requestRoleFor(did).get();
574 MastershipTerm term = termService.getMastershipTerm(did);
575 if (term != null && localNodeId.equals(term.master())) {
576 myNextRole = MASTER;
577 } else {
578 myNextRole = STANDBY;
579 }
580 } catch (InterruptedException e) {
581 Thread.currentThread().interrupt();
582 log.error("Interrupted waiting for Mastership", e);
583 } catch (ExecutionException e) {
584 log.error("Encountered an error waiting for Mastership", e);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800585 }
586 }
587
588 switch (myNextRole) {
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700589 case MASTER:
590 final Device device = getDevice(did);
591 if ((device != null) && !isAvailable(did)) {
592 //flag the device as online. Is there a better way to do this?
593 DefaultDeviceDescription deviceDescription
594 = new DefaultDeviceDescription(did.uri(),
595 device.type(),
596 device.manufacturer(),
597 device.hwVersion(),
598 device.swVersion(),
599 device.serialNumber(),
600 device.chassisId());
601 DeviceEvent devEvent =
602 store.createOrUpdateDevice(device.providerId(), did,
603 deviceDescription);
604 post(devEvent);
605 }
606 // TODO: should apply role only if there is mismatch
607 log.debug("Applying role {} to {}", myNextRole, did);
608 if (!applyRoleAndProbe(did, MASTER)) {
609 log.warn("Unsuccessful applying role {} to {}", myNextRole, did);
610 // immediately failed to apply role
611 mastershipService.relinquishMastership(did);
612 // FIXME disconnect?
613 }
614 break;
615 case STANDBY:
616 log.debug("Applying role {} to {}", myNextRole, did);
617 if (!applyRoleAndProbe(did, STANDBY)) {
618 log.warn("Unsuccessful applying role {} to {}", myNextRole, did);
619 // immediately failed to apply role
620 mastershipService.relinquishMastership(did);
621 // FIXME disconnect?
622 }
623 break;
624 case NONE:
625 default:
626 // should never reach here
627 log.error("You didn't see anything. I did not exist.");
628 break;
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800629 }
630 }
631
Madan Jampani328371d2015-05-29 14:06:27 -0700632 private void handleMastershipEvent(MastershipEvent event) {
633 if (event.type() != MastershipEvent.Type.MASTER_CHANGED) {
634 // Don't care if backup list changed.
635 return;
636 }
637
638 final DeviceId did = event.subject();
639
640 // myRole suggested by MastershipService
641 MastershipRole myNextRole;
642 if (localNodeId.equals(event.roleInfo().master())) {
643 // confirm latest info
644 MastershipTerm term = termService.getMastershipTerm(did);
samuele1fa7322015-07-14 16:35:16 +0800645 final boolean iHaveControl = term != null && localNodeId.equals(term.master());
Madan Jampani328371d2015-05-29 14:06:27 -0700646 if (iHaveControl) {
Madan Jampani328371d2015-05-29 14:06:27 -0700647 myNextRole = MASTER;
648 } else {
649 myNextRole = STANDBY;
650 }
651 } else if (event.roleInfo().backups().contains(localNodeId)) {
652 myNextRole = STANDBY;
653 } else {
654 myNextRole = NONE;
655 }
656
Madan Jampani328371d2015-05-29 14:06:27 -0700657 final boolean isReachable = isReachable(did);
658 if (!isReachable) {
659 // device is not connected to this node
660 if (myNextRole != NONE) {
661 log.warn("Node was instructed to be {} role for {}, "
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700662 + "but this node cannot reach the device. "
663 + "Relinquishing role. ",
samuele1fa7322015-07-14 16:35:16 +0800664 myNextRole, did);
Madan Jampani328371d2015-05-29 14:06:27 -0700665 mastershipService.relinquishMastership(did);
666 }
667 return;
668 }
669
670 // device is connected to this node:
671 if (store.getDevice(did) != null) {
672 reassertRole(did, myNextRole);
673 } else {
674 log.debug("Device is not yet/no longer in the store: {}", did);
675 }
676 }
677
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800678 // Intercepts mastership events
679 private class InternalMastershipListener implements MastershipListener {
680
tomb41d1ac2014-09-24 01:51:24 -0700681 @Override
682 public void event(MastershipEvent event) {
Madan Jampani328371d2015-05-29 14:06:27 -0700683 backgroundService.submit(() -> {
684 try {
685 handleMastershipEvent(event);
686 } catch (Exception e) {
687 log.warn("Failed to handle {}", event, e);
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700688 }
Madan Jampani328371d2015-05-29 14:06:27 -0700689 });
Ayaka Koshibe317245a2014-10-29 00:34:43 -0700690 }
tomb41d1ac2014-09-24 01:51:24 -0700691 }
tomf80c9722014-09-24 14:49:18 -0700692
693 // Store delegate to re-post events emitted from the store.
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700694 private class InternalStoreDelegate implements DeviceStoreDelegate {
tomf80c9722014-09-24 14:49:18 -0700695 @Override
696 public void notify(DeviceEvent event) {
697 post(event);
698 }
699 }
samuel738dfaf2015-07-11 11:08:57 +0800700
701 @Override
702 public Iterable<Device> getDevices(Type type) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900703 checkPermission(DEVICE_READ);
samuel738dfaf2015-07-11 11:08:57 +0800704 Set<Device> results = new HashSet<>();
705 Iterable<Device> devices = store.getDevices();
706 if (devices != null) {
707 devices.forEach(d -> {
708 if (type.equals(d.type())) {
709 results.add(d);
710 }
711 });
712 }
713 return results;
714 }
715
716 @Override
717 public Iterable<Device> getAvailableDevices(Type type) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900718 checkPermission(DEVICE_READ);
samuel738dfaf2015-07-11 11:08:57 +0800719 Set<Device> results = new HashSet<>();
720 Iterable<Device> availableDevices = store.getAvailableDevices();
721 if (availableDevices != null) {
722 availableDevices.forEach(d -> {
723 if (type.equals(d.type())) {
724 results.add(d);
725 }
726 });
727 }
728 return results;
729 }
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700730
731 private class InternalNetworkConfigListener implements NetworkConfigListener {
732 @Override
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700733 public boolean isRelevant(NetworkConfigEvent event) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700734 return (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
735 || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)
736 && (event.configClass().equals(BasicDeviceConfig.class)
737 || event.configClass().equals(OpticalPortConfig.class));
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700738 }
739
740 @Override
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700741 public void event(NetworkConfigEvent event) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700742 DeviceEvent de = null;
743 if (event.configClass().equals(BasicDeviceConfig.class)) {
744 log.info("Detected Device network config event {}", event.type());
745 DeviceId did = (DeviceId) event.subject();
746 BasicDeviceConfig cfg = networkConfigService.getConfig(did, BasicDeviceConfig.class);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700747
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700748 if (!isAllowed(cfg)) {
749 kickOutBadDevice(did);
750 } else {
751 Device dev = getDevice(did);
752 DeviceDescription desc = (dev == null) ? null : BasicDeviceOperator.descriptionOf(dev);
753 desc = BasicDeviceOperator.combine(cfg, desc);
Thomas Vachuska1627dc82015-11-13 12:22:14 -0800754 if (desc != null && getProvider(did) != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700755 de = store.createOrUpdateDevice(getProvider(did).id(), did, desc);
756 }
757 }
758 }
759 if (event.configClass().equals(OpticalPortConfig.class)) {
760 ConnectPoint cpt = (ConnectPoint) event.subject();
761 DeviceId did = cpt.deviceId();
762 Port dpt = getPort(did, cpt.port());
763
764 if (dpt != null) {
765 OpticalPortConfig opc = networkConfigService.getConfig(cpt, OpticalPortConfig.class);
766 PortDescription desc = OpticalPortOperator.descriptionOf(dpt);
767 desc = OpticalPortOperator.combine(opc, desc);
Thomas Vachuska1627dc82015-11-13 12:22:14 -0800768 if (desc != null && getProvider(did) != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700769 de = store.updatePortStatus(getProvider(did).id(), did, desc);
770 }
771 }
772 }
773
774 if (de != null) {
775 post(de);
776 }
777 }
778
779 // checks if the specified device is allowed by the BasicDeviceConfig
780 // and if not, removes it
781 private void kickOutBadDevice(DeviceId deviceId) {
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700782 Device badDevice = getDevice(deviceId);
783 if (badDevice != null) {
784 removeDevice(deviceId);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700785 }
786 }
787 }
tomd3097b02014-08-26 10:40:29 -0700788}