blob: 7ba02964dfa03533c65ed04fb8cf83298bf11435 [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;
Yuta HIGUCHIedd932f2017-03-11 13:47:41 -080024import org.onlab.util.GuavaCollectors;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080025import org.onlab.util.ItemNotFoundException;
Sho SHIMIZU76b046e2016-02-24 11:45:44 -080026import org.onosproject.mastership.MastershipService;
HIGUCHI Yuta6057d082016-04-29 11:57:23 -070027import org.onosproject.net.ChannelSpacing;
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080028import org.onosproject.net.ConnectPoint;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070029import org.onosproject.net.Device;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080030import org.onosproject.net.DeviceId;
HIGUCHI Yuta6057d082016-04-29 11:57:23 -070031import org.onosproject.net.GridType;
HIGUCHI Yutad39e3762015-12-04 09:43:16 -080032import org.onosproject.net.OchSignal;
Toru Furusawac23f5832015-12-04 11:39:18 -080033import org.onosproject.net.Port;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080034import org.onosproject.net.PortNumber;
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +020035import org.onosproject.net.TributarySlot;
HIGUCHI Yutad39e3762015-12-04 09:43:16 -080036import org.onosproject.net.behaviour.LambdaQuery;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080037import org.onosproject.net.behaviour.MplsQuery;
Toru Furusawac23f5832015-12-04 11:39:18 -080038import org.onosproject.net.behaviour.TributarySlotQuery;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080039import org.onosproject.net.behaviour.VlanQuery;
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080040import org.onosproject.net.config.NetworkConfigService;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070041import org.onosproject.net.device.DeviceEvent;
42import org.onosproject.net.device.DeviceListener;
HIGUCHI Yuta11d16092015-12-04 23:35:43 -080043import org.onosproject.net.device.DeviceService;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080044import org.onosproject.net.driver.DriverHandler;
45import org.onosproject.net.driver.DriverService;
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080046import org.onosproject.net.resource.DiscreteResource;
47import org.onosproject.net.resource.ResourceAdminService;
Sho SHIMIZUb6c63a32016-05-26 12:07:19 -070048import org.onosproject.net.config.basics.BandwidthCapacity;
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080049import org.onosproject.net.resource.Resource;
Sho SHIMIZUa6b4dc72016-03-11 19:00:20 -080050import org.onosproject.net.resource.ResourceQueryService;
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080051import org.onosproject.net.resource.Resources;
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +020052import org.slf4j.Logger;
53import org.slf4j.LoggerFactory;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070054
HIGUCHI Yutad39e3762015-12-04 09:43:16 -080055import java.util.Collections;
Naoki Shiotabe394c82016-02-03 16:44:29 -080056import java.util.LinkedList;
57import java.util.List;
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080058import java.util.Optional;
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -080059import java.util.Set;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070060import java.util.concurrent.ExecutorService;
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +020061import java.util.stream.Collectors;
HIGUCHI Yuta6057d082016-04-29 11:57:23 -070062import java.util.stream.Stream;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070063
64import static com.google.common.base.Preconditions.checkNotNull;
65
66/**
67 * An implementation of DeviceListener registering devices as resources.
68 */
69final class ResourceDeviceListener implements DeviceListener {
70
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +020071 private static final Logger log = LoggerFactory.getLogger(ResourceDeviceListener.class);
72
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070073 private final ResourceAdminService adminService;
Sho SHIMIZUa6b4dc72016-03-11 19:00:20 -080074 private final ResourceQueryService resourceService;
HIGUCHI Yuta11d16092015-12-04 23:35:43 -080075 private final DeviceService deviceService;
Sho SHIMIZU76b046e2016-02-24 11:45:44 -080076 private final MastershipService mastershipService;
Sho SHIMIZU44f37612015-11-25 16:23:22 -080077 private final DriverService driverService;
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080078 private final NetworkConfigService netcfgService;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070079 private final ExecutorService executor;
80
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080081
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070082 /**
83 * Creates an instance with the specified ResourceAdminService and ExecutorService.
84 *
85 * @param adminService instance invoked to register resources
Sho SHIMIZUa6b4dc72016-03-11 19:00:20 -080086 * @param resourceService {@link ResourceQueryService} to be used
Jian Lidfba7392016-01-22 16:46:58 -080087 * @param deviceService {@link DeviceService} to be used
Sho SHIMIZU76b046e2016-02-24 11:45:44 -080088 * @param mastershipService {@link MastershipService} to be used
Jian Lidfba7392016-01-22 16:46:58 -080089 * @param driverService {@link DriverService} to be used
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -080090 * @param netcfgService {@link NetworkConfigService} to be used.
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070091 * @param executor executor used for processing resource registration
92 */
Sho SHIMIZUa6b4dc72016-03-11 19:00:20 -080093 ResourceDeviceListener(ResourceAdminService adminService, ResourceQueryService resourceService,
Sho SHIMIZU76b046e2016-02-24 11:45:44 -080094 DeviceService deviceService, MastershipService mastershipService,
95 DriverService driverService, NetworkConfigService netcfgService,
96 ExecutorService executor) {
Sho SHIMIZUd97a9502015-08-18 10:02:30 -070097 this.adminService = checkNotNull(adminService);
Naoki Shiotabe394c82016-02-03 16:44:29 -080098 this.resourceService = checkNotNull(resourceService);
HIGUCHI Yuta11d16092015-12-04 23:35:43 -080099 this.deviceService = checkNotNull(deviceService);
Sho SHIMIZU76b046e2016-02-24 11:45:44 -0800100 this.mastershipService = checkNotNull(mastershipService);
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800101 this.driverService = checkNotNull(driverService);
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -0800102 this.netcfgService = checkNotNull(netcfgService);
Sho SHIMIZUd97a9502015-08-18 10:02:30 -0700103 this.executor = checkNotNull(executor);
104 }
105
106 @Override
107 public void event(DeviceEvent event) {
108 Device device = event.subject();
Sho SHIMIZU76b046e2016-02-24 11:45:44 -0800109 // registration happens only when the caller is the master of the device
110 if (!mastershipService.isLocalMaster(device.id())) {
111 return;
112 }
113
Sho SHIMIZUd97a9502015-08-18 10:02:30 -0700114 switch (event.type()) {
115 case DEVICE_ADDED:
116 registerDeviceResource(device);
117 break;
Sho SHIMIZUe60a5ab2015-08-20 11:51:49 -0700118 case DEVICE_REMOVED:
119 unregisterDeviceResource(device);
120 break;
HIGUCHI Yuta11d16092015-12-04 23:35:43 -0800121 case DEVICE_AVAILABILITY_CHANGED:
122 if (deviceService.isAvailable(device.id())) {
123 registerDeviceResource(device);
124 // TODO: do we need to walk the ports?
125 } else {
126 unregisterDeviceResource(device);
127 }
128 break;
Sho SHIMIZU08fdbd22015-08-19 16:59:35 -0700129 case PORT_ADDED:
HIGUCHI Yuta11d16092015-12-04 23:35:43 -0800130 case PORT_UPDATED:
131 if (event.port().isEnabled()) {
132 registerPortResource(device, event.port());
133 } else {
134 unregisterPortResource(device, event.port());
135 }
Sho SHIMIZUc2ddedd2015-08-20 11:54:29 -0700136 break;
Sho SHIMIZUe2292842015-08-20 11:59:23 -0700137 case PORT_REMOVED:
138 unregisterPortResource(device, event.port());
139 break;
Sho SHIMIZUd97a9502015-08-18 10:02:30 -0700140 default:
141 break;
142 }
143 }
144
145 private void registerDeviceResource(Device device) {
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800146 executor.execute(() -> {
147 boolean success = adminService.register(Resources.discrete(device.id()).resource());
148 if (!success) {
Yuta HIGUCHI1f3b3722017-03-17 19:33:07 -0700149 log.error("Failed to register Device: {}", device.id());
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800150 }
151 });
Sho SHIMIZUd97a9502015-08-18 10:02:30 -0700152 }
Sho SHIMIZU08fdbd22015-08-19 16:59:35 -0700153
Sho SHIMIZUe60a5ab2015-08-20 11:51:49 -0700154 private void unregisterDeviceResource(Device device) {
HIGUCHI Yuta060da9a2016-03-11 19:16:35 -0800155 executor.execute(() -> {
Sho SHIMIZU2fbc33c2016-02-09 14:03:23 -0800156 DiscreteResource devResource = Resources.discrete(device.id()).resource();
Naoki Shiotabe394c82016-02-03 16:44:29 -0800157 List<Resource> allResources = getDescendantResources(devResource);
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800158 adminService.unregister(Lists.transform(allResources, Resource::id));
Naoki Shiotabe394c82016-02-03 16:44:29 -0800159 });
Sho SHIMIZUe60a5ab2015-08-20 11:51:49 -0700160 }
161
Sho SHIMIZU08fdbd22015-08-19 16:59:35 -0700162 private void registerPortResource(Device device, Port port) {
Sho SHIMIZU460b9722016-01-28 10:48:26 -0800163 Resource portPath = Resources.discrete(device.id(), port.number()).resource();
HIGUCHI Yuta060da9a2016-03-11 19:16:35 -0800164 executor.execute(() -> {
Yuta HIGUCHI1f3b3722017-03-17 19:33:07 -0700165 if (!adminService.register(portPath)) {
166 log.error("Failed to register Port: {}", portPath.id());
167 }
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +0200168
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -0800169 queryBandwidth(device.id(), port.number())
170 .map(bw -> portPath.child(Bandwidth.class, bw.bps()))
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800171 .map(adminService::register)
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -0800172 .ifPresent(success -> {
173 if (!success) {
Yuta HIGUCHI1f3b3722017-03-17 19:33:07 -0700174 log.error("Failed to register Bandwidth for {}", portPath.id());
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -0800175 }
176 });
177
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800178 // for VLAN IDs
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800179 Set<VlanId> vlans = queryVlanIds(device.id(), port.number());
180 if (!vlans.isEmpty()) {
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800181 boolean success = adminService.register(vlans.stream()
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800182 .map(portPath::child)
183 .collect(Collectors.toList()));
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800184 if (!success) {
Yuta HIGUCHI1f3b3722017-03-17 19:33:07 -0700185 log.error("Failed to register VLAN IDs for {}", portPath.id());
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800186 }
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800187 }
188
189 // for MPLS labels
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800190 Set<MplsLabel> mplsLabels = queryMplsLabels(device.id(), port.number());
191 if (!mplsLabels.isEmpty()) {
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800192 boolean success = adminService.register(mplsLabels.stream()
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800193 .map(portPath::child)
194 .collect(Collectors.toList()));
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800195 if (!success) {
Yuta HIGUCHI1f3b3722017-03-17 19:33:07 -0700196 log.error("Failed to register MPLS Labels for {}", portPath.id());
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800197 }
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800198 }
199
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800200 // for Lambdas
Marc De Leenheer622861d2015-12-15 22:52:52 -0800201 Set<OchSignal> lambdas = queryLambdas(device.id(), port.number());
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800202 if (!lambdas.isEmpty()) {
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800203 boolean success = adminService.register(lambdas.stream()
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800204 .map(portPath::child)
205 .collect(Collectors.toList()));
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800206 if (!success) {
Yuta HIGUCHI1f3b3722017-03-17 19:33:07 -0700207 log.error("Failed to register lambdas for {}", portPath.id());
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800208 }
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800209 }
210
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800211 // for Tributary slots
Toru Furusawac23f5832015-12-04 11:39:18 -0800212 Set<TributarySlot> tSlots = queryTributarySlots(device.id(), port.number());
213 if (!tSlots.isEmpty()) {
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800214 boolean success = adminService.register(tSlots.stream()
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800215 .map(portPath::child)
216 .collect(Collectors.toList()));
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800217 if (!success) {
Yuta HIGUCHI1f3b3722017-03-17 19:33:07 -0700218 log.error("Failed to register tributary slots for {}", portPath.id());
Sho SHIMIZUf84ea7f2016-12-22 14:47:17 -0800219 }
Sho SHIMIZU2c7cecf2015-11-11 14:16:14 -0800220 }
221 });
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +0200222 }
223
Sho SHIMIZUe2292842015-08-20 11:59:23 -0700224 private void unregisterPortResource(Device device, Port port) {
HIGUCHI Yuta060da9a2016-03-11 19:16:35 -0800225 executor.execute(() -> {
Sho SHIMIZU2fbc33c2016-02-09 14:03:23 -0800226 DiscreteResource portResource = Resources.discrete(device.id(), port.number()).resource();
Naoki Shiotabe394c82016-02-03 16:44:29 -0800227 List<Resource> allResources = getDescendantResources(portResource);
Sho SHIMIZU7b326972016-02-09 15:53:39 -0800228 adminService.unregister(Lists.transform(allResources, Resource::id));
Naoki Shiotabe394c82016-02-03 16:44:29 -0800229 });
230 }
231
232 // Returns list of all descendant resources of given resource, including itself.
Sho SHIMIZU2fbc33c2016-02-09 14:03:23 -0800233 private List<Resource> getDescendantResources(DiscreteResource parent) {
Naoki Shiotabe394c82016-02-03 16:44:29 -0800234 LinkedList<Resource> allResources = new LinkedList<>();
235 allResources.add(parent);
236
Sho SHIMIZU2fbc33c2016-02-09 14:03:23 -0800237 Set<Resource> nextResources = resourceService.getRegisteredResources(parent.id());
Naoki Shiotabe394c82016-02-03 16:44:29 -0800238 while (!nextResources.isEmpty()) {
239 Set<Resource> currentResources = nextResources;
240 // resource list should be ordered from leaf to root
241 allResources.addAll(0, currentResources);
242
243 nextResources = currentResources.stream()
Sho SHIMIZU2fbc33c2016-02-09 14:03:23 -0800244 .filter(r -> r instanceof DiscreteResource)
245 .map(r -> (DiscreteResource) r)
246 .flatMap(r -> resourceService.getRegisteredResources(r.id()).stream())
Naoki Shiotabe394c82016-02-03 16:44:29 -0800247 .collect(Collectors.toSet());
248 }
249
250 return allResources;
Sho SHIMIZUe2292842015-08-20 11:59:23 -0700251 }
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +0200252
HIGUCHI Yuta1d7c9cb2016-01-20 18:22:36 -0800253 /**
254 * Query bandwidth capacity on a port.
255 *
256 * @param did {@link DeviceId}
257 * @param number {@link PortNumber}
258 * @return bandwidth capacity
259 */
260 private Optional<Bandwidth> queryBandwidth(DeviceId did, PortNumber number) {
261 // Check and use netcfg first.
262 ConnectPoint cp = new ConnectPoint(did, number);
263 BandwidthCapacity config = netcfgService.getConfig(cp, BandwidthCapacity.class);
264 if (config != null) {
265 log.trace("Registering configured bandwidth {} for {}/{}", config.capacity(), did, number);
266 return Optional.of(config.capacity());
267 }
268
269 // populate bandwidth value, assuming portSpeed == bandwidth
270 Port port = deviceService.getPort(did, number);
271 if (port != null) {
272 return Optional.of(Bandwidth.mbps(port.portSpeed()));
273 }
274 return Optional.empty();
275 }
276
Marc De Leenheer622861d2015-12-15 22:52:52 -0800277 private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) {
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800278 try {
279 DriverHandler handler = driverService.createHandler(did);
HIGUCHI Yuta82b3c112016-01-07 22:22:26 -0800280 if (handler == null || !handler.hasBehaviour(LambdaQuery.class)) {
Marc De Leenheer622861d2015-12-15 22:52:52 -0800281 return Collections.emptySet();
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800282 }
283 LambdaQuery query = handler.behaviour(LambdaQuery.class);
HIGUCHI Yuta11d16092015-12-04 23:35:43 -0800284 if (query != null) {
Marc De Leenheer2c305302015-12-07 21:37:44 -0800285 return query.queryLambdas(port).stream()
HIGUCHI Yuta6057d082016-04-29 11:57:23 -0700286 .flatMap(ResourceDeviceListener::toResourceGrid)
Yuta HIGUCHIedd932f2017-03-11 13:47:41 -0800287 .collect(GuavaCollectors.toImmutableSet());
HIGUCHI Yuta11d16092015-12-04 23:35:43 -0800288 } else {
Marc De Leenheer622861d2015-12-15 22:52:52 -0800289 return Collections.emptySet();
HIGUCHI Yuta11d16092015-12-04 23:35:43 -0800290 }
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800291 } catch (ItemNotFoundException e) {
Marc De Leenheer622861d2015-12-15 22:52:52 -0800292 return Collections.emptySet();
HIGUCHI Yutad39e3762015-12-04 09:43:16 -0800293 }
294 }
295
HIGUCHI Yuta6057d082016-04-29 11:57:23 -0700296 /**
297 * Convert {@link OchSignal} into gridtype used to track Resource.
298 *
299 * @param ochSignal {@link OchSignal}
300 * @return {@code ochSignal} mapped to Stream of flex grid slots with 6.25 GHz spacing
301 * and 12.5 GHz slot width.
302 */
303 private static Stream<OchSignal> toResourceGrid(OchSignal ochSignal) {
304 if (ochSignal.gridType() != GridType.FLEX) {
305 return OchSignal.toFlexGrid(ochSignal).stream();
306 }
307 if (ochSignal.gridType() == GridType.FLEX &&
308 ochSignal.channelSpacing() == ChannelSpacing.CHL_6P25GHZ &&
309 ochSignal.slotGranularity() == 1) {
310 // input was already flex grid slots with 6.25 GHz spacing and 12.5 GHz slot width.
311 return Stream.of(ochSignal);
312 }
313 // FIXME handle FLEX but not 6.25 GHz spacing or 12.5 GHz slot width case.
314 log.error("Converting {} to resource tracking grid not supported yet.", ochSignal);
315 return Stream.<OchSignal>builder().build();
316 }
317
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800318 private Set<VlanId> queryVlanIds(DeviceId device, PortNumber port) {
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800319 try {
320 DriverHandler handler = driverService.createHandler(device);
HIGUCHI Yuta82b3c112016-01-07 22:22:26 -0800321 if (handler == null || !handler.hasBehaviour(VlanQuery.class)) {
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800322 return ImmutableSet.of();
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800323 }
324
325 VlanQuery query = handler.behaviour(VlanQuery.class);
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800326 if (query == null) {
327 return ImmutableSet.of();
328 }
329 return query.queryVlanIds(port);
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800330 } catch (ItemNotFoundException e) {
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800331 return ImmutableSet.of();
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800332 }
333 }
334
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800335 private Set<MplsLabel> queryMplsLabels(DeviceId device, PortNumber port) {
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800336 try {
337 DriverHandler handler = driverService.createHandler(device);
HIGUCHI Yuta82b3c112016-01-07 22:22:26 -0800338 if (handler == null || !handler.hasBehaviour(MplsQuery.class)) {
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800339 return ImmutableSet.of();
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800340 }
341
342 MplsQuery query = handler.behaviour(MplsQuery.class);
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800343 if (query == null) {
344 return ImmutableSet.of();
345 }
346 return query.queryMplsLabels(port);
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800347 } catch (ItemNotFoundException e) {
HIGUCHI Yutab7a15d72015-12-15 09:54:40 -0800348 return ImmutableSet.of();
Sho SHIMIZU44f37612015-11-25 16:23:22 -0800349 }
350 }
351
Toru Furusawac23f5832015-12-04 11:39:18 -0800352 private Set<TributarySlot> queryTributarySlots(DeviceId device, PortNumber port) {
353 try {
Toru Furusawac23f5832015-12-04 11:39:18 -0800354 DriverHandler handler = driverService.createHandler(device);
HIGUCHI Yuta82b3c112016-01-07 22:22:26 -0800355 if (handler == null || !handler.hasBehaviour(TributarySlotQuery.class)) {
Toru Furusawac23f5832015-12-04 11:39:18 -0800356 return Collections.emptySet();
357 }
358 TributarySlotQuery query = handler.behaviour(TributarySlotQuery.class);
359 if (query != null) {
360 return query.queryTributarySlots(port);
361 } else {
362 return Collections.emptySet();
363 }
364 } catch (ItemNotFoundException e) {
365 return Collections.emptySet();
366 }
Rimon Ashkenazye2410ff2015-11-10 14:11:08 +0200367 }
Sho SHIMIZUd97a9502015-08-18 10:02:30 -0700368}