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