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