Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 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 | */ |
| 16 | package org.onosproject.net.newresource.impl; |
| 17 | |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 19 | import org.onlab.packet.MplsLabel; |
| 20 | import org.onlab.packet.VlanId; |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 21 | import org.onlab.util.Bandwidth; |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 22 | import org.onlab.util.ItemNotFoundException; |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 23 | import org.onosproject.net.ConnectPoint; |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 24 | import org.onosproject.net.Device; |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 25 | import org.onosproject.net.DeviceId; |
HIGUCHI Yuta | d39e376 | 2015-12-04 09:43:16 -0800 | [diff] [blame] | 26 | import org.onosproject.net.OchSignal; |
Toru Furusawa | c23f583 | 2015-12-04 11:39:18 -0800 | [diff] [blame] | 27 | import org.onosproject.net.Port; |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 28 | import org.onosproject.net.PortNumber; |
Rimon Ashkenazy | e2410ff | 2015-11-10 14:11:08 +0200 | [diff] [blame] | 29 | import org.onosproject.net.TributarySlot; |
HIGUCHI Yuta | d39e376 | 2015-12-04 09:43:16 -0800 | [diff] [blame] | 30 | import org.onosproject.net.behaviour.LambdaQuery; |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 31 | import org.onosproject.net.behaviour.MplsQuery; |
Toru Furusawa | c23f583 | 2015-12-04 11:39:18 -0800 | [diff] [blame] | 32 | import org.onosproject.net.behaviour.TributarySlotQuery; |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 33 | import org.onosproject.net.behaviour.VlanQuery; |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 34 | import org.onosproject.net.config.NetworkConfigService; |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 35 | import org.onosproject.net.device.DeviceEvent; |
| 36 | import org.onosproject.net.device.DeviceListener; |
HIGUCHI Yuta | 11d1609 | 2015-12-04 23:35:43 -0800 | [diff] [blame] | 37 | import org.onosproject.net.device.DeviceService; |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 38 | import org.onosproject.net.driver.DriverHandler; |
| 39 | import org.onosproject.net.driver.DriverService; |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 40 | import org.onosproject.net.newresource.ResourceAdminService; |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 41 | import org.onosproject.net.newresource.BandwidthCapacity; |
Sho SHIMIZU | 8fa670a | 2016-01-14 11:17:18 -0800 | [diff] [blame] | 42 | import org.onosproject.net.newresource.Resource; |
Rimon Ashkenazy | e2410ff | 2015-11-10 14:11:08 +0200 | [diff] [blame] | 43 | import org.slf4j.Logger; |
| 44 | import org.slf4j.LoggerFactory; |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 45 | |
HIGUCHI Yuta | d39e376 | 2015-12-04 09:43:16 -0800 | [diff] [blame] | 46 | import java.util.Collections; |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 47 | import java.util.Optional; |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 48 | import java.util.Set; |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 49 | import java.util.concurrent.ExecutorService; |
Rimon Ashkenazy | e2410ff | 2015-11-10 14:11:08 +0200 | [diff] [blame] | 50 | import java.util.stream.Collectors; |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 51 | |
| 52 | import static com.google.common.base.Preconditions.checkNotNull; |
| 53 | |
| 54 | /** |
| 55 | * An implementation of DeviceListener registering devices as resources. |
| 56 | */ |
| 57 | final class ResourceDeviceListener implements DeviceListener { |
| 58 | |
Rimon Ashkenazy | e2410ff | 2015-11-10 14:11:08 +0200 | [diff] [blame] | 59 | private static final Logger log = LoggerFactory.getLogger(ResourceDeviceListener.class); |
| 60 | |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 61 | private final ResourceAdminService adminService; |
HIGUCHI Yuta | 11d1609 | 2015-12-04 23:35:43 -0800 | [diff] [blame] | 62 | private final DeviceService deviceService; |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 63 | private final DriverService driverService; |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 64 | private final NetworkConfigService netcfgService; |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 65 | private final ExecutorService executor; |
| 66 | |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 67 | |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Creates an instance with the specified ResourceAdminService and ExecutorService. |
| 70 | * |
| 71 | * @param adminService instance invoked to register resources |
Jian Li | dfba739 | 2016-01-22 16:46:58 -0800 | [diff] [blame] | 72 | * @param deviceService {@link DeviceService} to be used |
| 73 | * @param driverService {@link DriverService} to be used |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 74 | * @param netcfgService {@link NetworkConfigService} to be used. |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 75 | * @param executor executor used for processing resource registration |
| 76 | */ |
HIGUCHI Yuta | 11d1609 | 2015-12-04 23:35:43 -0800 | [diff] [blame] | 77 | ResourceDeviceListener(ResourceAdminService adminService, DeviceService deviceService, DriverService driverService, |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 78 | NetworkConfigService netcfgService, ExecutorService executor) { |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 79 | this.adminService = checkNotNull(adminService); |
HIGUCHI Yuta | 11d1609 | 2015-12-04 23:35:43 -0800 | [diff] [blame] | 80 | this.deviceService = checkNotNull(deviceService); |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 81 | this.driverService = checkNotNull(driverService); |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 82 | this.netcfgService = checkNotNull(netcfgService); |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 83 | this.executor = checkNotNull(executor); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void event(DeviceEvent event) { |
| 88 | Device device = event.subject(); |
| 89 | switch (event.type()) { |
| 90 | case DEVICE_ADDED: |
| 91 | registerDeviceResource(device); |
| 92 | break; |
Sho SHIMIZU | e60a5ab | 2015-08-20 11:51:49 -0700 | [diff] [blame] | 93 | case DEVICE_REMOVED: |
| 94 | unregisterDeviceResource(device); |
| 95 | break; |
HIGUCHI Yuta | 11d1609 | 2015-12-04 23:35:43 -0800 | [diff] [blame] | 96 | case DEVICE_AVAILABILITY_CHANGED: |
| 97 | if (deviceService.isAvailable(device.id())) { |
| 98 | registerDeviceResource(device); |
| 99 | // TODO: do we need to walk the ports? |
| 100 | } else { |
| 101 | unregisterDeviceResource(device); |
| 102 | } |
| 103 | break; |
Sho SHIMIZU | 08fdbd2 | 2015-08-19 16:59:35 -0700 | [diff] [blame] | 104 | case PORT_ADDED: |
HIGUCHI Yuta | 11d1609 | 2015-12-04 23:35:43 -0800 | [diff] [blame] | 105 | case PORT_UPDATED: |
| 106 | if (event.port().isEnabled()) { |
| 107 | registerPortResource(device, event.port()); |
| 108 | } else { |
| 109 | unregisterPortResource(device, event.port()); |
| 110 | } |
Sho SHIMIZU | c2ddedd | 2015-08-20 11:54:29 -0700 | [diff] [blame] | 111 | break; |
Sho SHIMIZU | e229284 | 2015-08-20 11:59:23 -0700 | [diff] [blame] | 112 | case PORT_REMOVED: |
| 113 | unregisterPortResource(device, event.port()); |
| 114 | break; |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 115 | default: |
| 116 | break; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | private void registerDeviceResource(Device device) { |
Sho SHIMIZU | f95b96e | 2016-01-25 19:35:15 -0800 | [diff] [blame^] | 121 | executor.submit(() -> adminService.registerResources(Resource.discrete(device.id()).resource())); |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 122 | } |
Sho SHIMIZU | 08fdbd2 | 2015-08-19 16:59:35 -0700 | [diff] [blame] | 123 | |
Sho SHIMIZU | e60a5ab | 2015-08-20 11:51:49 -0700 | [diff] [blame] | 124 | private void unregisterDeviceResource(Device device) { |
Sho SHIMIZU | f95b96e | 2016-01-25 19:35:15 -0800 | [diff] [blame^] | 125 | executor.submit(() -> adminService.unregisterResources(Resource.discrete(device.id()).resource())); |
Sho SHIMIZU | e60a5ab | 2015-08-20 11:51:49 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Sho SHIMIZU | 08fdbd2 | 2015-08-19 16:59:35 -0700 | [diff] [blame] | 128 | private void registerPortResource(Device device, Port port) { |
Sho SHIMIZU | f95b96e | 2016-01-25 19:35:15 -0800 | [diff] [blame^] | 129 | Resource portPath = Resource.discrete(device.id(), port.number()).resource(); |
Sho SHIMIZU | 2c7cecf | 2015-11-11 14:16:14 -0800 | [diff] [blame] | 130 | executor.submit(() -> { |
| 131 | adminService.registerResources(portPath); |
Rimon Ashkenazy | e2410ff | 2015-11-10 14:11:08 +0200 | [diff] [blame] | 132 | |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 133 | queryBandwidth(device.id(), port.number()) |
| 134 | .map(bw -> portPath.child(Bandwidth.class, bw.bps())) |
| 135 | .map(adminService::registerResources) |
| 136 | .ifPresent(success -> { |
| 137 | if (!success) { |
| 138 | log.error("Failed to register Bandwidth for {}", portPath.id()); |
| 139 | } |
| 140 | }); |
| 141 | |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 142 | // for VLAN IDs |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 143 | Set<VlanId> vlans = queryVlanIds(device.id(), port.number()); |
| 144 | if (!vlans.isEmpty()) { |
| 145 | adminService.registerResources(vlans.stream() |
| 146 | .map(portPath::child) |
| 147 | .collect(Collectors.toList())); |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | // for MPLS labels |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 151 | Set<MplsLabel> mplsLabels = queryMplsLabels(device.id(), port.number()); |
| 152 | if (!mplsLabels.isEmpty()) { |
| 153 | adminService.registerResources(mplsLabels.stream() |
| 154 | .map(portPath::child) |
| 155 | .collect(Collectors.toList())); |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 156 | } |
| 157 | |
HIGUCHI Yuta | d39e376 | 2015-12-04 09:43:16 -0800 | [diff] [blame] | 158 | // for Lambdas |
Marc De Leenheer | 622861d | 2015-12-15 22:52:52 -0800 | [diff] [blame] | 159 | Set<OchSignal> lambdas = queryLambdas(device.id(), port.number()); |
HIGUCHI Yuta | d39e376 | 2015-12-04 09:43:16 -0800 | [diff] [blame] | 160 | if (!lambdas.isEmpty()) { |
| 161 | adminService.registerResources(lambdas.stream() |
| 162 | .map(portPath::child) |
| 163 | .collect(Collectors.toList())); |
| 164 | } |
| 165 | |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 166 | // for Tributary slots |
Toru Furusawa | c23f583 | 2015-12-04 11:39:18 -0800 | [diff] [blame] | 167 | Set<TributarySlot> tSlots = queryTributarySlots(device.id(), port.number()); |
| 168 | if (!tSlots.isEmpty()) { |
| 169 | adminService.registerResources(tSlots.stream() |
| 170 | .map(portPath::child) |
| 171 | .collect(Collectors.toList())); |
Sho SHIMIZU | 2c7cecf | 2015-11-11 14:16:14 -0800 | [diff] [blame] | 172 | } |
| 173 | }); |
Rimon Ashkenazy | e2410ff | 2015-11-10 14:11:08 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Sho SHIMIZU | e229284 | 2015-08-20 11:59:23 -0700 | [diff] [blame] | 176 | private void unregisterPortResource(Device device, Port port) { |
Sho SHIMIZU | f95b96e | 2016-01-25 19:35:15 -0800 | [diff] [blame^] | 177 | Resource resource = Resource.discrete(device.id(), port.number()).resource(); |
Sho SHIMIZU | 2c7cecf | 2015-11-11 14:16:14 -0800 | [diff] [blame] | 178 | executor.submit(() -> adminService.unregisterResources(resource)); |
Sho SHIMIZU | e229284 | 2015-08-20 11:59:23 -0700 | [diff] [blame] | 179 | } |
Rimon Ashkenazy | e2410ff | 2015-11-10 14:11:08 +0200 | [diff] [blame] | 180 | |
HIGUCHI Yuta | 1d7c9cb | 2016-01-20 18:22:36 -0800 | [diff] [blame] | 181 | /** |
| 182 | * Query bandwidth capacity on a port. |
| 183 | * |
| 184 | * @param did {@link DeviceId} |
| 185 | * @param number {@link PortNumber} |
| 186 | * @return bandwidth capacity |
| 187 | */ |
| 188 | private Optional<Bandwidth> queryBandwidth(DeviceId did, PortNumber number) { |
| 189 | // Check and use netcfg first. |
| 190 | ConnectPoint cp = new ConnectPoint(did, number); |
| 191 | BandwidthCapacity config = netcfgService.getConfig(cp, BandwidthCapacity.class); |
| 192 | if (config != null) { |
| 193 | log.trace("Registering configured bandwidth {} for {}/{}", config.capacity(), did, number); |
| 194 | return Optional.of(config.capacity()); |
| 195 | } |
| 196 | |
| 197 | // populate bandwidth value, assuming portSpeed == bandwidth |
| 198 | Port port = deviceService.getPort(did, number); |
| 199 | if (port != null) { |
| 200 | return Optional.of(Bandwidth.mbps(port.portSpeed())); |
| 201 | } |
| 202 | return Optional.empty(); |
| 203 | } |
| 204 | |
Marc De Leenheer | 622861d | 2015-12-15 22:52:52 -0800 | [diff] [blame] | 205 | private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) { |
HIGUCHI Yuta | d39e376 | 2015-12-04 09:43:16 -0800 | [diff] [blame] | 206 | try { |
| 207 | DriverHandler handler = driverService.createHandler(did); |
HIGUCHI Yuta | 82b3c11 | 2016-01-07 22:22:26 -0800 | [diff] [blame] | 208 | if (handler == null || !handler.hasBehaviour(LambdaQuery.class)) { |
Marc De Leenheer | 622861d | 2015-12-15 22:52:52 -0800 | [diff] [blame] | 209 | return Collections.emptySet(); |
HIGUCHI Yuta | d39e376 | 2015-12-04 09:43:16 -0800 | [diff] [blame] | 210 | } |
| 211 | LambdaQuery query = handler.behaviour(LambdaQuery.class); |
HIGUCHI Yuta | 11d1609 | 2015-12-04 23:35:43 -0800 | [diff] [blame] | 212 | if (query != null) { |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 213 | return query.queryLambdas(port).stream() |
| 214 | .flatMap(x -> OchSignal.toFlexGrid(x).stream()) |
Marc De Leenheer | 622861d | 2015-12-15 22:52:52 -0800 | [diff] [blame] | 215 | .collect(Collectors.toSet()); |
HIGUCHI Yuta | 11d1609 | 2015-12-04 23:35:43 -0800 | [diff] [blame] | 216 | } else { |
Marc De Leenheer | 622861d | 2015-12-15 22:52:52 -0800 | [diff] [blame] | 217 | return Collections.emptySet(); |
HIGUCHI Yuta | 11d1609 | 2015-12-04 23:35:43 -0800 | [diff] [blame] | 218 | } |
HIGUCHI Yuta | d39e376 | 2015-12-04 09:43:16 -0800 | [diff] [blame] | 219 | } catch (ItemNotFoundException e) { |
Marc De Leenheer | 622861d | 2015-12-15 22:52:52 -0800 | [diff] [blame] | 220 | return Collections.emptySet(); |
HIGUCHI Yuta | d39e376 | 2015-12-04 09:43:16 -0800 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 224 | private Set<VlanId> queryVlanIds(DeviceId device, PortNumber port) { |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 225 | try { |
| 226 | DriverHandler handler = driverService.createHandler(device); |
HIGUCHI Yuta | 82b3c11 | 2016-01-07 22:22:26 -0800 | [diff] [blame] | 227 | if (handler == null || !handler.hasBehaviour(VlanQuery.class)) { |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 228 | return ImmutableSet.of(); |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | VlanQuery query = handler.behaviour(VlanQuery.class); |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 232 | if (query == null) { |
| 233 | return ImmutableSet.of(); |
| 234 | } |
| 235 | return query.queryVlanIds(port); |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 236 | } catch (ItemNotFoundException e) { |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 237 | return ImmutableSet.of(); |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 241 | private Set<MplsLabel> queryMplsLabels(DeviceId device, PortNumber port) { |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 242 | try { |
| 243 | DriverHandler handler = driverService.createHandler(device); |
HIGUCHI Yuta | 82b3c11 | 2016-01-07 22:22:26 -0800 | [diff] [blame] | 244 | if (handler == null || !handler.hasBehaviour(MplsQuery.class)) { |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 245 | return ImmutableSet.of(); |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | MplsQuery query = handler.behaviour(MplsQuery.class); |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 249 | if (query == null) { |
| 250 | return ImmutableSet.of(); |
| 251 | } |
| 252 | return query.queryMplsLabels(port); |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 253 | } catch (ItemNotFoundException e) { |
HIGUCHI Yuta | b7a15d7 | 2015-12-15 09:54:40 -0800 | [diff] [blame] | 254 | return ImmutableSet.of(); |
Sho SHIMIZU | 44f3761 | 2015-11-25 16:23:22 -0800 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
Toru Furusawa | c23f583 | 2015-12-04 11:39:18 -0800 | [diff] [blame] | 258 | private Set<TributarySlot> queryTributarySlots(DeviceId device, PortNumber port) { |
| 259 | try { |
Toru Furusawa | c23f583 | 2015-12-04 11:39:18 -0800 | [diff] [blame] | 260 | DriverHandler handler = driverService.createHandler(device); |
HIGUCHI Yuta | 82b3c11 | 2016-01-07 22:22:26 -0800 | [diff] [blame] | 261 | if (handler == null || !handler.hasBehaviour(TributarySlotQuery.class)) { |
Toru Furusawa | c23f583 | 2015-12-04 11:39:18 -0800 | [diff] [blame] | 262 | return Collections.emptySet(); |
| 263 | } |
| 264 | TributarySlotQuery query = handler.behaviour(TributarySlotQuery.class); |
| 265 | if (query != null) { |
| 266 | return query.queryTributarySlots(port); |
| 267 | } else { |
| 268 | return Collections.emptySet(); |
| 269 | } |
| 270 | } catch (ItemNotFoundException e) { |
| 271 | return Collections.emptySet(); |
| 272 | } |
Rimon Ashkenazy | e2410ff | 2015-11-10 14:11:08 +0200 | [diff] [blame] | 273 | } |
Sho SHIMIZU | d97a950 | 2015-08-18 10:02:30 -0700 | [diff] [blame] | 274 | } |