blob: 60fd95abd97a301b0e546e3e8ca5097d2935da83 [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(
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +0200355 port -> (!(Device.Type.ROADM.equals(device.type()) ||
356 (Device.Type.OTN.equals(device.type())))) ?
Yafit Hadara9a73de2015-09-06 13:52:52 +0300357 new DefaultPortDescription(port.number(), false,
358 port.type(), port.portSpeed()) :
359 OpticalPortOperator.descriptionOf(port, false)
360 ).collect(Collectors.toList());
361
alshabibafc514a2014-12-01 14:44:05 -0800362 store.updatePorts(this.provider().id(), deviceId, descs);
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700363 try {
Madan Jampani565a66a2015-07-25 17:01:13 -0700364 if (mastershipService.isLocalMaster(deviceId)) {
Thomas Vachuska5f429d62015-05-28 15:34:36 -0700365 post(store.markOffline(deviceId));
366 }
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700367 } catch (IllegalStateException e) {
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700368 log.warn("Failed to mark {} offline", deviceId);
369 // only the MASTER should be marking off-line in normal cases,
samuele1fa7322015-07-14 16:35:16 +0800370 // but if I was the last STANDBY connection, etc. and no one else
371 // was there to mark the device offline, this instance may need to
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700372 // temporarily request for Master Role and mark offline.
373
samuele1fa7322015-07-14 16:35:16 +0800374 //there are times when this node will correctly have mastership, BUT
375 //that isn't reflected in the ClockManager before the device disconnects.
376 //we want to let go of the device anyways, so make sure this happens.
Yuta HIGUCHI0722fb22014-10-19 01:16:33 -0700377
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700378 // FIXME: Store semantics leaking out as IllegalStateException.
samuele1fa7322015-07-14 16:35:16 +0800379 // Consider revising store API to handle this scenario.
380 CompletableFuture<MastershipRole> roleFuture = mastershipService.requestRoleFor(deviceId);
Madan Jampanide003d92015-05-11 17:14:20 -0700381 roleFuture.whenComplete((role, error) -> {
samuele1fa7322015-07-14 16:35:16 +0800382 MastershipTerm term = termService.getMastershipTerm(deviceId);
383 // TODO: Move this type of check inside device clock manager, etc.
384 if (term != null && localNodeId.equals(term.master())) {
385 log.info("Retry marking {} offline", deviceId);
samuele1fa7322015-07-14 16:35:16 +0800386 post(store.markOffline(deviceId));
387 } else {
388 log.info("Failed again marking {} offline. {}", deviceId, role);
389 }
390 });
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700391 } finally {
Madan Jampanic6e574f2015-05-29 13:41:52 -0700392 try {
samuele1fa7322015-07-14 16:35:16 +0800393 //relinquish master role and ability to be backup.
Madan Jampanic6e574f2015-05-29 13:41:52 -0700394 mastershipService.relinquishMastership(deviceId).get();
395 } catch (InterruptedException e) {
samuele1fa7322015-07-14 16:35:16 +0800396 log.warn("Interrupted while reliquishing role for {}", deviceId);
Madan Jampanic6e574f2015-05-29 13:41:52 -0700397 Thread.currentThread().interrupt();
398 } catch (ExecutionException e) {
samuele1fa7322015-07-14 16:35:16 +0800399 log.error("Exception thrown while relinquishing role for {}", deviceId, e);
Madan Jampanic6e574f2015-05-29 13:41:52 -0700400 }
tom0efbb1d2014-09-09 11:54:28 -0700401 }
tomd3097b02014-08-26 10:40:29 -0700402 }
403
404 @Override
alshabibb7b40632014-09-28 21:30:00 -0700405 public void updatePorts(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700406 List<PortDescription> portDescriptions) {
tom32f66842014-08-27 19:27:47 -0700407 checkNotNull(deviceId, DEVICE_ID_NULL);
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700408 checkNotNull(portDescriptions, PORT_DESC_LIST_NULL);
tomeadbb462014-09-07 16:10:19 -0700409 checkValidity();
Madan Jampani565a66a2015-07-25 17:01:13 -0700410 if (!mastershipService.isLocalMaster(deviceId)) {
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700411 // Never been a master for this device
412 // any update will be ignored.
samuele1fa7322015-07-14 16:35:16 +0800413 log.trace("Ignoring {} port updates on standby node. {}", deviceId, portDescriptions);
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700414 return;
415 }
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700416 portDescriptions = portDescriptions.stream()
417 .map(e -> consolidate(deviceId, e))
418 .collect(Collectors.toList());
Yuta HIGUCHI5f6739c2014-10-01 14:04:01 -0700419 List<DeviceEvent> events = store.updatePorts(this.provider().id(),
samuele1fa7322015-07-14 16:35:16 +0800420 deviceId, portDescriptions);
Thomas Vachuska5923b9a2016-01-26 10:52:57 -0800421 if (events != null) {
422 for (DeviceEvent event : events) {
423 post(event);
424 }
tom32f66842014-08-27 19:27:47 -0700425 }
tomd3097b02014-08-26 10:40:29 -0700426 }
427
428 @Override
alshabibb7b40632014-09-28 21:30:00 -0700429 public void portStatusChanged(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700430 PortDescription portDescription) {
tom32f66842014-08-27 19:27:47 -0700431 checkNotNull(deviceId, DEVICE_ID_NULL);
432 checkNotNull(portDescription, PORT_DESCRIPTION_NULL);
tomeadbb462014-09-07 16:10:19 -0700433 checkValidity();
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700434
Madan Jampani565a66a2015-07-25 17:01:13 -0700435 if (!mastershipService.isLocalMaster(deviceId)) {
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700436 // Never been a master for this device
437 // any update will be ignored.
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700438 log.trace("Ignoring {} port update on standby node. {}", deviceId,
439 portDescription);
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700440 return;
441 }
Thomas Vachuskafa8aa2f2015-10-13 11:56:59 -0700442 Device device = nullIsNotFound(getDevice(deviceId), "Device not found");
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +0200443 if ((Device.Type.ROADM.equals(device.type())) ||
444 (Device.Type.OTN.equals(device.type()))) {
Yafit Hadara9a73de2015-09-06 13:52:52 +0300445 Port port = getPort(deviceId, portDescription.portNumber());
446 portDescription = OpticalPortOperator.descriptionOf(port, portDescription.isEnabled());
447 }
448
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700449 portDescription = consolidate(deviceId, portDescription);
samuele1fa7322015-07-14 16:35:16 +0800450 final DeviceEvent event = store.updatePortStatus(this.provider().id(),
451 deviceId, portDescription);
tomff7eb7c2014-09-08 12:49:03 -0700452 if (event != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700453 log.info("Device {} port {} status changed", deviceId, event.port().number());
tom0efbb1d2014-09-09 11:54:28 -0700454 post(event);
tomff7eb7c2014-09-08 12:49:03 -0700455 }
tomd3097b02014-08-26 10:40:29 -0700456 }
tom3f2bbd72014-09-24 12:07:58 -0700457
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700458 // merges the appropriate PortConfig with the description.
459 private PortDescription consolidate(DeviceId did, PortDescription desc) {
460 switch (desc.type()) {
461 case COPPER:
462 case VIRTUAL:
463 return desc;
464 default:
465 OpticalPortConfig opc = networkConfigService.getConfig(
466 new ConnectPoint(did, desc.portNumber()), OpticalPortConfig.class);
467 return OpticalPortOperator.combine(opc, desc);
468 }
469 }
470
tom3f2bbd72014-09-24 12:07:58 -0700471 @Override
samuele1fa7322015-07-14 16:35:16 +0800472 public void receivedRoleReply(DeviceId deviceId, MastershipRole requested,
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700473 MastershipRole response) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700474 // Several things can happen here:
475 // 1. request and response match
476 // 2. request and response don't match
477 // 3. MastershipRole and requested match (and 1 or 2 are true)
478 // 4. MastershipRole and requested don't match (and 1 or 2 are true)
479 //
480 // 2, 4, and 3 with case 2 are failure modes.
481
tom3f2bbd72014-09-24 12:07:58 -0700482 // FIXME: implement response to this notification
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700483
Madan Jampanif2af7712015-05-29 18:43:52 -0700484 log.debug("got reply to a role request for {}: asked for {}, and got {}",
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700485 deviceId, requested, response);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700486
487 if (requested == null && response == null) {
samuele1fa7322015-07-14 16:35:16 +0800488 // something was off with DeviceProvider, maybe check channel too?
Shashikanth VH387a1ca2016-02-09 20:35:21 +0530489 log.warn("Failed to assert role onto Device {}", deviceId);
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700490 mastershipService.relinquishMastership(deviceId);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700491 return;
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700492 }
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700493
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700494 if (Objects.equals(requested, response)) {
samuele1fa7322015-07-14 16:35:16 +0800495 if (Objects.equals(requested, mastershipService.getLocalRole(deviceId))) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700496 return;
497 } else {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800498 log.warn("Role mismatch on {}. set to {}, but store demands {}",
499 deviceId, response, mastershipService.getLocalRole(deviceId));
500 // roleManager got the device to comply, but doesn't agree with
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700501 // the store; use the store's view, then try to reassert.
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800502 backgroundService.submit(() -> reassertRole(deviceId, mastershipService.getLocalRole(deviceId)));
503 return;
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700504 }
505 } else {
506 // we didn't get back what we asked for. Reelect someone else.
samuele1fa7322015-07-14 16:35:16 +0800507 log.warn("Failed to assert role [{}] onto Device {}", response, deviceId);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700508 if (response == MastershipRole.MASTER) {
509 mastershipService.relinquishMastership(deviceId);
510 // TODO: Shouldn't we be triggering event?
samuele1fa7322015-07-14 16:35:16 +0800511 //final Device device = getDevice(deviceId);
512 //post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device));
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700513 }
514 }
tom3f2bbd72014-09-24 12:07:58 -0700515 }
sangho538108b2015-04-08 14:29:20 -0700516
517 @Override
samuele1fa7322015-07-14 16:35:16 +0800518 public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
sangho538108b2015-04-08 14:29:20 -0700519 checkNotNull(deviceId, DEVICE_ID_NULL);
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700520 checkNotNull(portStatistics, "Port statistics list cannot be null");
sangho538108b2015-04-08 14:29:20 -0700521 checkValidity();
522
samuele1fa7322015-07-14 16:35:16 +0800523 DeviceEvent event = store.updatePortStatistics(this.provider().id(),
524 deviceId, portStatistics);
sangho538108b2015-04-08 14:29:20 -0700525 post(event);
526 }
tomd3097b02014-08-26 10:40:29 -0700527 }
tom32f66842014-08-27 19:27:47 -0700528
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700529 // by default allowed, otherwise check flag
530 private boolean isAllowed(BasicDeviceConfig cfg) {
531 return (cfg == null || cfg.isAllowed());
532 }
533
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800534 // Applies the specified role to the device; ignores NONE
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700535
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800536 /**
537 * Apply role to device and send probe if MASTER.
538 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700539 * @param deviceId device identifier
540 * @param newRole new role to apply to the device
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800541 * @return true if the request was sent to provider
542 */
543 private boolean applyRoleAndProbe(DeviceId deviceId, MastershipRole newRole) {
544 if (newRole.equals(MastershipRole.NONE)) {
samuele1fa7322015-07-14 16:35:16 +0800545 //no-op
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700546 return true;
547 }
Ayaka Koshibe317245a2014-10-29 00:34:43 -0700548
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800549 DeviceProvider provider = getProvider(deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800550 if (provider == null) {
samuele1fa7322015-07-14 16:35:16 +0800551 log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800552 return false;
553 }
554 provider.roleChanged(deviceId, newRole);
555
556 if (newRole.equals(MastershipRole.MASTER)) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800557 log.debug("sent TriggerProbe({})", deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800558 // only trigger event when request was sent to provider
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800559 provider.triggerProbe(deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800560 }
561 return true;
562 }
563
564 /**
565 * Reaasert role for specified device connected to this node.
566 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700567 * @param did device identifier
568 * @param nextRole role to apply. If NONE is specified,
569 * it will ask mastership service for a role and apply it.
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800570 */
samuele1fa7322015-07-14 16:35:16 +0800571 private void reassertRole(final DeviceId did,
572 final MastershipRole nextRole) {
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800573
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800574 MastershipRole myNextRole = nextRole;
575 if (myNextRole == NONE) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800576 try {
577 mastershipService.requestRoleFor(did).get();
578 MastershipTerm term = termService.getMastershipTerm(did);
579 if (term != null && localNodeId.equals(term.master())) {
580 myNextRole = MASTER;
581 } else {
582 myNextRole = STANDBY;
583 }
584 } catch (InterruptedException e) {
585 Thread.currentThread().interrupt();
586 log.error("Interrupted waiting for Mastership", e);
587 } catch (ExecutionException e) {
588 log.error("Encountered an error waiting for Mastership", e);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800589 }
590 }
591
592 switch (myNextRole) {
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700593 case MASTER:
594 final Device device = getDevice(did);
595 if ((device != null) && !isAvailable(did)) {
596 //flag the device as online. Is there a better way to do this?
597 DefaultDeviceDescription deviceDescription
598 = new DefaultDeviceDescription(did.uri(),
599 device.type(),
600 device.manufacturer(),
601 device.hwVersion(),
602 device.swVersion(),
603 device.serialNumber(),
604 device.chassisId());
605 DeviceEvent devEvent =
606 store.createOrUpdateDevice(device.providerId(), did,
607 deviceDescription);
608 post(devEvent);
609 }
610 // TODO: should apply role only if there is mismatch
611 log.debug("Applying role {} to {}", myNextRole, did);
612 if (!applyRoleAndProbe(did, MASTER)) {
613 log.warn("Unsuccessful applying role {} to {}", myNextRole, did);
614 // immediately failed to apply role
615 mastershipService.relinquishMastership(did);
616 // FIXME disconnect?
617 }
618 break;
619 case STANDBY:
620 log.debug("Applying role {} to {}", myNextRole, did);
621 if (!applyRoleAndProbe(did, STANDBY)) {
622 log.warn("Unsuccessful applying role {} to {}", myNextRole, did);
623 // immediately failed to apply role
624 mastershipService.relinquishMastership(did);
625 // FIXME disconnect?
626 }
627 break;
628 case NONE:
629 default:
630 // should never reach here
631 log.error("You didn't see anything. I did not exist.");
632 break;
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800633 }
634 }
635
Madan Jampani328371d2015-05-29 14:06:27 -0700636 private void handleMastershipEvent(MastershipEvent event) {
637 if (event.type() != MastershipEvent.Type.MASTER_CHANGED) {
638 // Don't care if backup list changed.
639 return;
640 }
641
642 final DeviceId did = event.subject();
643
644 // myRole suggested by MastershipService
645 MastershipRole myNextRole;
646 if (localNodeId.equals(event.roleInfo().master())) {
647 // confirm latest info
648 MastershipTerm term = termService.getMastershipTerm(did);
samuele1fa7322015-07-14 16:35:16 +0800649 final boolean iHaveControl = term != null && localNodeId.equals(term.master());
Madan Jampani328371d2015-05-29 14:06:27 -0700650 if (iHaveControl) {
Madan Jampani328371d2015-05-29 14:06:27 -0700651 myNextRole = MASTER;
652 } else {
653 myNextRole = STANDBY;
654 }
655 } else if (event.roleInfo().backups().contains(localNodeId)) {
656 myNextRole = STANDBY;
657 } else {
658 myNextRole = NONE;
659 }
660
Madan Jampani328371d2015-05-29 14:06:27 -0700661 final boolean isReachable = isReachable(did);
662 if (!isReachable) {
663 // device is not connected to this node
664 if (myNextRole != NONE) {
665 log.warn("Node was instructed to be {} role for {}, "
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700666 + "but this node cannot reach the device. "
667 + "Relinquishing role. ",
samuele1fa7322015-07-14 16:35:16 +0800668 myNextRole, did);
Madan Jampani328371d2015-05-29 14:06:27 -0700669 mastershipService.relinquishMastership(did);
670 }
671 return;
672 }
673
674 // device is connected to this node:
675 if (store.getDevice(did) != null) {
676 reassertRole(did, myNextRole);
677 } else {
678 log.debug("Device is not yet/no longer in the store: {}", did);
679 }
680 }
681
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800682 // Intercepts mastership events
683 private class InternalMastershipListener implements MastershipListener {
684
tomb41d1ac2014-09-24 01:51:24 -0700685 @Override
686 public void event(MastershipEvent event) {
Madan Jampani328371d2015-05-29 14:06:27 -0700687 backgroundService.submit(() -> {
688 try {
689 handleMastershipEvent(event);
690 } catch (Exception e) {
691 log.warn("Failed to handle {}", event, e);
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700692 }
Madan Jampani328371d2015-05-29 14:06:27 -0700693 });
Ayaka Koshibe317245a2014-10-29 00:34:43 -0700694 }
tomb41d1ac2014-09-24 01:51:24 -0700695 }
tomf80c9722014-09-24 14:49:18 -0700696
697 // Store delegate to re-post events emitted from the store.
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700698 private class InternalStoreDelegate implements DeviceStoreDelegate {
tomf80c9722014-09-24 14:49:18 -0700699 @Override
700 public void notify(DeviceEvent event) {
701 post(event);
702 }
703 }
samuel738dfaf2015-07-11 11:08:57 +0800704
705 @Override
706 public Iterable<Device> getDevices(Type type) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900707 checkPermission(DEVICE_READ);
samuel738dfaf2015-07-11 11:08:57 +0800708 Set<Device> results = new HashSet<>();
709 Iterable<Device> devices = store.getDevices();
710 if (devices != null) {
711 devices.forEach(d -> {
712 if (type.equals(d.type())) {
713 results.add(d);
714 }
715 });
716 }
717 return results;
718 }
719
720 @Override
721 public Iterable<Device> getAvailableDevices(Type type) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900722 checkPermission(DEVICE_READ);
samuel738dfaf2015-07-11 11:08:57 +0800723 Set<Device> results = new HashSet<>();
724 Iterable<Device> availableDevices = store.getAvailableDevices();
725 if (availableDevices != null) {
726 availableDevices.forEach(d -> {
727 if (type.equals(d.type())) {
728 results.add(d);
729 }
730 });
731 }
732 return results;
733 }
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700734
735 private class InternalNetworkConfigListener implements NetworkConfigListener {
736 @Override
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700737 public boolean isRelevant(NetworkConfigEvent event) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700738 return (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
739 || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)
740 && (event.configClass().equals(BasicDeviceConfig.class)
741 || event.configClass().equals(OpticalPortConfig.class));
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700742 }
743
744 @Override
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700745 public void event(NetworkConfigEvent event) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700746 DeviceEvent de = null;
747 if (event.configClass().equals(BasicDeviceConfig.class)) {
Thomas Vachuska138de8b2016-01-11 21:31:38 -0800748 log.debug("Detected device network config event {}", event.type());
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700749 DeviceId did = (DeviceId) event.subject();
750 BasicDeviceConfig cfg = networkConfigService.getConfig(did, BasicDeviceConfig.class);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700751
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700752 if (!isAllowed(cfg)) {
753 kickOutBadDevice(did);
754 } else {
755 Device dev = getDevice(did);
756 DeviceDescription desc = (dev == null) ? null : BasicDeviceOperator.descriptionOf(dev);
757 desc = BasicDeviceOperator.combine(cfg, desc);
Thomas Vachuska1627dc82015-11-13 12:22:14 -0800758 if (desc != null && getProvider(did) != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700759 de = store.createOrUpdateDevice(getProvider(did).id(), did, desc);
760 }
761 }
762 }
763 if (event.configClass().equals(OpticalPortConfig.class)) {
764 ConnectPoint cpt = (ConnectPoint) event.subject();
765 DeviceId did = cpt.deviceId();
766 Port dpt = getPort(did, cpt.port());
767
768 if (dpt != null) {
769 OpticalPortConfig opc = networkConfigService.getConfig(cpt, OpticalPortConfig.class);
770 PortDescription desc = OpticalPortOperator.descriptionOf(dpt);
771 desc = OpticalPortOperator.combine(opc, desc);
Thomas Vachuska1627dc82015-11-13 12:22:14 -0800772 if (desc != null && getProvider(did) != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700773 de = store.updatePortStatus(getProvider(did).id(), did, desc);
774 }
775 }
776 }
777
778 if (de != null) {
779 post(de);
780 }
781 }
782
783 // checks if the specified device is allowed by the BasicDeviceConfig
784 // and if not, removes it
785 private void kickOutBadDevice(DeviceId deviceId) {
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700786 Device badDevice = getDevice(deviceId);
787 if (badDevice != null) {
788 removeDevice(deviceId);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700789 }
790 }
791 }
tomd3097b02014-08-26 10:40:29 -0700792}