blob: fa319190a9f207ec8ccfacdb747d8a544b7b6227 [file] [log] [blame]
Sho SHIMIZUd97a9502015-08-18 10:02:30 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Sho SHIMIZUd97a9502015-08-18 10:02:30 -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 */
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080016package org.onosproject.net.resource.impl;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070017
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -080018import com.google.common.collect.ImmutableSet;
Sho SHIMIZU72f81b12016-02-09 09:26:17 -080019import com.google.common.collect.Lists;
HIGUCHI Yuta6057d082016-04-29 11:57:23 -070020
Sho SHIMIZU44f37612015-11-25 16:23:22 -080021import org.onlab.packet.MplsLabel;
22import org.onlab.packet.VlanId;
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080023import org.onlab.util.Bandwidth;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080024import org.onlab.util.ItemNotFoundException;
Sho SHIMIZU76b046e2016-02-24 11:45:44 -080025import org.onosproject.mastership.MastershipService;
HIGUCHI Yuta6057d082016-04-29 11:57:23 -070026import org.onosproject.net.ChannelSpacing;
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080027import org.onosproject.net.ConnectPoint;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070028import org.onosproject.net.Device;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080029import org.onosproject.net.DeviceId;
HIGUCHI Yuta6057d082016-04-29 11:57:23 -070030import org.onosproject.net.GridType;
HIGUCHI Yutad39e3762015-12-04 09:43:16 -080031import org.onosproject.net.OchSignal;
Toru Furusawac23f5832015-12-04 11:39:18 -080032import org.onosproject.net.Port;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080033import org.onosproject.net.PortNumber;
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +020034import org.onosproject.net.TributarySlot;
HIGUCHI Yutad39e3762015-12-04 09:43:16 -080035import org.onosproject.net.behaviour.LambdaQuery;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080036import org.onosproject.net.behaviour.MplsQuery;
Toru Furusawac23f5832015-12-04 11:39:18 -080037import org.onosproject.net.behaviour.TributarySlotQuery;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080038import org.onosproject.net.behaviour.VlanQuery;
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080039import org.onosproject.net.config.NetworkConfigService;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070040import org.onosproject.net.device.DeviceEvent;
41import org.onosproject.net.device.DeviceListener;
HIGUCHI Yuta11d16092015-12-04 23:35:43 -080042import org.onosproject.net.device.DeviceService;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080043import org.onosproject.net.driver.DriverHandler;
44import org.onosproject.net.driver.DriverService;
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080045import org.onosproject.net.resource.DiscreteResource;
46import org.onosproject.net.resource.ResourceAdminService;
Sho SHIMIZUb6c63a32016-05-26 12:07:19 -070047import org.onosproject.net.config.basics.BandwidthCapacity;
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080048import org.onosproject.net.resource.Resource;
Sho SHIMIZUa6b4dc72016-03-11 19:00:20 -080049import org.onosproject.net.resource.ResourceQueryService;
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080050import org.onosproject.net.resource.Resources;
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +020051import org.slf4j.Logger;
52import org.slf4j.LoggerFactory;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070053
HIGUCHI Yutad39e3762015-12-04 09:43:16 -080054import java.util.Collections;
Naoki Shiotabe394c82016-02-03 16:44:29 -080055import java.util.LinkedList;
56import java.util.List;
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080057import java.util.Optional;
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -080058import java.util.Set;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070059import java.util.concurrent.ExecutorService;
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +020060import java.util.stream.Collectors;
HIGUCHI Yuta6057d082016-04-29 11:57:23 -070061import java.util.stream.Stream;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070062
63import static com.google.common.base.Preconditions.checkNotNull;
64
65/**
66 * An implementation of DeviceListener registering devices as resources.
67 */
68final class ResourceDeviceListener implements DeviceListener {
69
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +020070 private static final Logger log = LoggerFactory.getLogger(ResourceDeviceListener.class);
71
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070072 private final ResourceAdminService adminService;
Sho SHIMIZUa6b4dc72016-03-11 19:00:20 -080073 private final ResourceQueryService resourceService;
HIGUCHI Yuta11d16092015-12-04 23:35:43 -080074 private final DeviceService deviceService;
Sho SHIMIZU76b046e2016-02-24 11:45:44 -080075 private final MastershipService mastershipService;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080076 private final DriverService driverService;
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080077 private final NetworkConfigService netcfgService;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070078 private final ExecutorService executor;
79
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080080
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070081 /**
82 * Creates an instance with the specified ResourceAdminService and ExecutorService.
83 *
84 * @param adminService instance invoked to register resources
Sho SHIMIZUa6b4dc72016-03-11 19:00:20 -080085 * @param resourceService {@link ResourceQueryService} to be used
Jian Lidfba7392016-01-22 16:46:58 -080086 * @param deviceService {@link DeviceService} to be used
Sho SHIMIZU76b046e2016-02-24 11:45:44 -080087 * @param mastershipService {@link MastershipService} to be used
Jian Lidfba7392016-01-22 16:46:58 -080088 * @param driverService {@link DriverService} to be used
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080089 * @param netcfgService {@link NetworkConfigService} to be used.
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070090 * @param executor executor used for processing resource registration
91 */
Sho SHIMIZUa6b4dc72016-03-11 19:00:20 -080092 ResourceDeviceListener(ResourceAdminService adminService, ResourceQueryService resourceService,
Sho SHIMIZU76b046e2016-02-24 11:45:44 -080093 DeviceService deviceService, MastershipService mastershipService,
94 DriverService driverService, NetworkConfigService netcfgService,
95 ExecutorService executor) {
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070096 this.adminService = checkNotNull(adminService);
Naoki Shiotabe394c82016-02-03 16:44:29 -080097 this.resourceService = checkNotNull(resourceService);
HIGUCHI Yuta11d16092015-12-04 23:35:43 -080098 this.deviceService = checkNotNull(deviceService);
Sho SHIMIZU76b046e2016-02-24 11:45:44 -080099 this.mastershipService = checkNotNull(mastershipService);
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800100 this.driverService = checkNotNull(driverService);
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -0800101 this.netcfgService = checkNotNull(netcfgService);
Sho SHIMIZUd97a9502015-08-18 10:02:30 -0700102 this.executor = checkNotNull(executor);
103 }
104
105 @Override
106 public void event(DeviceEvent event) {
107 Device device = event.subject();
Sho SHIMIZU76b046e2016-02-24 11:45:44 -0800108 // registration happens only when the caller is the master of the device
109 if (!mastershipService.isLocalMaster(device.id())) {
110 return;
111 }
112
Sho SHIMIZUd97a9502015-08-18 10:02:30 -0700113 switch (event.type()) {
114 case DEVICE_ADDED:
115 registerDeviceResource(device);
116 break;
Sho SHIMIZUe60a5ab2015-08-20 11:51:49 -0700117 case DEVICE_REMOVED:
118 unregisterDeviceResource(device);
119 break;
HIGUCHI Yuta11d16092015-12-04 23:35:43 -0800120 case DEVICE_AVAILABILITY_CHANGED:
121 if (deviceService.isAvailable(device.id())) {
122 registerDeviceResource(device);
123 // TODO: do we need to walk the ports?
124 } else {
125 unregisterDeviceResource(device);
126 }
127 break;
Sho SHIMIZU08fdbd22015-08-19 16:59:35 -0700128 case PORT_ADDED:
HIGUCHI Yuta11d16092015-12-04 23:35:43 -0800129 case PORT_UPDATED:
130 if (event.port().isEnabled()) {
131 registerPortResource(device, event.port());
132 } else {
133 unregisterPortResource(device, event.port());
134 }
Sho SHIMIZUc2ddedd2015-08-20 11:54:29 -0700135 break;
Sho SHIMIZUe2292842015-08-20 11:59:23 -0700136 case PORT_REMOVED:
137 unregisterPortResource(device, event.port());
138 break;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -0700139 default:
140 break;
141 }
142 }
143
144 private void registerDeviceResource(Device device) {
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800145 executor.execute(() -> {
146 boolean success = adminService.register(Resources.discrete(device.id()).resource());
147 if (!success) {
148 log.warn("Failed to register Device: {}", device.id());
149 }
150 });
Sho SHIMIZUd97a9502015-08-18 10:02:30 -0700151 }
Sho SHIMIZU08fdbd22015-08-19 16:59:35 -0700152
Sho SHIMIZUe60a5ab2015-08-20 11:51:49 -0700153 private void unregisterDeviceResource(Device device) {
HIGUCHI Yuta060da9a2016-03-11 19:16:35 -0800154 executor.execute(() -> {
Sho SHIMIZU2fbc33c2016-02-09 14:03:23 -0800155 DiscreteResource devResource = Resources.discrete(device.id()).resource();
Naoki Shiotabe394c82016-02-03 16:44:29 -0800156 List<Resource> allResources = getDescendantResources(devResource);
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800157 adminService.unregister(Lists.transform(allResources, Resource::id));
Naoki Shiotabe394c82016-02-03 16:44:29 -0800158 });
Sho SHIMIZUe60a5ab2015-08-20 11:51:49 -0700159 }
160
Sho SHIMIZU08fdbd22015-08-19 16:59:35 -0700161 private void registerPortResource(Device device, Port port) {
Sho SHIMIZU460b9722016-01-28 10:48:26 -0800162 Resource portPath = Resources.discrete(device.id(), port.number()).resource();
HIGUCHI Yuta060da9a2016-03-11 19:16:35 -0800163 executor.execute(() -> {
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800164 adminService.register(portPath);
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +0200165
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -0800166 queryBandwidth(device.id(), port.number())
167 .map(bw -> portPath.child(Bandwidth.class, bw.bps()))
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800168 .map(adminService::register)
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -0800169 .ifPresent(success -> {
170 if (!success) {
Ray Milkey0ae473d2016-04-04 10:56:47 -0700171 log.warn("Failed to register Bandwidth for {}", portPath.id());
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -0800172 }
173 });
174
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800175 // for VLAN IDs
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800176 Set<VlanId> vlans = queryVlanIds(device.id(), port.number());
177 if (!vlans.isEmpty()) {
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800178 boolean success = adminService.register(vlans.stream()
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800179 .map(portPath::child)
180 .collect(Collectors.toList()));
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800181 if (!success) {
182 log.warn("Failed to register VLAN IDs for {}", portPath.id());
183 }
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800184 }
185
186 // for MPLS labels
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800187 Set<MplsLabel> mplsLabels = queryMplsLabels(device.id(), port.number());
188 if (!mplsLabels.isEmpty()) {
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800189 boolean success = adminService.register(mplsLabels.stream()
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800190 .map(portPath::child)
191 .collect(Collectors.toList()));
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800192 if (!success) {
193 log.warn("Failed to register MPLS Labels for {}", portPath.id());
194 }
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800195 }
196
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800197 // for Lambdas
Marc De Leenheer622861d2015-12-15 22:52:52 -0800198 Set<OchSignal> lambdas = queryLambdas(device.id(), port.number());
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800199 if (!lambdas.isEmpty()) {
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800200 boolean success = adminService.register(lambdas.stream()
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800201 .map(portPath::child)
202 .collect(Collectors.toList()));
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800203 if (!success) {
204 log.warn("Failed to register lambdas for {}", portPath.id());
205 }
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800206 }
207
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800208 // for Tributary slots
Toru Furusawac23f5832015-12-04 11:39:18 -0800209 Set<TributarySlot> tSlots = queryTributarySlots(device.id(), port.number());
210 if (!tSlots.isEmpty()) {
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800211 boolean success = adminService.register(tSlots.stream()
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800212 .map(portPath::child)
213 .collect(Collectors.toList()));
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800214 if (!success) {
215 log.warn("Failed to register tributary slots for {}", portPath.id());
216 }
Sho SHIMIZU2c7cecf2015-11-11 14:16:14 -0800217 }
218 });
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +0200219 }
220
Sho SHIMIZUe2292842015-08-20 11:59:23 -0700221 private void unregisterPortResource(Device device, Port port) {
HIGUCHI Yuta060da9a2016-03-11 19:16:35 -0800222 executor.execute(() -> {
Sho SHIMIZU2fbc33c2016-02-09 14:03:23 -0800223 DiscreteResource portResource = Resources.discrete(device.id(), port.number()).resource();
Naoki Shiotabe394c82016-02-03 16:44:29 -0800224 List<Resource> allResources = getDescendantResources(portResource);
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800225 adminService.unregister(Lists.transform(allResources, Resource::id));
Naoki Shiotabe394c82016-02-03 16:44:29 -0800226 });
227 }
228
229 // Returns list of all descendant resources of given resource, including itself.
Sho SHIMIZU2fbc33c2016-02-09 14:03:23 -0800230 private List<Resource> getDescendantResources(DiscreteResource parent) {
Naoki Shiotabe394c82016-02-03 16:44:29 -0800231 LinkedList<Resource> allResources = new LinkedList<>();
232 allResources.add(parent);
233
Sho SHIMIZU2fbc33c2016-02-09 14:03:23 -0800234 Set<Resource> nextResources = resourceService.getRegisteredResources(parent.id());
Naoki Shiotabe394c82016-02-03 16:44:29 -0800235 while (!nextResources.isEmpty()) {
236 Set<Resource> currentResources = nextResources;
237 // resource list should be ordered from leaf to root
238 allResources.addAll(0, currentResources);
239
240 nextResources = currentResources.stream()
Sho SHIMIZU2fbc33c2016-02-09 14:03:23 -0800241 .filter(r -> r instanceof DiscreteResource)
242 .map(r -> (DiscreteResource) r)
243 .flatMap(r -> resourceService.getRegisteredResources(r.id()).stream())
Naoki Shiotabe394c82016-02-03 16:44:29 -0800244 .collect(Collectors.toSet());
245 }
246
247 return allResources;
Sho SHIMIZUe2292842015-08-20 11:59:23 -0700248 }
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +0200249
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -0800250 /**
251 * Query bandwidth capacity on a port.
252 *
253 * @param did {@link DeviceId}
254 * @param number {@link PortNumber}
255 * @return bandwidth capacity
256 */
257 private Optional<Bandwidth> queryBandwidth(DeviceId did, PortNumber number) {
258 // Check and use netcfg first.
259 ConnectPoint cp = new ConnectPoint(did, number);
260 BandwidthCapacity config = netcfgService.getConfig(cp, BandwidthCapacity.class);
261 if (config != null) {
262 log.trace("Registering configured bandwidth {} for {}/{}", config.capacity(), did, number);
263 return Optional.of(config.capacity());
264 }
265
266 // populate bandwidth value, assuming portSpeed == bandwidth
267 Port port = deviceService.getPort(did, number);
268 if (port != null) {
269 return Optional.of(Bandwidth.mbps(port.portSpeed()));
270 }
271 return Optional.empty();
272 }
273
Marc De Leenheer622861d2015-12-15 22:52:52 -0800274 private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) {
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800275 try {
276 DriverHandler handler = driverService.createHandler(did);
HIGUCHI Yuta82b3c112016-01-07 22:22:26 -0800277 if (handler == null || !handler.hasBehaviour(LambdaQuery.class)) {
Marc De Leenheer622861d2015-12-15 22:52:52 -0800278 return Collections.emptySet();
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800279 }
280 LambdaQuery query = handler.behaviour(LambdaQuery.class);
HIGUCHI Yuta11d16092015-12-04 23:35:43 -0800281 if (query != null) {
Marc De Leenheer2c305302015-12-07 21:37:44 -0800282 return query.queryLambdas(port).stream()
HIGUCHI Yuta6057d082016-04-29 11:57:23 -0700283 .flatMap(ResourceDeviceListener::toResourceGrid)
Marc De Leenheer622861d2015-12-15 22:52:52 -0800284 .collect(Collectors.toSet());
HIGUCHI Yuta11d16092015-12-04 23:35:43 -0800285 } else {
Marc De Leenheer622861d2015-12-15 22:52:52 -0800286 return Collections.emptySet();
HIGUCHI Yuta11d16092015-12-04 23:35:43 -0800287 }
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800288 } catch (ItemNotFoundException e) {
Marc De Leenheer622861d2015-12-15 22:52:52 -0800289 return Collections.emptySet();
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800290 }
291 }
292
HIGUCHI Yuta6057d082016-04-29 11:57:23 -0700293 /**
294 * Convert {@link OchSignal} into gridtype used to track Resource.
295 *
296 * @param ochSignal {@link OchSignal}
297 * @return {@code ochSignal} mapped to Stream of flex grid slots with 6.25 GHz spacing
298 * and 12.5 GHz slot width.
299 */
300 private static Stream<OchSignal> toResourceGrid(OchSignal ochSignal) {
301 if (ochSignal.gridType() != GridType.FLEX) {
302 return OchSignal.toFlexGrid(ochSignal).stream();
303 }
304 if (ochSignal.gridType() == GridType.FLEX &&
305 ochSignal.channelSpacing() == ChannelSpacing.CHL_6P25GHZ &&
306 ochSignal.slotGranularity() == 1) {
307 // input was already flex grid slots with 6.25 GHz spacing and 12.5 GHz slot width.
308 return Stream.of(ochSignal);
309 }
310 // FIXME handle FLEX but not 6.25 GHz spacing or 12.5 GHz slot width case.
311 log.error("Converting {} to resource tracking grid not supported yet.", ochSignal);
312 return Stream.<OchSignal>builder().build();
313 }
314
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800315 private Set<VlanId> queryVlanIds(DeviceId device, PortNumber port) {
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800316 try {
317 DriverHandler handler = driverService.createHandler(device);
HIGUCHI Yuta82b3c112016-01-07 22:22:26 -0800318 if (handler == null || !handler.hasBehaviour(VlanQuery.class)) {
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800319 return ImmutableSet.of();
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800320 }
321
322 VlanQuery query = handler.behaviour(VlanQuery.class);
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800323 if (query == null) {
324 return ImmutableSet.of();
325 }
326 return query.queryVlanIds(port);
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800327 } catch (ItemNotFoundException e) {
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800328 return ImmutableSet.of();
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800329 }
330 }
331
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800332 private Set<MplsLabel> queryMplsLabels(DeviceId device, PortNumber port) {
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800333 try {
334 DriverHandler handler = driverService.createHandler(device);
HIGUCHI Yuta82b3c112016-01-07 22:22:26 -0800335 if (handler == null || !handler.hasBehaviour(MplsQuery.class)) {
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800336 return ImmutableSet.of();
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800337 }
338
339 MplsQuery query = handler.behaviour(MplsQuery.class);
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800340 if (query == null) {
341 return ImmutableSet.of();
342 }
343 return query.queryMplsLabels(port);
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800344 } catch (ItemNotFoundException e) {
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800345 return ImmutableSet.of();
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800346 }
347 }
348
Toru Furusawac23f5832015-12-04 11:39:18 -0800349 private Set<TributarySlot> queryTributarySlots(DeviceId device, PortNumber port) {
350 try {
Toru Furusawac23f5832015-12-04 11:39:18 -0800351 DriverHandler handler = driverService.createHandler(device);
HIGUCHI Yuta82b3c112016-01-07 22:22:26 -0800352 if (handler == null || !handler.hasBehaviour(TributarySlotQuery.class)) {
Toru Furusawac23f5832015-12-04 11:39:18 -0800353 return Collections.emptySet();
354 }
355 TributarySlotQuery query = handler.behaviour(TributarySlotQuery.class);
356 if (query != null) {
357 return query.queryTributarySlots(port);
358 } else {
359 return Collections.emptySet();
360 }
361 } catch (ItemNotFoundException e) {
362 return Collections.emptySet();
363 }
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +0200364 }
Sho SHIMIZUd97a9502015-08-18 10:02:30 -0700365}