blob: 5ef70fcea3ad60eccc54ecf3ee74f89f8f05e3c1 [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() {
HIGUCHI Yuta060da9a2016-03-11 19:16:35 -0800128 backgroundService = newSingleThreadScheduledExecutor(
129 groupedThreads("onos/device", "manager-background", log));
Madan Jampanide003d92015-05-11 17:14:20 -0700130 localNodeId = clusterService.getLocalNode().id();
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800131
tomf80c9722014-09-24 14:49:18 -0700132 store.setDelegate(delegate);
tom96dfcab2014-08-28 09:26:03 -0700133 eventDispatcher.addSink(DeviceEvent.class, listenerRegistry);
tomb41d1ac2014-09-24 01:51:24 -0700134 mastershipService.addListener(mastershipListener);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700135 networkConfigService.addListener(networkConfigListener);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800136
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700137 backgroundService.scheduleWithFixedDelay(() -> {
138 try {
139 mastershipCheck();
140 } catch (Exception e) {
141 log.error("Exception thrown during integrity check", e);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800142 }
143 }, 1, 1, TimeUnit.MINUTES);
tomd3097b02014-08-26 10:40:29 -0700144 log.info("Started");
145 }
146
147 @Deactivate
148 public void deactivate() {
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800149 backgroundService.shutdown();
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700150 networkConfigService.removeListener(networkConfigListener);
tomf80c9722014-09-24 14:49:18 -0700151 store.unsetDelegate(delegate);
tomb41d1ac2014-09-24 01:51:24 -0700152 mastershipService.removeListener(mastershipListener);
tom5f38b3a2014-08-27 23:50:54 -0700153 eventDispatcher.removeSink(DeviceEvent.class);
tomd3097b02014-08-26 10:40:29 -0700154 log.info("Stopped");
155 }
156
157 @Override
tomad2d2092014-09-06 23:24:20 -0700158 public int getDeviceCount() {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900159 checkPermission(DEVICE_READ);
tomad2d2092014-09-06 23:24:20 -0700160 return store.getDeviceCount();
tomd3097b02014-08-26 10:40:29 -0700161 }
162
163 @Override
tom32f66842014-08-27 19:27:47 -0700164 public Iterable<Device> getDevices() {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900165 checkPermission(DEVICE_READ);
tome5ec3fd2014-09-04 15:18:06 -0700166 return store.getDevices();
tomd3097b02014-08-26 10:40:29 -0700167 }
168
tom32f66842014-08-27 19:27:47 -0700169 @Override
Yuta HIGUCHIf1f2ac02014-11-26 14:02:22 -0800170 public Iterable<Device> getAvailableDevices() {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900171 checkPermission(DEVICE_READ);
Yuta HIGUCHIf1f2ac02014-11-26 14:02:22 -0800172 return store.getAvailableDevices();
173 }
174
175 @Override
tom32f66842014-08-27 19:27:47 -0700176 public Device getDevice(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900177 checkPermission(DEVICE_READ);
tom32f66842014-08-27 19:27:47 -0700178 checkNotNull(deviceId, DEVICE_ID_NULL);
tom132b58a2014-08-28 16:11:28 -0700179 return store.getDevice(deviceId);
tom32f66842014-08-27 19:27:47 -0700180 }
181
182 @Override
tomad2d2092014-09-06 23:24:20 -0700183 public MastershipRole getRole(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900184 checkPermission(DEVICE_READ);
tomad2d2092014-09-06 23:24:20 -0700185 checkNotNull(deviceId, DEVICE_ID_NULL);
tomb41d1ac2014-09-24 01:51:24 -0700186 return mastershipService.getLocalRole(deviceId);
tomad2d2092014-09-06 23:24:20 -0700187 }
188
189 @Override
tom32f66842014-08-27 19:27:47 -0700190 public List<Port> getPorts(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900191 checkPermission(DEVICE_READ);
tom32f66842014-08-27 19:27:47 -0700192 checkNotNull(deviceId, DEVICE_ID_NULL);
tom132b58a2014-08-28 16:11:28 -0700193 return store.getPorts(deviceId);
tom32f66842014-08-27 19:27:47 -0700194 }
195
196 @Override
sangho538108b2015-04-08 14:29:20 -0700197 public List<PortStatistics> getPortStatistics(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900198 checkPermission(DEVICE_READ);
sangho538108b2015-04-08 14:29:20 -0700199 checkNotNull(deviceId, DEVICE_ID_NULL);
200 return store.getPortStatistics(deviceId);
201 }
202
203 @Override
Dusan Pajin11ff4a82015-08-20 18:03:05 +0200204 public List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900205 checkPermission(DEVICE_READ);
Dusan Pajin11ff4a82015-08-20 18:03:05 +0200206 checkNotNull(deviceId, DEVICE_ID_NULL);
207 return store.getPortDeltaStatistics(deviceId);
208 }
209
210 @Override
tom32f66842014-08-27 19:27:47 -0700211 public Port getPort(DeviceId deviceId, PortNumber portNumber) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900212 checkPermission(DEVICE_READ);
tom32f66842014-08-27 19:27:47 -0700213 checkNotNull(deviceId, DEVICE_ID_NULL);
214 checkNotNull(portNumber, PORT_NUMBER_NULL);
tom132b58a2014-08-28 16:11:28 -0700215 return store.getPort(deviceId, portNumber);
tom32f66842014-08-27 19:27:47 -0700216 }
217
218 @Override
tomff7eb7c2014-09-08 12:49:03 -0700219 public boolean isAvailable(DeviceId deviceId) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900220 checkPermission(DEVICE_READ);
Changhoon Yoon541ef712015-05-23 17:18:34 +0900221
tomff7eb7c2014-09-08 12:49:03 -0700222 checkNotNull(deviceId, DEVICE_ID_NULL);
223 return store.isAvailable(deviceId);
224 }
225
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700226 // Check a device for control channel connectivity.
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700227 private boolean isReachable(DeviceId deviceId) {
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800228 if (deviceId == null) {
229 return false;
230 }
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700231 DeviceProvider provider = getProvider(deviceId);
232 if (provider != null) {
233 return provider.isReachable(deviceId);
234 } else {
Yuta HIGUCHI72669c42014-11-13 14:48:17 -0800235 log.debug("Provider not found for {}", deviceId);
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700236 return false;
237 }
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700238 }
239
tome5ec3fd2014-09-04 15:18:06 -0700240 @Override
241 public void removeDevice(DeviceId deviceId) {
242 checkNotNull(deviceId, DEVICE_ID_NULL);
243 DeviceEvent event = store.removeDevice(deviceId);
tom0efbb1d2014-09-09 11:54:28 -0700244 if (event != null) {
245 log.info("Device {} administratively removed", deviceId);
246 post(event);
247 }
tome5ec3fd2014-09-04 15:18:06 -0700248 }
249
tom7869ad92014-09-09 14:32:08 -0700250 @Override
samuele1fa7322015-07-14 16:35:16 +0800251 protected DeviceProviderService createProviderService(
252 DeviceProvider provider) {
tom7869ad92014-09-09 14:32:08 -0700253 return new InternalDeviceProviderService(provider);
254 }
255
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800256 /**
257 * Checks if all the reachable devices have a valid mastership role.
258 */
259 private void mastershipCheck() {
260 log.debug("Checking mastership");
261 for (Device device : getDevices()) {
262 final DeviceId deviceId = device.id();
Jonathan Hart2f669362015-02-11 16:19:20 -0800263 log.trace("Checking device {}", deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800264
265 if (!isReachable(deviceId)) {
266 continue;
267 }
268
269 if (mastershipService.getLocalRole(deviceId) != NONE) {
270 continue;
271 }
272
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700273 log.info("{} is reachable but did not have a valid role, reasserting", deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800274
275 // isReachable but was not MASTER or STANDBY, get a role and apply
276 // Note: NONE triggers request to MastershipService
277 reassertRole(deviceId, NONE);
278 }
279 }
280
tomd3097b02014-08-26 10:40:29 -0700281 // Personalized device provider service issued to the supplied provider.
tomdc361b62014-09-09 20:36:52 -0700282 private class InternalDeviceProviderService
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700283 extends AbstractProviderService<DeviceProvider>
284 implements DeviceProviderService {
tomd3097b02014-08-26 10:40:29 -0700285
tomcfde0622014-09-09 11:02:42 -0700286 InternalDeviceProviderService(DeviceProvider provider) {
tomd3097b02014-08-26 10:40:29 -0700287 super(provider);
288 }
289
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700290 /**
291 * Apply role in reaction to provider event.
292 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700293 * @param deviceId device identifier
294 * @param newRole new role to apply to the device
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700295 * @return true if the request was sent to provider
296 */
297 private boolean applyRole(DeviceId deviceId, MastershipRole newRole) {
298
299 if (newRole.equals(MastershipRole.NONE)) {
samuele1fa7322015-07-14 16:35:16 +0800300 //no-op
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700301 return true;
302 }
303
304 DeviceProvider provider = provider();
305 if (provider == null) {
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700306 log.warn("Provider for {} was not found. Cannot apply role {}",
307 deviceId, newRole);
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700308 return false;
309 }
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700310 provider.roleChanged(deviceId, newRole);
311 // not triggering probe when triggered by provider service event
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700312
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700313 return true;
314 }
315
tomd3097b02014-08-26 10:40:29 -0700316 @Override
alshabibb7b40632014-09-28 21:30:00 -0700317 public void deviceConnected(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700318 DeviceDescription deviceDescription) {
tom32f66842014-08-27 19:27:47 -0700319 checkNotNull(deviceId, DEVICE_ID_NULL);
320 checkNotNull(deviceDescription, DEVICE_DESCRIPTION_NULL);
tomeadbb462014-09-07 16:10:19 -0700321 checkValidity();
Yuta HIGUCHI24b2e2a2014-10-07 15:53:57 -0700322
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700323 BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class);
324 if (!isAllowed(cfg)) {
325 log.warn("Device {} is not allowed", deviceId);
326 return;
327 }
328 // Generate updated description and establish my Role
329 deviceDescription = BasicDeviceOperator.combine(cfg, deviceDescription);
Madan Jampani565a66a2015-07-25 17:01:13 -0700330 Futures.getUnchecked(mastershipService.requestRoleFor(deviceId)
331 .thenAccept(role -> {
332 log.info("Local role is {} for {}", role, deviceId);
333 applyRole(deviceId, role);
334 }));
HIGUCHI Yuta11530fb2015-05-27 13:10:20 -0700335
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700336 DeviceEvent event = store.createOrUpdateDevice(provider().id(), deviceId,
337 deviceDescription);
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700338 log.info("Device {} connected", deviceId);
tom80c0e5e2014-09-08 18:08:58 -0700339 if (event != null) {
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700340 log.trace("event: {} {}", event.type(), event);
tom568581d2014-09-08 20:13:36 -0700341 post(event);
tom80c0e5e2014-09-08 18:08:58 -0700342 }
tomd3097b02014-08-26 10:40:29 -0700343 }
344
345 @Override
346 public void deviceDisconnected(DeviceId deviceId) {
tom32f66842014-08-27 19:27:47 -0700347 checkNotNull(deviceId, DEVICE_ID_NULL);
tomeadbb462014-09-07 16:10:19 -0700348 checkValidity();
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700349
Yuta HIGUCHI2d3cd312014-10-31 11:38:04 -0700350 log.info("Device {} disconnected from this node", deviceId);
Ayaka Koshibed9f693e2014-09-29 18:04:54 -0700351
alshabibafc514a2014-12-01 14:44:05 -0800352 List<Port> ports = store.getPorts(deviceId);
Yafit Hadara9a73de2015-09-06 13:52:52 +0300353 final Device device = getDevice(deviceId);
354
355 List<PortDescription> descs = ports.stream().map(
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +0200356 port -> (!(Device.Type.ROADM.equals(device.type()) ||
357 (Device.Type.OTN.equals(device.type())))) ?
Yafit Hadara9a73de2015-09-06 13:52:52 +0300358 new DefaultPortDescription(port.number(), false,
359 port.type(), port.portSpeed()) :
360 OpticalPortOperator.descriptionOf(port, false)
361 ).collect(Collectors.toList());
362
alshabibafc514a2014-12-01 14:44:05 -0800363 store.updatePorts(this.provider().id(), deviceId, descs);
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700364 try {
Madan Jampani565a66a2015-07-25 17:01:13 -0700365 if (mastershipService.isLocalMaster(deviceId)) {
Thomas Vachuska5f429d62015-05-28 15:34:36 -0700366 post(store.markOffline(deviceId));
367 }
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700368 } catch (IllegalStateException e) {
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700369 log.warn("Failed to mark {} offline", deviceId);
370 // only the MASTER should be marking off-line in normal cases,
samuele1fa7322015-07-14 16:35:16 +0800371 // but if I was the last STANDBY connection, etc. and no one else
372 // was there to mark the device offline, this instance may need to
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700373 // temporarily request for Master Role and mark offline.
374
samuele1fa7322015-07-14 16:35:16 +0800375 //there are times when this node will correctly have mastership, BUT
376 //that isn't reflected in the ClockManager before the device disconnects.
377 //we want to let go of the device anyways, so make sure this happens.
Yuta HIGUCHI0722fb22014-10-19 01:16:33 -0700378
Yuta HIGUCHIeb24e9d2014-10-26 19:34:20 -0700379 // FIXME: Store semantics leaking out as IllegalStateException.
samuele1fa7322015-07-14 16:35:16 +0800380 // Consider revising store API to handle this scenario.
381 CompletableFuture<MastershipRole> roleFuture = mastershipService.requestRoleFor(deviceId);
Madan Jampanide003d92015-05-11 17:14:20 -0700382 roleFuture.whenComplete((role, error) -> {
samuele1fa7322015-07-14 16:35:16 +0800383 MastershipTerm term = termService.getMastershipTerm(deviceId);
384 // TODO: Move this type of check inside device clock manager, etc.
385 if (term != null && localNodeId.equals(term.master())) {
386 log.info("Retry marking {} offline", deviceId);
samuele1fa7322015-07-14 16:35:16 +0800387 post(store.markOffline(deviceId));
388 } else {
389 log.info("Failed again marking {} offline. {}", deviceId, role);
390 }
391 });
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700392 } finally {
Madan Jampanic6e574f2015-05-29 13:41:52 -0700393 try {
samuele1fa7322015-07-14 16:35:16 +0800394 //relinquish master role and ability to be backup.
Madan Jampanic6e574f2015-05-29 13:41:52 -0700395 mastershipService.relinquishMastership(deviceId).get();
396 } catch (InterruptedException e) {
samuele1fa7322015-07-14 16:35:16 +0800397 log.warn("Interrupted while reliquishing role for {}", deviceId);
Madan Jampanic6e574f2015-05-29 13:41:52 -0700398 Thread.currentThread().interrupt();
399 } catch (ExecutionException e) {
samuele1fa7322015-07-14 16:35:16 +0800400 log.error("Exception thrown while relinquishing role for {}", deviceId, e);
Madan Jampanic6e574f2015-05-29 13:41:52 -0700401 }
tom0efbb1d2014-09-09 11:54:28 -0700402 }
tomd3097b02014-08-26 10:40:29 -0700403 }
404
405 @Override
alshabibb7b40632014-09-28 21:30:00 -0700406 public void updatePorts(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700407 List<PortDescription> portDescriptions) {
tom32f66842014-08-27 19:27:47 -0700408 checkNotNull(deviceId, DEVICE_ID_NULL);
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700409 checkNotNull(portDescriptions, PORT_DESC_LIST_NULL);
tomeadbb462014-09-07 16:10:19 -0700410 checkValidity();
Madan Jampani565a66a2015-07-25 17:01:13 -0700411 if (!mastershipService.isLocalMaster(deviceId)) {
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700412 // Never been a master for this device
413 // any update will be ignored.
samuele1fa7322015-07-14 16:35:16 +0800414 log.trace("Ignoring {} port updates on standby node. {}", deviceId, portDescriptions);
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700415 return;
416 }
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700417 portDescriptions = portDescriptions.stream()
418 .map(e -> consolidate(deviceId, e))
419 .collect(Collectors.toList());
Yuta HIGUCHI5f6739c2014-10-01 14:04:01 -0700420 List<DeviceEvent> events = store.updatePorts(this.provider().id(),
samuele1fa7322015-07-14 16:35:16 +0800421 deviceId, portDescriptions);
Thomas Vachuska5923b9a2016-01-26 10:52:57 -0800422 if (events != null) {
423 for (DeviceEvent event : events) {
424 post(event);
425 }
tom32f66842014-08-27 19:27:47 -0700426 }
tomd3097b02014-08-26 10:40:29 -0700427 }
428
429 @Override
alshabibb7b40632014-09-28 21:30:00 -0700430 public void portStatusChanged(DeviceId deviceId,
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700431 PortDescription portDescription) {
tom32f66842014-08-27 19:27:47 -0700432 checkNotNull(deviceId, DEVICE_ID_NULL);
433 checkNotNull(portDescription, PORT_DESCRIPTION_NULL);
tomeadbb462014-09-07 16:10:19 -0700434 checkValidity();
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700435
Madan Jampani565a66a2015-07-25 17:01:13 -0700436 if (!mastershipService.isLocalMaster(deviceId)) {
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700437 // Never been a master for this device
438 // any update will be ignored.
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700439 log.trace("Ignoring {} port update on standby node. {}", deviceId,
440 portDescription);
Yuta HIGUCHI13c0b872014-10-30 18:09:22 -0700441 return;
442 }
Thomas Vachuskafa8aa2f2015-10-13 11:56:59 -0700443 Device device = nullIsNotFound(getDevice(deviceId), "Device not found");
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +0200444 if ((Device.Type.ROADM.equals(device.type())) ||
445 (Device.Type.OTN.equals(device.type()))) {
Yafit Hadara9a73de2015-09-06 13:52:52 +0300446 Port port = getPort(deviceId, portDescription.portNumber());
447 portDescription = OpticalPortOperator.descriptionOf(port, portDescription.isEnabled());
448 }
449
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700450 portDescription = consolidate(deviceId, portDescription);
samuele1fa7322015-07-14 16:35:16 +0800451 final DeviceEvent event = store.updatePortStatus(this.provider().id(),
452 deviceId, portDescription);
tomff7eb7c2014-09-08 12:49:03 -0700453 if (event != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700454 log.info("Device {} port {} status changed", deviceId, event.port().number());
tom0efbb1d2014-09-09 11:54:28 -0700455 post(event);
tomff7eb7c2014-09-08 12:49:03 -0700456 }
tomd3097b02014-08-26 10:40:29 -0700457 }
tom3f2bbd72014-09-24 12:07:58 -0700458
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700459 // merges the appropriate PortConfig with the description.
460 private PortDescription consolidate(DeviceId did, PortDescription desc) {
461 switch (desc.type()) {
462 case COPPER:
463 case VIRTUAL:
464 return desc;
465 default:
466 OpticalPortConfig opc = networkConfigService.getConfig(
467 new ConnectPoint(did, desc.portNumber()), OpticalPortConfig.class);
468 return OpticalPortOperator.combine(opc, desc);
469 }
470 }
471
tom3f2bbd72014-09-24 12:07:58 -0700472 @Override
samuele1fa7322015-07-14 16:35:16 +0800473 public void receivedRoleReply(DeviceId deviceId, MastershipRole requested,
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700474 MastershipRole response) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700475 // Several things can happen here:
476 // 1. request and response match
477 // 2. request and response don't match
478 // 3. MastershipRole and requested match (and 1 or 2 are true)
479 // 4. MastershipRole and requested don't match (and 1 or 2 are true)
480 //
481 // 2, 4, and 3 with case 2 are failure modes.
482
tom3f2bbd72014-09-24 12:07:58 -0700483 // FIXME: implement response to this notification
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700484
Madan Jampanif2af7712015-05-29 18:43:52 -0700485 log.debug("got reply to a role request for {}: asked for {}, and got {}",
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700486 deviceId, requested, response);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700487
488 if (requested == null && response == null) {
samuele1fa7322015-07-14 16:35:16 +0800489 // something was off with DeviceProvider, maybe check channel too?
Shashikanth VH387a1ca2016-02-09 20:35:21 +0530490 log.warn("Failed to assert role onto Device {}", deviceId);
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700491 mastershipService.relinquishMastership(deviceId);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700492 return;
Yuta HIGUCHIcf603902014-10-07 23:04:32 -0700493 }
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700494
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700495 if (Objects.equals(requested, response)) {
samuele1fa7322015-07-14 16:35:16 +0800496 if (Objects.equals(requested, mastershipService.getLocalRole(deviceId))) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700497 return;
498 } else {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800499 log.warn("Role mismatch on {}. set to {}, but store demands {}",
500 deviceId, response, mastershipService.getLocalRole(deviceId));
501 // roleManager got the device to comply, but doesn't agree with
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700502 // the store; use the store's view, then try to reassert.
HIGUCHI Yuta060da9a2016-03-11 19:16:35 -0800503 backgroundService.execute(() -> reassertRole(deviceId, mastershipService.getLocalRole(deviceId)));
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800504 return;
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700505 }
506 } else {
507 // we didn't get back what we asked for. Reelect someone else.
samuele1fa7322015-07-14 16:35:16 +0800508 log.warn("Failed to assert role [{}] onto Device {}", response, deviceId);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700509 if (response == MastershipRole.MASTER) {
510 mastershipService.relinquishMastership(deviceId);
511 // TODO: Shouldn't we be triggering event?
samuele1fa7322015-07-14 16:35:16 +0800512 //final Device device = getDevice(deviceId);
513 //post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device));
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700514 }
515 }
tom3f2bbd72014-09-24 12:07:58 -0700516 }
sangho538108b2015-04-08 14:29:20 -0700517
518 @Override
samuele1fa7322015-07-14 16:35:16 +0800519 public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
sangho538108b2015-04-08 14:29:20 -0700520 checkNotNull(deviceId, DEVICE_ID_NULL);
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700521 checkNotNull(portStatistics, "Port statistics list cannot be null");
sangho538108b2015-04-08 14:29:20 -0700522 checkValidity();
523
samuele1fa7322015-07-14 16:35:16 +0800524 DeviceEvent event = store.updatePortStatistics(this.provider().id(),
525 deviceId, portStatistics);
sangho538108b2015-04-08 14:29:20 -0700526 post(event);
527 }
tomd3097b02014-08-26 10:40:29 -0700528 }
tom32f66842014-08-27 19:27:47 -0700529
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700530 // by default allowed, otherwise check flag
531 private boolean isAllowed(BasicDeviceConfig cfg) {
532 return (cfg == null || cfg.isAllowed());
533 }
534
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800535 // Applies the specified role to the device; ignores NONE
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700536
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800537 /**
538 * Apply role to device and send probe if MASTER.
539 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700540 * @param deviceId device identifier
541 * @param newRole new role to apply to the device
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800542 * @return true if the request was sent to provider
543 */
544 private boolean applyRoleAndProbe(DeviceId deviceId, MastershipRole newRole) {
545 if (newRole.equals(MastershipRole.NONE)) {
samuele1fa7322015-07-14 16:35:16 +0800546 //no-op
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700547 return true;
548 }
Ayaka Koshibe317245a2014-10-29 00:34:43 -0700549
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800550 DeviceProvider provider = getProvider(deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800551 if (provider == null) {
samuele1fa7322015-07-14 16:35:16 +0800552 log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800553 return false;
554 }
555 provider.roleChanged(deviceId, newRole);
556
557 if (newRole.equals(MastershipRole.MASTER)) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800558 log.debug("sent TriggerProbe({})", deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800559 // only trigger event when request was sent to provider
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800560 provider.triggerProbe(deviceId);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800561 }
562 return true;
563 }
564
565 /**
566 * Reaasert role for specified device connected to this node.
567 *
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700568 * @param did device identifier
569 * @param nextRole role to apply. If NONE is specified,
570 * it will ask mastership service for a role and apply it.
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800571 */
samuele1fa7322015-07-14 16:35:16 +0800572 private void reassertRole(final DeviceId did,
573 final MastershipRole nextRole) {
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800574
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800575 MastershipRole myNextRole = nextRole;
576 if (myNextRole == NONE) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800577 try {
578 mastershipService.requestRoleFor(did).get();
579 MastershipTerm term = termService.getMastershipTerm(did);
580 if (term != null && localNodeId.equals(term.master())) {
581 myNextRole = MASTER;
582 } else {
583 myNextRole = STANDBY;
584 }
585 } catch (InterruptedException e) {
586 Thread.currentThread().interrupt();
587 log.error("Interrupted waiting for Mastership", e);
588 } catch (ExecutionException e) {
589 log.error("Encountered an error waiting for Mastership", e);
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800590 }
591 }
592
593 switch (myNextRole) {
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700594 case MASTER:
595 final Device device = getDevice(did);
596 if ((device != null) && !isAvailable(did)) {
597 //flag the device as online. Is there a better way to do this?
598 DefaultDeviceDescription deviceDescription
599 = new DefaultDeviceDescription(did.uri(),
600 device.type(),
601 device.manufacturer(),
602 device.hwVersion(),
603 device.swVersion(),
604 device.serialNumber(),
605 device.chassisId());
606 DeviceEvent devEvent =
607 store.createOrUpdateDevice(device.providerId(), did,
608 deviceDescription);
609 post(devEvent);
610 }
611 // TODO: should apply role only if there is mismatch
612 log.debug("Applying role {} to {}", myNextRole, did);
613 if (!applyRoleAndProbe(did, MASTER)) {
614 log.warn("Unsuccessful applying role {} to {}", myNextRole, did);
615 // immediately failed to apply role
616 mastershipService.relinquishMastership(did);
617 // FIXME disconnect?
618 }
619 break;
620 case STANDBY:
621 log.debug("Applying role {} to {}", myNextRole, did);
622 if (!applyRoleAndProbe(did, STANDBY)) {
623 log.warn("Unsuccessful applying role {} to {}", myNextRole, did);
624 // immediately failed to apply role
625 mastershipService.relinquishMastership(did);
626 // FIXME disconnect?
627 }
628 break;
629 case NONE:
630 default:
631 // should never reach here
632 log.error("You didn't see anything. I did not exist.");
633 break;
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800634 }
635 }
636
Madan Jampani328371d2015-05-29 14:06:27 -0700637 private void handleMastershipEvent(MastershipEvent event) {
638 if (event.type() != MastershipEvent.Type.MASTER_CHANGED) {
639 // Don't care if backup list changed.
640 return;
641 }
642
643 final DeviceId did = event.subject();
644
645 // myRole suggested by MastershipService
646 MastershipRole myNextRole;
647 if (localNodeId.equals(event.roleInfo().master())) {
648 // confirm latest info
649 MastershipTerm term = termService.getMastershipTerm(did);
samuele1fa7322015-07-14 16:35:16 +0800650 final boolean iHaveControl = term != null && localNodeId.equals(term.master());
Madan Jampani328371d2015-05-29 14:06:27 -0700651 if (iHaveControl) {
Madan Jampani328371d2015-05-29 14:06:27 -0700652 myNextRole = MASTER;
653 } else {
654 myNextRole = STANDBY;
655 }
656 } else if (event.roleInfo().backups().contains(localNodeId)) {
657 myNextRole = STANDBY;
658 } else {
659 myNextRole = NONE;
660 }
661
Madan Jampani328371d2015-05-29 14:06:27 -0700662 final boolean isReachable = isReachable(did);
663 if (!isReachable) {
664 // device is not connected to this node
665 if (myNextRole != NONE) {
666 log.warn("Node was instructed to be {} role for {}, "
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700667 + "but this node cannot reach the device. "
668 + "Relinquishing role. ",
samuele1fa7322015-07-14 16:35:16 +0800669 myNextRole, did);
Madan Jampani328371d2015-05-29 14:06:27 -0700670 mastershipService.relinquishMastership(did);
671 }
672 return;
673 }
674
675 // device is connected to this node:
676 if (store.getDevice(did) != null) {
677 reassertRole(did, myNextRole);
678 } else {
679 log.debug("Device is not yet/no longer in the store: {}", did);
680 }
681 }
682
Yuta HIGUCHI63323fd2014-11-11 12:16:58 -0800683 // Intercepts mastership events
684 private class InternalMastershipListener implements MastershipListener {
685
tomb41d1ac2014-09-24 01:51:24 -0700686 @Override
687 public void event(MastershipEvent event) {
HIGUCHI Yuta060da9a2016-03-11 19:16:35 -0800688 backgroundService.execute(() -> {
Madan Jampani328371d2015-05-29 14:06:27 -0700689 try {
690 handleMastershipEvent(event);
691 } catch (Exception e) {
692 log.warn("Failed to handle {}", event, e);
Yuta HIGUCHId26354d2014-10-31 14:14:38 -0700693 }
Madan Jampani328371d2015-05-29 14:06:27 -0700694 });
Ayaka Koshibe317245a2014-10-29 00:34:43 -0700695 }
tomb41d1ac2014-09-24 01:51:24 -0700696 }
tomf80c9722014-09-24 14:49:18 -0700697
698 // Store delegate to re-post events emitted from the store.
Thomas Vachuskab17c41f2015-05-19 11:16:05 -0700699 private class InternalStoreDelegate implements DeviceStoreDelegate {
tomf80c9722014-09-24 14:49:18 -0700700 @Override
701 public void notify(DeviceEvent event) {
702 post(event);
703 }
704 }
samuel738dfaf2015-07-11 11:08:57 +0800705
706 @Override
707 public Iterable<Device> getDevices(Type type) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900708 checkPermission(DEVICE_READ);
samuel738dfaf2015-07-11 11:08:57 +0800709 Set<Device> results = new HashSet<>();
710 Iterable<Device> devices = store.getDevices();
711 if (devices != null) {
712 devices.forEach(d -> {
713 if (type.equals(d.type())) {
714 results.add(d);
715 }
716 });
717 }
718 return results;
719 }
720
721 @Override
722 public Iterable<Device> getAvailableDevices(Type type) {
Changhoon Yoonb856b812015-08-10 03:47:19 +0900723 checkPermission(DEVICE_READ);
samuel738dfaf2015-07-11 11:08:57 +0800724 Set<Device> results = new HashSet<>();
725 Iterable<Device> availableDevices = store.getAvailableDevices();
726 if (availableDevices != null) {
727 availableDevices.forEach(d -> {
728 if (type.equals(d.type())) {
729 results.add(d);
730 }
731 });
732 }
733 return results;
734 }
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700735
736 private class InternalNetworkConfigListener implements NetworkConfigListener {
737 @Override
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700738 public boolean isRelevant(NetworkConfigEvent event) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700739 return (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
740 || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)
741 && (event.configClass().equals(BasicDeviceConfig.class)
742 || event.configClass().equals(OpticalPortConfig.class));
Thomas Vachuska42e8cce2015-07-29 19:25:18 -0700743 }
744
745 @Override
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700746 public void event(NetworkConfigEvent event) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700747 DeviceEvent de = null;
748 if (event.configClass().equals(BasicDeviceConfig.class)) {
Thomas Vachuska138de8b2016-01-11 21:31:38 -0800749 log.debug("Detected device network config event {}", event.type());
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700750 DeviceId did = (DeviceId) event.subject();
751 BasicDeviceConfig cfg = networkConfigService.getConfig(did, BasicDeviceConfig.class);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700752
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700753 if (!isAllowed(cfg)) {
754 kickOutBadDevice(did);
755 } else {
756 Device dev = getDevice(did);
757 DeviceDescription desc = (dev == null) ? null : BasicDeviceOperator.descriptionOf(dev);
758 desc = BasicDeviceOperator.combine(cfg, desc);
Thomas Vachuska1627dc82015-11-13 12:22:14 -0800759 if (desc != null && getProvider(did) != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700760 de = store.createOrUpdateDevice(getProvider(did).id(), did, desc);
761 }
762 }
763 }
764 if (event.configClass().equals(OpticalPortConfig.class)) {
765 ConnectPoint cpt = (ConnectPoint) event.subject();
766 DeviceId did = cpt.deviceId();
767 Port dpt = getPort(did, cpt.port());
768
769 if (dpt != null) {
770 OpticalPortConfig opc = networkConfigService.getConfig(cpt, OpticalPortConfig.class);
771 PortDescription desc = OpticalPortOperator.descriptionOf(dpt);
772 desc = OpticalPortOperator.combine(opc, desc);
Thomas Vachuska1627dc82015-11-13 12:22:14 -0800773 if (desc != null && getProvider(did) != null) {
Ayaka Koshibed0ab3c02015-09-04 15:43:46 -0700774 de = store.updatePortStatus(getProvider(did).id(), did, desc);
775 }
776 }
777 }
778
779 if (de != null) {
780 post(de);
781 }
782 }
783
784 // checks if the specified device is allowed by the BasicDeviceConfig
785 // and if not, removes it
786 private void kickOutBadDevice(DeviceId deviceId) {
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700787 Device badDevice = getDevice(deviceId);
788 if (badDevice != null) {
789 removeDevice(deviceId);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700790 }
791 }
792 }
tomd3097b02014-08-26 10:40:29 -0700793}