blob: 17ff85c48159e9d65458cdee6c737f973b73a91b [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
samuel738dfaf2015-07-11 11:08:57 +080018import static com.google.common.base.Preconditions.checkNotNull;
Sahil Lele3a0cdd52015-07-21 14:16:31 -070019import static com.google.common.base.Preconditions.checkState;
samuel738dfaf2015-07-11 11:08:57 +080020import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
21import static org.onlab.util.Tools.groupedThreads;
22import 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.slf4j.LoggerFactory.getLogger;
27
28import java.util.Collection;
29import java.util.HashSet;
30import java.util.List;
31import java.util.Objects;
32import java.util.Set;
33import java.util.concurrent.CompletableFuture;
34import java.util.concurrent.ExecutionException;
35import java.util.concurrent.ScheduledExecutorService;
36import java.util.concurrent.TimeUnit;
37
tomd3097b02014-08-26 10:40:29 -070038import org.apache.felix.scr.annotations.Activate;
39import org.apache.felix.scr.annotations.Component;
40import org.apache.felix.scr.annotations.Deactivate;
tom5f38b3a2014-08-27 23:50:54 -070041import org.apache.felix.scr.annotations.Reference;
42import org.apache.felix.scr.annotations.ReferenceCardinality;
tomd3097b02014-08-26 10:40:29 -070043import org.apache.felix.scr.annotations.Service;
Brian O'Connorabafb502014-12-02 22:26:20 -080044import org.onosproject.cluster.ClusterService;
45import org.onosproject.cluster.NodeId;
Changhoon Yoon541ef712015-05-23 17:18:34 +090046import org.onosproject.core.Permission;
Brian O'Connorabafb502014-12-02 22:26:20 -080047import org.onosproject.event.EventDeliveryService;
samuel738dfaf2015-07-11 11:08:57 +080048import org.onosproject.event.ListenerRegistry;
Sahil Lele3a0cdd52015-07-21 14:16:31 -070049import org.onosproject.incubator.net.config.NetworkConfigEvent;
50import org.onosproject.incubator.net.config.NetworkConfigListener;
51import org.onosproject.incubator.net.config.NetworkConfigService;
52import org.onosproject.incubator.net.config.basics.BasicDeviceConfig;
Brian O'Connorabafb502014-12-02 22:26:20 -080053import org.onosproject.mastership.MastershipEvent;
54import org.onosproject.mastership.MastershipListener;
55import org.onosproject.mastership.MastershipService;
56import org.onosproject.mastership.MastershipTerm;
57import org.onosproject.mastership.MastershipTermService;
Sahil Lele3a0cdd52015-07-21 14:16:31 -070058import org.onosproject.net.DefaultAnnotations;
Brian O'Connorabafb502014-12-02 22:26:20 -080059import org.onosproject.net.Device;
samuel738dfaf2015-07-11 11:08:57 +080060import org.onosproject.net.Device.Type;
Brian O'Connorabafb502014-12-02 22:26:20 -080061import org.onosproject.net.DeviceId;
62import org.onosproject.net.MastershipRole;
63import org.onosproject.net.Port;
64import org.onosproject.net.PortNumber;
Sahil Lele3a0cdd52015-07-21 14:16:31 -070065import org.onosproject.net.SparseAnnotations;
Brian O'Connorabafb502014-12-02 22:26:20 -080066import org.onosproject.net.device.DefaultDeviceDescription;
67import org.onosproject.net.device.DefaultPortDescription;
68import org.onosproject.net.device.DeviceAdminService;
69import org.onosproject.net.device.DeviceClockProviderService;
70import org.onosproject.net.device.DeviceDescription;
71import org.onosproject.net.device.DeviceEvent;
72import org.onosproject.net.device.DeviceListener;
73import org.onosproject.net.device.DeviceProvider;
74import org.onosproject.net.device.DeviceProviderRegistry;
75import org.onosproject.net.device.DeviceProviderService;
76import org.onosproject.net.device.DeviceService;
77import org.onosproject.net.device.DeviceStore;
78import org.onosproject.net.device.DeviceStoreDelegate;
79import org.onosproject.net.device.PortDescription;
sangho538108b2015-04-08 14:29:20 -070080import org.onosproject.net.device.PortStatistics;
Brian O'Connorabafb502014-12-02 22:26:20 -080081import org.onosproject.net.provider.AbstractProviderRegistry;
82import org.onosproject.net.provider.AbstractProviderService;
tomd3097b02014-08-26 10:40:29 -070083import org.slf4j.Logger;
tomd3097b02014-08-26 10:40:29 -070084
samuel738dfaf2015-07-11 11:08:57 +080085import com.google.common.collect.Lists;
Jonathan Hart2f669362015-02-11 16:19:20 -080086
samuele1fa7322015-07-14 16:35:16 +080087
tomd3097b02014-08-26 10:40:29 -070088/**
tome4729872014-09-23 00:37:37 -070089 * Provides implementation of the device SB & NB APIs.
tomd3097b02014-08-26 10:40:29 -070090 */
91@Component(immediate = true)
92@Service
tom41a2c5f2014-09-19 09:20:35 -070093public class DeviceManager
Thomas Vachuskad16ce182014-10-29 17:25:29 -070094 extends AbstractProviderRegistry<DeviceProvider, DeviceProviderService>
95 implements DeviceService, DeviceAdminService, DeviceProviderRegistry {
tom32f66842014-08-27 19:27:47 -070096
tome5ec3fd2014-09-04 15:18:06 -070097 private static final String DEVICE_ID_NULL = "Device ID cannot be null";
98 private static final String PORT_NUMBER_NULL = "Port number cannot be null";
99 private static final String DEVICE_DESCRIPTION_NULL = "Device description cannot be null";
100 private static final String PORT_DESCRIPTION_NULL = "Port description cannot be null";
tomd3097b02014-08-26 10:40:29 -0700101
tom5f38b3a2014-08-27 23:50:54 -0700102 private final Logger log = getLogger(getClass());
tomd3097b02014-08-26 10:40:29 -0700103
samuele1fa7322015-07-14 16:35:16 +0800104 protected final ListenerRegistry<DeviceEvent, DeviceListener> listenerRegistry =
105 new ListenerRegistry<>();
tom32f66842014-08-27 19:27:47 -0700106
alshabib339a3d92014-09-26 17:54:32 -0700107 private final DeviceStoreDelegate delegate = new InternalStoreDelegate();
tomf80c9722014-09-24 14:49:18 -0700108
tomc78acee2014-09-24 15:16:55 -0700109 private final MastershipListener mastershipListener = new InternalMastershipListener();
Madan Jampanide003d92015-05-11 17:14:20 -0700110 private NodeId localNodeId;
tomb41d1ac2014-09-24 01:51:24 -0700111
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800112 private ScheduledExecutorService backgroundService;
113
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700114 private final NetworkConfigListener networkConfigListener = new InternalNetworkConfigListener();
115
tom41a2c5f2014-09-19 09:20:35 -0700116 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
117 protected DeviceStore store;
tomd3097b02014-08-26 10:40:29 -0700118
tom5f38b3a2014-08-27 23:50:54 -0700119 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
tome5ec3fd2014-09-04 15:18:06 -0700120 protected EventDeliveryService eventDispatcher;
tom5f38b3a2014-08-27 23:50:54 -0700121
Ayaka Koshibea7f044e2014-09-23 16:56:20 -0700122 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
tomb41d1ac2014-09-24 01:51:24 -0700123 protected ClusterService clusterService;
124
125 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Ayaka Koshibea7f044e2014-09-23 16:56:20 -0700126 protected MastershipService mastershipService;
127
Yuta HIGUCHIbcac4992014-11-22 19:27:57 -0800128 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Ayaka Koshibe3de43ca2014-09-26 16:40:23 -0700129 protected MastershipTermService termService;
130
Madan Jampani61056bc2014-09-27 09:07:26 -0700131 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Yuta HIGUCHI093e83e2014-10-10 22:26:11 -0700132 protected DeviceClockProviderService deviceClockProviderService;
Madan Jampani61056bc2014-09-27 09:07:26 -0700133
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700134 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
135 protected NetworkConfigService networkConfigService;
136
137
138
tomd3097b02014-08-26 10:40:29 -0700139 @Activate
140 public void activate() {
samuele1fa7322015-07-14 16:35:16 +0800141 backgroundService = newSingleThreadScheduledExecutor(groupedThreads("onos/device", "manager-background"));
Madan Jampanide003d92015-05-11 17:14:20 -0700142 localNodeId = clusterService.getLocalNode().id();
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800143
tomf80c9722014-09-24 14:49:18 -0700144 store.setDelegate(delegate);
tom96dfcab2014-08-28 09:26:03 -0700145 eventDispatcher.addSink(DeviceEvent.class, listenerRegistry);
tomb41d1ac2014-09-24 01:51:24 -0700146 mastershipService.addListener(mastershipListener);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700147 networkConfigService.addListener(networkConfigListener);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800148
149 backgroundService.scheduleWithFixedDelay(new Runnable() {
150
151 @Override
152 public void run() {
153 try {
154 mastershipCheck();
155 } catch (Exception e) {
156 log.error("Exception thrown during integrity check", e);
157 }
158 }
159 }, 1, 1, TimeUnit.MINUTES);
tomd3097b02014-08-26 10:40:29 -0700160 log.info("Started");
161 }
162
163 @Deactivate
164 public void deactivate() {
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800165 backgroundService.shutdown();
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700166 networkConfigService.removeListener(networkConfigListener);
tomf80c9722014-09-24 14:49:18 -0700167 store.unsetDelegate(delegate);
tomb41d1ac2014-09-24 01:51:24 -0700168 mastershipService.removeListener(mastershipListener);
tom5f38b3a2014-08-27 23:50:54 -0700169 eventDispatcher.removeSink(DeviceEvent.class);
tomd3097b02014-08-26 10:40:29 -0700170 log.info("Stopped");
171 }
172
173 @Override
tomad2d2092014-09-06 23:24:20 -0700174 public int getDeviceCount() {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900175 checkPermission(Permission.DEVICE_READ);
176
tomad2d2092014-09-06 23:24:20 -0700177 return store.getDeviceCount();
tomd3097b02014-08-26 10:40:29 -0700178 }
179
180 @Override
tom32f66842014-08-27 19:27:47 -0700181 public Iterable<Device> getDevices() {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900182 checkPermission(Permission.DEVICE_READ);
183
tome5ec3fd2014-09-04 15:18:06 -0700184 return store.getDevices();
tomd3097b02014-08-26 10:40:29 -0700185 }
186
tom32f66842014-08-27 19:27:47 -0700187 @Override
Yuta HIGUCHIf1f2ac02014-11-26 14:02:22 -0800188 public Iterable<Device> getAvailableDevices() {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900189 checkPermission(Permission.DEVICE_READ);
190
Yuta HIGUCHIf1f2ac02014-11-26 14:02:22 -0800191 return store.getAvailableDevices();
192 }
193
194 @Override
tom32f66842014-08-27 19:27:47 -0700195 public Device getDevice(DeviceId deviceId) {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900196 checkPermission(Permission.DEVICE_READ);
197
tom32f66842014-08-27 19:27:47 -0700198 checkNotNull(deviceId, DEVICE_ID_NULL);
tom132b58a2014-08-28 16:11:28 -0700199 return store.getDevice(deviceId);
tom32f66842014-08-27 19:27:47 -0700200 }
201
202 @Override
tomad2d2092014-09-06 23:24:20 -0700203 public MastershipRole getRole(DeviceId deviceId) {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900204 checkPermission(Permission.DEVICE_READ);
205
tomad2d2092014-09-06 23:24:20 -0700206 checkNotNull(deviceId, DEVICE_ID_NULL);
tomb41d1ac2014-09-24 01:51:24 -0700207 return mastershipService.getLocalRole(deviceId);
tomad2d2092014-09-06 23:24:20 -0700208 }
209
210 @Override
tom32f66842014-08-27 19:27:47 -0700211 public List<Port> getPorts(DeviceId deviceId) {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900212 checkPermission(Permission.DEVICE_READ);
213
tom32f66842014-08-27 19:27:47 -0700214 checkNotNull(deviceId, DEVICE_ID_NULL);
tom132b58a2014-08-28 16:11:28 -0700215 return store.getPorts(deviceId);
tom32f66842014-08-27 19:27:47 -0700216 }
217
218 @Override
sangho538108b2015-04-08 14:29:20 -0700219 public List<PortStatistics> getPortStatistics(DeviceId deviceId) {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900220 checkPermission(Permission.DEVICE_READ);
221
sangho538108b2015-04-08 14:29:20 -0700222 checkNotNull(deviceId, DEVICE_ID_NULL);
223 return store.getPortStatistics(deviceId);
224 }
225
226 @Override
tom32f66842014-08-27 19:27:47 -0700227 public Port getPort(DeviceId deviceId, PortNumber portNumber) {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900228 checkPermission(Permission.DEVICE_READ);
229
tom32f66842014-08-27 19:27:47 -0700230 checkNotNull(deviceId, DEVICE_ID_NULL);
231 checkNotNull(portNumber, PORT_NUMBER_NULL);
tom132b58a2014-08-28 16:11:28 -0700232 return store.getPort(deviceId, portNumber);
tom32f66842014-08-27 19:27:47 -0700233 }
234
235 @Override
tomff7eb7c2014-09-08 12:49:03 -0700236 public boolean isAvailable(DeviceId deviceId) {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900237 checkPermission(Permission.DEVICE_READ);
238
tomff7eb7c2014-09-08 12:49:03 -0700239 checkNotNull(deviceId, DEVICE_ID_NULL);
240 return store.isAvailable(deviceId);
241 }
242
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700243 // Check a device for control channel connectivity.
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700244 private boolean isReachable(DeviceId deviceId) {
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800245 if (deviceId == null) {
246 return false;
247 }
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700248 DeviceProvider provider = getProvider(deviceId);
249 if (provider != null) {
250 return provider.isReachable(deviceId);
251 } else {
Yuta HIGUCHI72669c42014-11-13 14:48:17 -0800252 log.debug("Provider not found for {}", deviceId);
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700253 return false;
254 }
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700255 }
256
tome5ec3fd2014-09-04 15:18:06 -0700257 @Override
258 public void removeDevice(DeviceId deviceId) {
259 checkNotNull(deviceId, DEVICE_ID_NULL);
260 DeviceEvent event = store.removeDevice(deviceId);
tom0efbb1d2014-09-09 11:54:28 -0700261 if (event != null) {
262 log.info("Device {} administratively removed", deviceId);
263 post(event);
264 }
tome5ec3fd2014-09-04 15:18:06 -0700265 }
266
tom7869ad92014-09-09 14:32:08 -0700267 @Override
268 public void addListener(DeviceListener listener) {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900269 checkPermission(Permission.DEVICE_EVENT);
270
tom7869ad92014-09-09 14:32:08 -0700271 listenerRegistry.addListener(listener);
272 }
273
274 @Override
275 public void removeListener(DeviceListener listener) {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900276 checkPermission(Permission.DEVICE_EVENT);
277
tom7869ad92014-09-09 14:32:08 -0700278 listenerRegistry.removeListener(listener);
279 }
280
281 @Override
samuele1fa7322015-07-14 16:35:16 +0800282 protected DeviceProviderService createProviderService(
283 DeviceProvider provider) {
tom7869ad92014-09-09 14:32:08 -0700284 return new InternalDeviceProviderService(provider);
285 }
286
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800287 /**
288 * Checks if all the reachable devices have a valid mastership role.
289 */
290 private void mastershipCheck() {
291 log.debug("Checking mastership");
292 for (Device device : getDevices()) {
293 final DeviceId deviceId = device.id();
Jonathan Hart2f669362015-02-11 16:19:20 -0800294 log.trace("Checking device {}", deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800295
296 if (!isReachable(deviceId)) {
297 continue;
298 }
299
300 if (mastershipService.getLocalRole(deviceId) != NONE) {
301 continue;
302 }
303
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700304 log.info("{} is reachable but did not have a valid role, reasserting",
305 deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800306
307 // isReachable but was not MASTER or STANDBY, get a role and apply
308 // Note: NONE triggers request to MastershipService
309 reassertRole(deviceId, NONE);
310 }
311 }
312
tomd3097b02014-08-26 10:40:29 -0700313 // Personalized device provider service issued to the supplied provider.
tomdc361b62014-09-09 20:36:52 -0700314 private class InternalDeviceProviderService
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700315 extends AbstractProviderService<DeviceProvider>
316 implements DeviceProviderService {
tomd3097b02014-08-26 10:40:29 -0700317
tomcfde0622014-09-09 11:02:42 -0700318 InternalDeviceProviderService(DeviceProvider provider) {
tomd3097b02014-08-26 10:40:29 -0700319 super(provider);
320 }
321
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700322 /**
323 * Apply role in reaction to provider event.
324 *
samuele1fa7322015-07-14 16:35:16 +0800325 * @param deviceId device identifier
326 * @param newRole new role to apply to the device
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700327 * @return true if the request was sent to provider
328 */
329 private boolean applyRole(DeviceId deviceId, MastershipRole newRole) {
330
331 if (newRole.equals(MastershipRole.NONE)) {
samuele1fa7322015-07-14 16:35:16 +0800332 //no-op
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700333 return true;
334 }
335
336 DeviceProvider provider = provider();
337 if (provider == null) {
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700338 log.warn("Provider for {} was not found. Cannot apply role {}",
339 deviceId, newRole);
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700340 return false;
341 }
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700342 provider.roleChanged(deviceId, newRole);
343 // not triggering probe when triggered by provider service event
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700344
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700345 return true;
346 }
347
samuele1fa7322015-07-14 16:35:16 +0800348
tomd3097b02014-08-26 10:40:29 -0700349 @Override
alshabibb7b40632014-09-28 21:30:00 -0700350 public void deviceConnected(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700351 DeviceDescription deviceDescription) {
tom32f66842014-08-27 19:27:47 -0700352 checkNotNull(deviceId, DEVICE_ID_NULL);
353 checkNotNull(deviceDescription, DEVICE_DESCRIPTION_NULL);
tomeadbb462014-09-07 16:10:19 -0700354 checkValidity();
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700355 deviceDescription = validateDevice(deviceDescription, deviceId);
Yuta HIGUCHI24b2e2a2014-10-07 15:53:57 -0700356
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700357 // check my Role
samuele1fa7322015-07-14 16:35:16 +0800358 CompletableFuture<MastershipRole> role = mastershipService.requestRoleFor(deviceId);
HIGUCHI Yuta11530fb2015-05-27 13:10:20 -0700359 try {
360 // Device subsystem must wait for role assignment
361 // to avoid losing Device information.
362 // (This node could be the only Node connected to the Device.)
363 role.get();
364 } catch (InterruptedException e) {
samuele1fa7322015-07-14 16:35:16 +0800365 log.warn("Interrupted while waiting role-assignment for {}", deviceId);
HIGUCHI Yuta11530fb2015-05-27 13:10:20 -0700366 Thread.currentThread().interrupt();
367 } catch (ExecutionException e) {
368 log.error("Exception thrown while waiting role-assignment for {}",
369 deviceId, e);
370 }
371
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700372 final MastershipTerm term = termService.getMastershipTerm(deviceId);
Madan Jampanide003d92015-05-11 17:14:20 -0700373 if (term == null || !localNodeId.equals(term.master())) {
Yuta HIGUCHI2d3cd312014-10-31 11:38:04 -0700374 log.info("Role of this node is STANDBY for {}", deviceId);
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700375 applyRole(deviceId, MastershipRole.STANDBY);
Marc De Leenheerb473b9d2015-02-06 15:21:03 -0800376 } else {
377 log.info("Role of this node is MASTER for {}", deviceId);
378 // tell clock provider if this instance is the master
379 deviceClockProviderService.setMastershipTerm(deviceId, term);
380 applyRole(deviceId, MastershipRole.MASTER);
Yuta HIGUCHI24b2e2a2014-10-07 15:53:57 -0700381 }
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700382 DeviceEvent event = store.createOrUpdateDevice(provider().id(), deviceId,
383 deviceDescription);
tom80c0e5e2014-09-08 18:08:58 -0700384 if (event != null) {
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700385 log.trace("event: {} {}", event.type(), event);
tom568581d2014-09-08 20:13:36 -0700386 post(event);
tom80c0e5e2014-09-08 18:08:58 -0700387 }
tomd3097b02014-08-26 10:40:29 -0700388 }
389
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700390 // returns a DeviceDescription made from the union of the BasicDeviceConfig
391 // annotations if it exists
392 private DeviceDescription validateDevice(DeviceDescription deviceDescription, DeviceId deviceId) {
393 BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class);
394 checkState(cfg == null || cfg.isAllowed(), "Device " + deviceId + " is not allowed");
395 log.info("Device {} connected", deviceId);
396 if (cfg != null) {
397 SparseAnnotations finalSparse = processAnnotations(cfg, deviceDescription, deviceId);
398 if (cfg.type() != Type.SWITCH) {
399 deviceDescription = new DefaultDeviceDescription(deviceDescription,
400 cfg.type(), finalSparse);
401 } else {
402 deviceDescription = new DefaultDeviceDescription(deviceDescription,
403 deviceDescription.type(), finalSparse);
404 }
405 }
406 return deviceDescription;
407 }
408
tomd3097b02014-08-26 10:40:29 -0700409 @Override
410 public void deviceDisconnected(DeviceId deviceId) {
tom32f66842014-08-27 19:27:47 -0700411 checkNotNull(deviceId, DEVICE_ID_NULL);
tomeadbb462014-09-07 16:10:19 -0700412 checkValidity();
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700413
Yuta HIGUCHI2d3cd312014-10-31 11:38:04 -0700414 log.info("Device {} disconnected from this node", deviceId);
Ayaka Koshibed9f693e2014-09-29 18:04:54 -0700415
alshabibafc514a2014-12-01 14:44:05 -0800416 List<Port> ports = store.getPorts(deviceId);
417 List<PortDescription> descs = Lists.newArrayList();
samuele1fa7322015-07-14 16:35:16 +0800418 ports.forEach(port ->
419 descs.add(new DefaultPortDescription(port.number(),
420 false, port.type(),
421 port.portSpeed())));
alshabibafc514a2014-12-01 14:44:05 -0800422 store.updatePorts(this.provider().id(), deviceId, descs);
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700423 try {
Thomas Vachuska5f429d62015-05-28 15:34:36 -0700424 if (mastershipService.getLocalRole(deviceId) == MASTER) {
425 post(store.markOffline(deviceId));
426 }
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700427 } catch (IllegalStateException e) {
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700428 log.warn("Failed to mark {} offline", deviceId);
429 // only the MASTER should be marking off-line in normal cases,
samuele1fa7322015-07-14 16:35:16 +0800430 // but if I was the last STANDBY connection, etc. and no one else
431 // was there to mark the device offline, this instance may need to
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700432 // temporarily request for Master Role and mark offline.
433
samuele1fa7322015-07-14 16:35:16 +0800434 //there are times when this node will correctly have mastership, BUT
435 //that isn't reflected in the ClockManager before the device disconnects.
436 //we want to let go of the device anyways, so make sure this happens.
Yuta HIGUCHI0722fb22014-10-19 01:16:33 -0700437
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700438 // FIXME: Store semantics leaking out as IllegalStateException.
samuele1fa7322015-07-14 16:35:16 +0800439 // Consider revising store API to handle this scenario.
440 CompletableFuture<MastershipRole> roleFuture = mastershipService.requestRoleFor(deviceId);
Madan Jampanide003d92015-05-11 17:14:20 -0700441 roleFuture.whenComplete((role, error) -> {
samuele1fa7322015-07-14 16:35:16 +0800442 MastershipTerm term = termService.getMastershipTerm(deviceId);
443 // TODO: Move this type of check inside device clock manager, etc.
444 if (term != null && localNodeId.equals(term.master())) {
445 log.info("Retry marking {} offline", deviceId);
446 deviceClockProviderService.setMastershipTerm(deviceId, term);
447 post(store.markOffline(deviceId));
448 } else {
449 log.info("Failed again marking {} offline. {}", deviceId, role);
450 }
451 });
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700452 } finally {
Madan Jampanic6e574f2015-05-29 13:41:52 -0700453 try {
samuele1fa7322015-07-14 16:35:16 +0800454 //relinquish master role and ability to be backup.
Madan Jampanic6e574f2015-05-29 13:41:52 -0700455 mastershipService.relinquishMastership(deviceId).get();
456 } catch (InterruptedException e) {
samuele1fa7322015-07-14 16:35:16 +0800457 log.warn("Interrupted while reliquishing role for {}", deviceId);
Madan Jampanic6e574f2015-05-29 13:41:52 -0700458 Thread.currentThread().interrupt();
459 } catch (ExecutionException e) {
samuele1fa7322015-07-14 16:35:16 +0800460 log.error("Exception thrown while relinquishing role for {}", deviceId, e);
Madan Jampanic6e574f2015-05-29 13:41:52 -0700461 }
tom0efbb1d2014-09-09 11:54:28 -0700462 }
tomd3097b02014-08-26 10:40:29 -0700463 }
464
465 @Override
alshabibb7b40632014-09-28 21:30:00 -0700466 public void updatePorts(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700467 List<PortDescription> portDescriptions) {
tom32f66842014-08-27 19:27:47 -0700468 checkNotNull(deviceId, DEVICE_ID_NULL);
alshabibb7b40632014-09-28 21:30:00 -0700469 checkNotNull(portDescriptions,
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700470 "Port descriptions list cannot be null");
tomeadbb462014-09-07 16:10:19 -0700471 checkValidity();
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700472 if (!deviceClockProviderService.isTimestampAvailable(deviceId)) {
473 // Never been a master for this device
474 // any update will be ignored.
samuele1fa7322015-07-14 16:35:16 +0800475 log.trace("Ignoring {} port updates on standby node. {}", deviceId, portDescriptions);
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700476 return;
477 }
478
Yuta HIGUCHI5f6739c2014-10-01 14:04:01 -0700479 List<DeviceEvent> events = store.updatePorts(this.provider().id(),
samuele1fa7322015-07-14 16:35:16 +0800480 deviceId, portDescriptions);
tom32f66842014-08-27 19:27:47 -0700481 for (DeviceEvent event : events) {
482 post(event);
483 }
tomd3097b02014-08-26 10:40:29 -0700484 }
485
486 @Override
alshabibb7b40632014-09-28 21:30:00 -0700487 public void portStatusChanged(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700488 PortDescription portDescription) {
tom32f66842014-08-27 19:27:47 -0700489 checkNotNull(deviceId, DEVICE_ID_NULL);
490 checkNotNull(portDescription, PORT_DESCRIPTION_NULL);
tomeadbb462014-09-07 16:10:19 -0700491 checkValidity();
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700492
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700493 if (!deviceClockProviderService.isTimestampAvailable(deviceId)) {
494 // Never been a master for this device
495 // any update will be ignored.
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700496 log.trace("Ignoring {} port update on standby node. {}", deviceId,
497 portDescription);
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700498 return;
499 }
500
samuele1fa7322015-07-14 16:35:16 +0800501 final DeviceEvent event = store.updatePortStatus(this.provider().id(),
502 deviceId, portDescription);
tomff7eb7c2014-09-08 12:49:03 -0700503 if (event != null) {
alshabibb7b40632014-09-28 21:30:00 -0700504 log.info("Device {} port {} status changed", deviceId, event
505 .port().number());
tom0efbb1d2014-09-09 11:54:28 -0700506 post(event);
tomff7eb7c2014-09-08 12:49:03 -0700507 }
tomd3097b02014-08-26 10:40:29 -0700508 }
tom3f2bbd72014-09-24 12:07:58 -0700509
510 @Override
samuele1fa7322015-07-14 16:35:16 +0800511 public void receivedRoleReply(DeviceId deviceId, MastershipRole requested,
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700512 MastershipRole response) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700513 // Several things can happen here:
514 // 1. request and response match
515 // 2. request and response don't match
516 // 3. MastershipRole and requested match (and 1 or 2 are true)
517 // 4. MastershipRole and requested don't match (and 1 or 2 are true)
518 //
519 // 2, 4, and 3 with case 2 are failure modes.
520
tom3f2bbd72014-09-24 12:07:58 -0700521 // FIXME: implement response to this notification
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700522
Madan Jampanif2af7712015-05-29 18:43:52 -0700523 log.debug("got reply to a role request for {}: asked for {}, and got {}",
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700524 deviceId, requested, response);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700525
526 if (requested == null && response == null) {
samuele1fa7322015-07-14 16:35:16 +0800527 // something was off with DeviceProvider, maybe check channel too?
528 log.warn("Failed to assert role [{}] onto Device {}", requested, deviceId);
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700529 mastershipService.relinquishMastership(deviceId);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700530 return;
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700531 }
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700532
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700533 if (Objects.equals(requested, response)) {
samuele1fa7322015-07-14 16:35:16 +0800534 if (Objects.equals(requested, mastershipService.getLocalRole(deviceId))) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700535 return;
536 } else {
537 return;
samuele1fa7322015-07-14 16:35:16 +0800538 // FIXME roleManager got the device to comply, but doesn't agree with
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700539 // the store; use the store's view, then try to reassert.
540 }
541 } else {
542 // we didn't get back what we asked for. Reelect someone else.
samuele1fa7322015-07-14 16:35:16 +0800543 log.warn("Failed to assert role [{}] onto Device {}", response, deviceId);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700544 if (response == MastershipRole.MASTER) {
545 mastershipService.relinquishMastership(deviceId);
546 // TODO: Shouldn't we be triggering event?
samuele1fa7322015-07-14 16:35:16 +0800547 //final Device device = getDevice(deviceId);
548 //post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device));
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700549 }
550 }
tom3f2bbd72014-09-24 12:07:58 -0700551 }
sangho538108b2015-04-08 14:29:20 -0700552
553 @Override
samuele1fa7322015-07-14 16:35:16 +0800554 public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
sangho538108b2015-04-08 14:29:20 -0700555 checkNotNull(deviceId, DEVICE_ID_NULL);
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700556 checkNotNull(portStatistics, "Port statistics list cannot be null");
sangho538108b2015-04-08 14:29:20 -0700557 checkValidity();
558
samuele1fa7322015-07-14 16:35:16 +0800559 DeviceEvent event = store.updatePortStatistics(this.provider().id(),
560 deviceId, portStatistics);
sangho538108b2015-04-08 14:29:20 -0700561 post(event);
562 }
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700563
564 // supplements or replaces deviceDescription annotations with
565 // BasicDeviceConfig annotations
566 private SparseAnnotations processAnnotations(BasicDeviceConfig cfg, DeviceDescription deviceDescription,
567 DeviceId deviceId) {
568 SparseAnnotations originalAnnotations = deviceDescription.annotations();
569 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
570 if (cfg.driver() != deviceId.toString()) {
571 newBuilder.set(cfg.DRIVER, cfg.driver());
572 }
573 if (cfg.type() != Type.SWITCH) {
574 newBuilder.set(cfg.TYPE, cfg.type().toString());
575 }
576 if (cfg.name() != null) {
577 newBuilder.set(cfg.NAME, cfg.name());
578 }
579 if (cfg.latitude() != -1) {
580 newBuilder.set(cfg.LATITUDE, Double.toString(cfg.latitude()));
581 }
582 if (cfg.longitude() != -1) {
583 newBuilder.set(cfg.LONGITUDE, Double.toString(cfg.longitude()));
584 }
585 if (cfg.rackAddress() != null) {
586 newBuilder.set(cfg.RACK_ADDRESS, cfg.rackAddress());
587 }
588 if (cfg.owner() != null) {
589 newBuilder.set(cfg.OWNER, cfg.owner());
590 }
591 DefaultAnnotations newAnnotations = newBuilder.build();
592 return DefaultAnnotations.union(originalAnnotations, newAnnotations);
593 }
tomd3097b02014-08-26 10:40:29 -0700594 }
tom32f66842014-08-27 19:27:47 -0700595
tomeadbb462014-09-07 16:10:19 -0700596 // Posts the specified event to the local event dispatcher.
tom32f66842014-08-27 19:27:47 -0700597 private void post(DeviceEvent event) {
598 if (event != null && eventDispatcher != null) {
599 eventDispatcher.post(event);
600 }
601 }
602
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800603 // Applies the specified role to the device; ignores NONE
604 /**
605 * Apply role to device and send probe if MASTER.
606 *
samuele1fa7322015-07-14 16:35:16 +0800607 * @param deviceId device identifier
608 * @param newRole new role to apply to the device
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800609 * @return true if the request was sent to provider
610 */
611 private boolean applyRoleAndProbe(DeviceId deviceId, MastershipRole newRole) {
612 if (newRole.equals(MastershipRole.NONE)) {
samuele1fa7322015-07-14 16:35:16 +0800613 //no-op
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700614 return true;
615 }
Ayaka Koshibe317245a2014-10-29 00:34:43 -0700616
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800617 DeviceProvider provider = getProvider(deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800618 if (provider == null) {
samuele1fa7322015-07-14 16:35:16 +0800619 log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800620 return false;
621 }
622 provider.roleChanged(deviceId, newRole);
623
624 if (newRole.equals(MastershipRole.MASTER)) {
625 // only trigger event when request was sent to provider
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800626 provider.triggerProbe(deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800627 }
628 return true;
629 }
630
631 /**
632 * Reaasert role for specified device connected to this node.
633 *
samuele1fa7322015-07-14 16:35:16 +0800634 * @param did device identifier
635 * @param nextRole role to apply. If NONE is specified,
636 * it will ask mastership service for a role and apply it.
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800637 */
samuele1fa7322015-07-14 16:35:16 +0800638 private void reassertRole(final DeviceId did,
639 final MastershipRole nextRole) {
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800640
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800641 MastershipRole myNextRole = nextRole;
642 if (myNextRole == NONE) {
643 mastershipService.requestRoleFor(did);
644 MastershipTerm term = termService.getMastershipTerm(did);
Madan Jampanide003d92015-05-11 17:14:20 -0700645 if (term != null && localNodeId.equals(term.master())) {
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800646 myNextRole = MASTER;
647 } else {
648 myNextRole = STANDBY;
649 }
650 }
651
652 switch (myNextRole) {
653 case MASTER:
654 final Device device = getDevice(did);
655 if ((device != null) && !isAvailable(did)) {
samuele1fa7322015-07-14 16:35:16 +0800656 //flag the device as online. Is there a better way to do this?
657 DefaultDeviceDescription deviceDescription
658 = new DefaultDeviceDescription(did.uri(),
659 device.type(),
660 device.manufacturer(),
661 device.hwVersion(),
662 device.swVersion(),
663 device.serialNumber(),
664 device.chassisId());
665 DeviceEvent devEvent =
666 store.createOrUpdateDevice(device.providerId(), did,
667 deviceDescription);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800668 post(devEvent);
669 }
670 // TODO: should apply role only if there is mismatch
Madan Jampanif2af7712015-05-29 18:43:52 -0700671 log.debug("Applying role {} to {}", myNextRole, did);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800672 if (!applyRoleAndProbe(did, MASTER)) {
Madan Jampanif2af7712015-05-29 18:43:52 -0700673 log.warn("Unsuccessful applying role {} to {}", myNextRole, did);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800674 // immediately failed to apply role
675 mastershipService.relinquishMastership(did);
676 // FIXME disconnect?
677 }
678 break;
679 case STANDBY:
Madan Jampanif2af7712015-05-29 18:43:52 -0700680 log.debug("Applying role {} to {}", myNextRole, did);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800681 if (!applyRoleAndProbe(did, STANDBY)) {
Madan Jampanif2af7712015-05-29 18:43:52 -0700682 log.warn("Unsuccessful applying role {} to {}", myNextRole, did);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800683 // immediately failed to apply role
684 mastershipService.relinquishMastership(did);
685 // FIXME disconnect?
686 }
687 break;
688 case NONE:
689 default:
690 // should never reach here
691 log.error("You didn't see anything. I did not exist.");
692 break;
693 }
694 }
695
Madan Jampani328371d2015-05-29 14:06:27 -0700696 private void handleMastershipEvent(MastershipEvent event) {
697 if (event.type() != MastershipEvent.Type.MASTER_CHANGED) {
698 // Don't care if backup list changed.
699 return;
700 }
701
702 final DeviceId did = event.subject();
703
704 // myRole suggested by MastershipService
705 MastershipRole myNextRole;
706 if (localNodeId.equals(event.roleInfo().master())) {
707 // confirm latest info
708 MastershipTerm term = termService.getMastershipTerm(did);
samuele1fa7322015-07-14 16:35:16 +0800709 final boolean iHaveControl = term != null && localNodeId.equals(term.master());
Madan Jampani328371d2015-05-29 14:06:27 -0700710 if (iHaveControl) {
711 deviceClockProviderService.setMastershipTerm(did, term);
712 myNextRole = MASTER;
713 } else {
714 myNextRole = STANDBY;
715 }
716 } else if (event.roleInfo().backups().contains(localNodeId)) {
717 myNextRole = STANDBY;
718 } else {
719 myNextRole = NONE;
720 }
721
samuele1fa7322015-07-14 16:35:16 +0800722
Madan Jampani328371d2015-05-29 14:06:27 -0700723 final boolean isReachable = isReachable(did);
724 if (!isReachable) {
725 // device is not connected to this node
726 if (myNextRole != NONE) {
727 log.warn("Node was instructed to be {} role for {}, "
728 + "but this node cannot reach the device. "
samuele1fa7322015-07-14 16:35:16 +0800729 + "Relinquishing role. ",
730 myNextRole, did);
Madan Jampani328371d2015-05-29 14:06:27 -0700731 mastershipService.relinquishMastership(did);
732 }
733 return;
734 }
735
736 // device is connected to this node:
737 if (store.getDevice(did) != null) {
738 reassertRole(did, myNextRole);
739 } else {
740 log.debug("Device is not yet/no longer in the store: {}", did);
741 }
742 }
743
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800744 // Intercepts mastership events
745 private class InternalMastershipListener implements MastershipListener {
746
tomb41d1ac2014-09-24 01:51:24 -0700747 @Override
748 public void event(MastershipEvent event) {
Madan Jampani328371d2015-05-29 14:06:27 -0700749 backgroundService.submit(() -> {
750 try {
751 handleMastershipEvent(event);
752 } catch (Exception e) {
753 log.warn("Failed to handle {}", event, e);
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700754 }
Madan Jampani328371d2015-05-29 14:06:27 -0700755 });
Ayaka Koshibe317245a2014-10-29 00:34:43 -0700756 }
tomb41d1ac2014-09-24 01:51:24 -0700757 }
tomf80c9722014-09-24 14:49:18 -0700758
759 // Store delegate to re-post events emitted from the store.
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700760 private class InternalStoreDelegate implements DeviceStoreDelegate {
tomf80c9722014-09-24 14:49:18 -0700761 @Override
762 public void notify(DeviceEvent event) {
763 post(event);
764 }
765 }
samuel738dfaf2015-07-11 11:08:57 +0800766
767 @Override
768 public Iterable<Device> getDevices(Type type) {
769 checkPermission(Permission.DEVICE_READ);
770 Set<Device> results = new HashSet<>();
771 Iterable<Device> devices = store.getDevices();
772 if (devices != null) {
773 devices.forEach(d -> {
774 if (type.equals(d.type())) {
775 results.add(d);
776 }
777 });
778 }
779 return results;
780 }
781
782 @Override
783 public Iterable<Device> getAvailableDevices(Type type) {
784 checkPermission(Permission.DEVICE_READ);
785 Set<Device> results = new HashSet<>();
786 Iterable<Device> availableDevices = store.getAvailableDevices();
787 if (availableDevices != null) {
788 availableDevices.forEach(d -> {
789 if (type.equals(d.type())) {
790 results.add(d);
791 }
792 });
793 }
794 return results;
795 }
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700796
797 private class InternalNetworkConfigListener implements NetworkConfigListener {
798 @Override
799 public void event(NetworkConfigEvent event) {
800 if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
801 event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) &&
802 event.configClass().equals(BasicDeviceConfig.class)) {
803 log.info("Detected Device network config event {}", event.type());
804 kickOutBadDevice(((DeviceId) event.subject()));
805 }
806 }
807 }
808
809 // checks if the specified device is allowed by the BasicDeviceConfig
810 // and if not, removes it
811 private void kickOutBadDevice(DeviceId deviceId) {
812 BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class);
813 if (!cfg.isAllowed()) {
814 Device badDevice = getDevice(deviceId);
815 if (badDevice != null) {
816 removeDevice(deviceId);
817 } else {
818 log.info("Failed removal: Device {} does not exist", deviceId);
819 }
820 }
821 }
tomd3097b02014-08-26 10:40:29 -0700822}