blob: 936d859da4a35c8bc83a6367f3f7836ef64a8dd0 [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);
Thomas Vachuska5923b9a2016-01-26 10:52:57 -0800420 if (events != null) {
421 for (DeviceEvent event : events) {
422 post(event);
423 }
tom32f66842014-08-27 19:27:47 -0700424 }
tomd3097b02014-08-26 10:40:29 -0700425 }
426
427 @Override
alshabibb7b40632014-09-28 21:30:00 -0700428 public void portStatusChanged(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700429 PortDescription portDescription) {
tom32f66842014-08-27 19:27:47 -0700430 checkNotNull(deviceId, DEVICE_ID_NULL);
431 checkNotNull(portDescription, PORT_DESCRIPTION_NULL);
tomeadbb462014-09-07 16:10:19 -0700432 checkValidity();
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700433
Madan Jampani565a66a2015-07-25 17:01:13 -0700434 if (!mastershipService.isLocalMaster(deviceId)) {
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700435 // Never been a master for this device
436 // any update will be ignored.
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700437 log.trace("Ignoring {} port update on standby node. {}", deviceId,
438 portDescription);
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700439 return;
440 }
Thomas Vachuskafa8aa2f2015-10-13 11:56:59 -0700441 Device device = nullIsNotFound(getDevice(deviceId), "Device not found");
Yafit Hadara9a73de2015-09-06 13:52:52 +0300442 if ((Device.Type.ROADM.equals(device.type()))) {
443 Port port = getPort(deviceId, portDescription.portNumber());
444 portDescription = OpticalPortOperator.descriptionOf(port, portDescription.isEnabled());
445 }
446
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700447 portDescription = consolidate(deviceId, portDescription);
samuele1fa7322015-07-14 16:35:16 +0800448 final DeviceEvent event = store.updatePortStatus(this.provider().id(),
449 deviceId, portDescription);
tomff7eb7c2014-09-08 12:49:03 -0700450 if (event != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700451 log.info("Device {} port {} status changed", deviceId, event.port().number());
tom0efbb1d2014-09-09 11:54:28 -0700452 post(event);
tomff7eb7c2014-09-08 12:49:03 -0700453 }
tomd3097b02014-08-26 10:40:29 -0700454 }
tom3f2bbd72014-09-24 12:07:58 -0700455
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700456 // merges the appropriate PortConfig with the description.
457 private PortDescription consolidate(DeviceId did, PortDescription desc) {
458 switch (desc.type()) {
459 case COPPER:
460 case VIRTUAL:
461 return desc;
462 default:
463 OpticalPortConfig opc = networkConfigService.getConfig(
464 new ConnectPoint(did, desc.portNumber()), OpticalPortConfig.class);
465 return OpticalPortOperator.combine(opc, desc);
466 }
467 }
468
tom3f2bbd72014-09-24 12:07:58 -0700469 @Override
samuele1fa7322015-07-14 16:35:16 +0800470 public void receivedRoleReply(DeviceId deviceId, MastershipRole requested,
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700471 MastershipRole response) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700472 // Several things can happen here:
473 // 1. request and response match
474 // 2. request and response don't match
475 // 3. MastershipRole and requested match (and 1 or 2 are true)
476 // 4. MastershipRole and requested don't match (and 1 or 2 are true)
477 //
478 // 2, 4, and 3 with case 2 are failure modes.
479
tom3f2bbd72014-09-24 12:07:58 -0700480 // FIXME: implement response to this notification
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700481
Madan Jampanif2af7712015-05-29 18:43:52 -0700482 log.debug("got reply to a role request for {}: asked for {}, and got {}",
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700483 deviceId, requested, response);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700484
485 if (requested == null && response == null) {
samuele1fa7322015-07-14 16:35:16 +0800486 // something was off with DeviceProvider, maybe check channel too?
487 log.warn("Failed to assert role [{}] onto Device {}", requested, deviceId);
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700488 mastershipService.relinquishMastership(deviceId);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700489 return;
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700490 }
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700491
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700492 if (Objects.equals(requested, response)) {
samuele1fa7322015-07-14 16:35:16 +0800493 if (Objects.equals(requested, mastershipService.getLocalRole(deviceId))) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700494 return;
495 } else {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800496 log.warn("Role mismatch on {}. set to {}, but store demands {}",
497 deviceId, response, mastershipService.getLocalRole(deviceId));
498 // roleManager got the device to comply, but doesn't agree with
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700499 // the store; use the store's view, then try to reassert.
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800500 backgroundService.submit(() -> reassertRole(deviceId, mastershipService.getLocalRole(deviceId)));
501 return;
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700502 }
503 } else {
504 // we didn't get back what we asked for. Reelect someone else.
samuele1fa7322015-07-14 16:35:16 +0800505 log.warn("Failed to assert role [{}] onto Device {}", response, deviceId);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700506 if (response == MastershipRole.MASTER) {
507 mastershipService.relinquishMastership(deviceId);
508 // TODO: Shouldn't we be triggering event?
samuele1fa7322015-07-14 16:35:16 +0800509 //final Device device = getDevice(deviceId);
510 //post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device));
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700511 }
512 }
tom3f2bbd72014-09-24 12:07:58 -0700513 }
sangho538108b2015-04-08 14:29:20 -0700514
515 @Override
samuele1fa7322015-07-14 16:35:16 +0800516 public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
sangho538108b2015-04-08 14:29:20 -0700517 checkNotNull(deviceId, DEVICE_ID_NULL);
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700518 checkNotNull(portStatistics, "Port statistics list cannot be null");
sangho538108b2015-04-08 14:29:20 -0700519 checkValidity();
520
samuele1fa7322015-07-14 16:35:16 +0800521 DeviceEvent event = store.updatePortStatistics(this.provider().id(),
522 deviceId, portStatistics);
sangho538108b2015-04-08 14:29:20 -0700523 post(event);
524 }
tomd3097b02014-08-26 10:40:29 -0700525 }
tom32f66842014-08-27 19:27:47 -0700526
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700527 // by default allowed, otherwise check flag
528 private boolean isAllowed(BasicDeviceConfig cfg) {
529 return (cfg == null || cfg.isAllowed());
530 }
531
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800532 // Applies the specified role to the device; ignores NONE
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700533
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800534 /**
535 * Apply role to device and send probe if MASTER.
536 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700537 * @param deviceId device identifier
538 * @param newRole new role to apply to the device
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800539 * @return true if the request was sent to provider
540 */
541 private boolean applyRoleAndProbe(DeviceId deviceId, MastershipRole newRole) {
542 if (newRole.equals(MastershipRole.NONE)) {
samuele1fa7322015-07-14 16:35:16 +0800543 //no-op
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700544 return true;
545 }
Ayaka Koshibe317245a2014-10-29 00:34:43 -0700546
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800547 DeviceProvider provider = getProvider(deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800548 if (provider == null) {
samuele1fa7322015-07-14 16:35:16 +0800549 log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800550 return false;
551 }
552 provider.roleChanged(deviceId, newRole);
553
554 if (newRole.equals(MastershipRole.MASTER)) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800555 log.debug("sent TriggerProbe({})", deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800556 // only trigger event when request was sent to provider
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800557 provider.triggerProbe(deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800558 }
559 return true;
560 }
561
562 /**
563 * Reaasert role for specified device connected to this node.
564 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700565 * @param did device identifier
566 * @param nextRole role to apply. If NONE is specified,
567 * it will ask mastership service for a role and apply it.
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800568 */
samuele1fa7322015-07-14 16:35:16 +0800569 private void reassertRole(final DeviceId did,
570 final MastershipRole nextRole) {
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800571
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800572 MastershipRole myNextRole = nextRole;
573 if (myNextRole == NONE) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800574 try {
575 mastershipService.requestRoleFor(did).get();
576 MastershipTerm term = termService.getMastershipTerm(did);
577 if (term != null && localNodeId.equals(term.master())) {
578 myNextRole = MASTER;
579 } else {
580 myNextRole = STANDBY;
581 }
582 } catch (InterruptedException e) {
583 Thread.currentThread().interrupt();
584 log.error("Interrupted waiting for Mastership", e);
585 } catch (ExecutionException e) {
586 log.error("Encountered an error waiting for Mastership", e);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800587 }
588 }
589
590 switch (myNextRole) {
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700591 case MASTER:
592 final Device device = getDevice(did);
593 if ((device != null) && !isAvailable(did)) {
594 //flag the device as online. Is there a better way to do this?
595 DefaultDeviceDescription deviceDescription
596 = new DefaultDeviceDescription(did.uri(),
597 device.type(),
598 device.manufacturer(),
599 device.hwVersion(),
600 device.swVersion(),
601 device.serialNumber(),
602 device.chassisId());
603 DeviceEvent devEvent =
604 store.createOrUpdateDevice(device.providerId(), did,
605 deviceDescription);
606 post(devEvent);
607 }
608 // TODO: should apply role only if there is mismatch
609 log.debug("Applying role {} to {}", myNextRole, did);
610 if (!applyRoleAndProbe(did, MASTER)) {
611 log.warn("Unsuccessful applying role {} to {}", myNextRole, did);
612 // immediately failed to apply role
613 mastershipService.relinquishMastership(did);
614 // FIXME disconnect?
615 }
616 break;
617 case STANDBY:
618 log.debug("Applying role {} to {}", myNextRole, did);
619 if (!applyRoleAndProbe(did, STANDBY)) {
620 log.warn("Unsuccessful applying role {} to {}", myNextRole, did);
621 // immediately failed to apply role
622 mastershipService.relinquishMastership(did);
623 // FIXME disconnect?
624 }
625 break;
626 case NONE:
627 default:
628 // should never reach here
629 log.error("You didn't see anything. I did not exist.");
630 break;
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800631 }
632 }
633
Madan Jampani328371d2015-05-29 14:06:27 -0700634 private void handleMastershipEvent(MastershipEvent event) {
635 if (event.type() != MastershipEvent.Type.MASTER_CHANGED) {
636 // Don't care if backup list changed.
637 return;
638 }
639
640 final DeviceId did = event.subject();
641
642 // myRole suggested by MastershipService
643 MastershipRole myNextRole;
644 if (localNodeId.equals(event.roleInfo().master())) {
645 // confirm latest info
646 MastershipTerm term = termService.getMastershipTerm(did);
samuele1fa7322015-07-14 16:35:16 +0800647 final boolean iHaveControl = term != null && localNodeId.equals(term.master());
Madan Jampani328371d2015-05-29 14:06:27 -0700648 if (iHaveControl) {
Madan Jampani328371d2015-05-29 14:06:27 -0700649 myNextRole = MASTER;
650 } else {
651 myNextRole = STANDBY;
652 }
653 } else if (event.roleInfo().backups().contains(localNodeId)) {
654 myNextRole = STANDBY;
655 } else {
656 myNextRole = NONE;
657 }
658
Madan Jampani328371d2015-05-29 14:06:27 -0700659 final boolean isReachable = isReachable(did);
660 if (!isReachable) {
661 // device is not connected to this node
662 if (myNextRole != NONE) {
663 log.warn("Node was instructed to be {} role for {}, "
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700664 + "but this node cannot reach the device. "
665 + "Relinquishing role. ",
samuele1fa7322015-07-14 16:35:16 +0800666 myNextRole, did);
Madan Jampani328371d2015-05-29 14:06:27 -0700667 mastershipService.relinquishMastership(did);
668 }
669 return;
670 }
671
672 // device is connected to this node:
673 if (store.getDevice(did) != null) {
674 reassertRole(did, myNextRole);
675 } else {
676 log.debug("Device is not yet/no longer in the store: {}", did);
677 }
678 }
679
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800680 // Intercepts mastership events
681 private class InternalMastershipListener implements MastershipListener {
682
tomb41d1ac2014-09-24 01:51:24 -0700683 @Override
684 public void event(MastershipEvent event) {
Madan Jampani328371d2015-05-29 14:06:27 -0700685 backgroundService.submit(() -> {
686 try {
687 handleMastershipEvent(event);
688 } catch (Exception e) {
689 log.warn("Failed to handle {}", event, e);
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700690 }
Madan Jampani328371d2015-05-29 14:06:27 -0700691 });
Ayaka Koshibe317245a2014-10-29 00:34:43 -0700692 }
tomb41d1ac2014-09-24 01:51:24 -0700693 }
tomf80c9722014-09-24 14:49:18 -0700694
695 // Store delegate to re-post events emitted from the store.
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700696 private class InternalStoreDelegate implements DeviceStoreDelegate {
tomf80c9722014-09-24 14:49:18 -0700697 @Override
698 public void notify(DeviceEvent event) {
699 post(event);
700 }
701 }
samuel738dfaf2015-07-11 11:08:57 +0800702
703 @Override
704 public Iterable<Device> getDevices(Type type) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900705 checkPermission(DEVICE_READ);
samuel738dfaf2015-07-11 11:08:57 +0800706 Set<Device> results = new HashSet<>();
707 Iterable<Device> devices = store.getDevices();
708 if (devices != null) {
709 devices.forEach(d -> {
710 if (type.equals(d.type())) {
711 results.add(d);
712 }
713 });
714 }
715 return results;
716 }
717
718 @Override
719 public Iterable<Device> getAvailableDevices(Type type) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900720 checkPermission(DEVICE_READ);
samuel738dfaf2015-07-11 11:08:57 +0800721 Set<Device> results = new HashSet<>();
722 Iterable<Device> availableDevices = store.getAvailableDevices();
723 if (availableDevices != null) {
724 availableDevices.forEach(d -> {
725 if (type.equals(d.type())) {
726 results.add(d);
727 }
728 });
729 }
730 return results;
731 }
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700732
733 private class InternalNetworkConfigListener implements NetworkConfigListener {
734 @Override
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700735 public boolean isRelevant(NetworkConfigEvent event) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700736 return (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
737 || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)
738 && (event.configClass().equals(BasicDeviceConfig.class)
739 || event.configClass().equals(OpticalPortConfig.class));
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700740 }
741
742 @Override
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700743 public void event(NetworkConfigEvent event) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700744 DeviceEvent de = null;
745 if (event.configClass().equals(BasicDeviceConfig.class)) {
Thomas Vachuska138de8b2016-01-11 21:31:38 -0800746 log.debug("Detected device network config event {}", event.type());
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700747 DeviceId did = (DeviceId) event.subject();
748 BasicDeviceConfig cfg = networkConfigService.getConfig(did, BasicDeviceConfig.class);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700749
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700750 if (!isAllowed(cfg)) {
751 kickOutBadDevice(did);
752 } else {
753 Device dev = getDevice(did);
754 DeviceDescription desc = (dev == null) ? null : BasicDeviceOperator.descriptionOf(dev);
755 desc = BasicDeviceOperator.combine(cfg, desc);
Thomas Vachuska1627dc82015-11-13 12:22:14 -0800756 if (desc != null && getProvider(did) != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700757 de = store.createOrUpdateDevice(getProvider(did).id(), did, desc);
758 }
759 }
760 }
761 if (event.configClass().equals(OpticalPortConfig.class)) {
762 ConnectPoint cpt = (ConnectPoint) event.subject();
763 DeviceId did = cpt.deviceId();
764 Port dpt = getPort(did, cpt.port());
765
766 if (dpt != null) {
767 OpticalPortConfig opc = networkConfigService.getConfig(cpt, OpticalPortConfig.class);
768 PortDescription desc = OpticalPortOperator.descriptionOf(dpt);
769 desc = OpticalPortOperator.combine(opc, desc);
Thomas Vachuska1627dc82015-11-13 12:22:14 -0800770 if (desc != null && getProvider(did) != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700771 de = store.updatePortStatus(getProvider(did).id(), did, desc);
772 }
773 }
774 }
775
776 if (de != null) {
777 post(de);
778 }
779 }
780
781 // checks if the specified device is allowed by the BasicDeviceConfig
782 // and if not, removes it
783 private void kickOutBadDevice(DeviceId deviceId) {
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700784 Device badDevice = getDevice(deviceId);
785 if (badDevice != null) {
786 removeDevice(deviceId);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700787 }
788 }
789 }
tomd3097b02014-08-26 10:40:29 -0700790}