Committed by
Yuta HIGUCHI
[Falcon] Register TributarySlot resources in resource manager.
Change-Id: I61d63a7644a9edc2296a8f955af2ac2bfb93a5e4
Showing
4 changed files
with
148 additions
and
42 deletions
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 | + | ||
17 | +package org.onosproject.net.behaviour; | ||
18 | + | ||
19 | +import com.google.common.annotations.Beta; | ||
20 | +import org.onosproject.net.PortNumber; | ||
21 | +import org.onosproject.net.TributarySlot; | ||
22 | +import org.onosproject.net.driver.HandlerBehaviour; | ||
23 | + | ||
24 | +import java.util.Set; | ||
25 | + | ||
26 | +/** | ||
27 | + * Behaviour to retrieve available tributary slot resources. | ||
28 | + */ | ||
29 | +@Beta | ||
30 | +public interface TributarySlotQuery extends HandlerBehaviour { | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns set of TributarySlot instances which can be used at the port. | ||
34 | + * | ||
35 | + * @param port port to be checked for the available resources. | ||
36 | + * @return set of TributarySlot instances which can be used at the port. | ||
37 | + */ | ||
38 | + Set<TributarySlot> queryTributarySlots(PortNumber port); | ||
39 | +} |
... | @@ -16,20 +16,18 @@ | ... | @@ -16,20 +16,18 @@ |
16 | package org.onosproject.net.newresource.impl; | 16 | package org.onosproject.net.newresource.impl; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableSet; | 18 | import com.google.common.collect.ImmutableSet; |
19 | -import com.google.common.collect.Lists; | ||
20 | import org.onlab.packet.MplsLabel; | 19 | import org.onlab.packet.MplsLabel; |
21 | import org.onlab.packet.VlanId; | 20 | import org.onlab.packet.VlanId; |
22 | import org.onlab.util.ItemNotFoundException; | 21 | import org.onlab.util.ItemNotFoundException; |
23 | import org.onosproject.net.Device; | 22 | import org.onosproject.net.Device; |
24 | import org.onosproject.net.DeviceId; | 23 | import org.onosproject.net.DeviceId; |
25 | -import org.onosproject.net.Port; | ||
26 | -import org.onosproject.net.OchPort; | ||
27 | import org.onosproject.net.OchSignal; | 24 | import org.onosproject.net.OchSignal; |
25 | +import org.onosproject.net.Port; | ||
28 | import org.onosproject.net.PortNumber; | 26 | import org.onosproject.net.PortNumber; |
29 | import org.onosproject.net.TributarySlot; | 27 | import org.onosproject.net.TributarySlot; |
30 | -import org.onosproject.net.OduSignalType; | ||
31 | import org.onosproject.net.behaviour.LambdaQuery; | 28 | import org.onosproject.net.behaviour.LambdaQuery; |
32 | import org.onosproject.net.behaviour.MplsQuery; | 29 | import org.onosproject.net.behaviour.MplsQuery; |
30 | +import org.onosproject.net.behaviour.TributarySlotQuery; | ||
33 | import org.onosproject.net.behaviour.VlanQuery; | 31 | import org.onosproject.net.behaviour.VlanQuery; |
34 | import org.onosproject.net.device.DeviceEvent; | 32 | import org.onosproject.net.device.DeviceEvent; |
35 | import org.onosproject.net.device.DeviceListener; | 33 | import org.onosproject.net.device.DeviceListener; |
... | @@ -43,11 +41,9 @@ import org.slf4j.Logger; | ... | @@ -43,11 +41,9 @@ import org.slf4j.Logger; |
43 | import org.slf4j.LoggerFactory; | 41 | import org.slf4j.LoggerFactory; |
44 | 42 | ||
45 | import java.util.Collections; | 43 | import java.util.Collections; |
46 | -import java.util.List; | ||
47 | import java.util.Set; | 44 | import java.util.Set; |
48 | import java.util.concurrent.ExecutorService; | 45 | import java.util.concurrent.ExecutorService; |
49 | import java.util.stream.Collectors; | 46 | import java.util.stream.Collectors; |
50 | -import java.util.stream.IntStream; | ||
51 | 47 | ||
52 | import static com.google.common.base.Preconditions.checkNotNull; | 48 | import static com.google.common.base.Preconditions.checkNotNull; |
53 | 49 | ||
... | @@ -58,17 +54,11 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -58,17 +54,11 @@ final class ResourceDeviceListener implements DeviceListener { |
58 | 54 | ||
59 | private static final Logger log = LoggerFactory.getLogger(ResourceDeviceListener.class); | 55 | private static final Logger log = LoggerFactory.getLogger(ResourceDeviceListener.class); |
60 | 56 | ||
61 | - private static final int TOTAL_ODU2_TRIBUTARY_SLOTS = 8; | ||
62 | - private static final int TOTAL_ODU4_TRIBUTARY_SLOTS = 80; | ||
63 | - private static final List<TributarySlot> ENTIRE_ODU2_TRIBUTARY_SLOTS = getEntireOdu2TributarySlots(); | ||
64 | - private static final List<TributarySlot> ENTIRE_ODU4_TRIBUTARY_SLOTS = getEntireOdu4TributarySlots(); | ||
65 | - | ||
66 | private final ResourceAdminService adminService; | 57 | private final ResourceAdminService adminService; |
67 | private final DeviceService deviceService; | 58 | private final DeviceService deviceService; |
68 | private final DriverService driverService; | 59 | private final DriverService driverService; |
69 | private final ExecutorService executor; | 60 | private final ExecutorService executor; |
70 | 61 | ||
71 | - | ||
72 | /** | 62 | /** |
73 | * Creates an instance with the specified ResourceAdminService and ExecutorService. | 63 | * Creates an instance with the specified ResourceAdminService and ExecutorService. |
74 | * | 64 | * |
... | @@ -156,31 +146,15 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -156,31 +146,15 @@ final class ResourceDeviceListener implements DeviceListener { |
156 | } | 146 | } |
157 | 147 | ||
158 | // for Tributary slots | 148 | // for Tributary slots |
159 | - // TODO: need to define Behaviour to make a query about OCh port | 149 | + Set<TributarySlot> tSlots = queryTributarySlots(device.id(), port.number()); |
160 | - switch (port.type()) { | 150 | + if (!tSlots.isEmpty()) { |
161 | - case OCH: | 151 | + adminService.registerResources(tSlots.stream() |
162 | - // register ODU TributarySlots against the OCH port | 152 | + .map(portPath::child) |
163 | - registerTributarySlotsResources(((OchPort) port).signalType(), portPath); | 153 | + .collect(Collectors.toList())); |
164 | - break; | ||
165 | - default: | ||
166 | - break; | ||
167 | } | 154 | } |
168 | }); | 155 | }); |
169 | } | 156 | } |
170 | 157 | ||
171 | - private void registerTributarySlotsResources(OduSignalType oduSignalType, ResourcePath portPath) { | ||
172 | - switch (oduSignalType) { | ||
173 | - case ODU2: | ||
174 | - adminService.registerResources(Lists.transform(ENTIRE_ODU2_TRIBUTARY_SLOTS, portPath::child)); | ||
175 | - break; | ||
176 | - case ODU4: | ||
177 | - adminService.registerResources(Lists.transform(ENTIRE_ODU4_TRIBUTARY_SLOTS, portPath::child)); | ||
178 | - break; | ||
179 | - default: | ||
180 | - break; | ||
181 | - } | ||
182 | - } | ||
183 | - | ||
184 | private void unregisterPortResource(Device device, Port port) { | 158 | private void unregisterPortResource(Device device, Port port) { |
185 | ResourcePath resource = ResourcePath.discrete(device.id(), port.number()); | 159 | ResourcePath resource = ResourcePath.discrete(device.id(), port.number()); |
186 | executor.submit(() -> adminService.unregisterResources(resource)); | 160 | executor.submit(() -> adminService.unregisterResources(resource)); |
... | @@ -260,14 +234,26 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -260,14 +234,26 @@ final class ResourceDeviceListener implements DeviceListener { |
260 | } | 234 | } |
261 | } | 235 | } |
262 | 236 | ||
263 | - private static List<TributarySlot> getEntireOdu2TributarySlots() { | 237 | + private Set<TributarySlot> queryTributarySlots(DeviceId device, PortNumber port) { |
264 | - return IntStream.rangeClosed(1, TOTAL_ODU2_TRIBUTARY_SLOTS) | 238 | + try { |
265 | - .mapToObj(TributarySlot::of) | 239 | + // DriverHandler does not provide a way to check if a |
266 | - .collect(Collectors.toList()); | 240 | + // behaviour is supported. |
267 | - } | 241 | + Driver driver = driverService.getDriver(device); |
268 | - private static List<TributarySlot> getEntireOdu4TributarySlots() { | 242 | + if (driver == null || !driver.hasBehaviour(TributarySlotQuery.class)) { |
269 | - return IntStream.rangeClosed(1, TOTAL_ODU4_TRIBUTARY_SLOTS) | 243 | + return Collections.emptySet(); |
270 | - .mapToObj(TributarySlot::of) | 244 | + } |
271 | - .collect(Collectors.toList()); | 245 | + DriverHandler handler = driverService.createHandler(device); |
246 | + if (handler == null) { | ||
247 | + return Collections.emptySet(); | ||
248 | + } | ||
249 | + TributarySlotQuery query = handler.behaviour(TributarySlotQuery.class); | ||
250 | + if (query != null) { | ||
251 | + return query.queryTributarySlots(port); | ||
252 | + } else { | ||
253 | + return Collections.emptySet(); | ||
254 | + } | ||
255 | + } catch (ItemNotFoundException e) { | ||
256 | + return Collections.emptySet(); | ||
257 | + } | ||
272 | } | 258 | } |
273 | } | 259 | } | ... | ... |
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.driver.query; | ||
17 | + | ||
18 | +import org.onlab.util.GuavaCollectors; | ||
19 | +import org.onosproject.net.OchPort; | ||
20 | +import org.onosproject.net.OduSignalType; | ||
21 | +import org.onosproject.net.Port; | ||
22 | +import org.onosproject.net.PortNumber; | ||
23 | +import org.onosproject.net.TributarySlot; | ||
24 | +import org.onosproject.net.device.DeviceService; | ||
25 | +import org.onosproject.net.driver.AbstractHandlerBehaviour; | ||
26 | +import org.onosproject.net.behaviour.TributarySlotQuery; | ||
27 | +import org.slf4j.Logger; | ||
28 | +import org.slf4j.LoggerFactory; | ||
29 | + | ||
30 | +import java.util.Collections; | ||
31 | +import java.util.Set; | ||
32 | +import java.util.stream.IntStream; | ||
33 | + | ||
34 | +/** | ||
35 | + * TributarySlotQuery implementation which responds that all slots of ODU2 or ODU4 are available for the port. | ||
36 | + */ | ||
37 | +public class DefaultTributarySlotQuery extends AbstractHandlerBehaviour implements TributarySlotQuery { | ||
38 | + | ||
39 | + private static final Logger log = LoggerFactory.getLogger(DefaultTributarySlotQuery.class); | ||
40 | + | ||
41 | + private static final int TOTAL_ODU2_TRIBUTARY_SLOTS = 8; | ||
42 | + private static final int TOTAL_ODU4_TRIBUTARY_SLOTS = 80; | ||
43 | + | ||
44 | + private static Set<TributarySlot> getEntireOdu2TributarySlots() { | ||
45 | + return IntStream.rangeClosed(1, TOTAL_ODU2_TRIBUTARY_SLOTS) | ||
46 | + .mapToObj(TributarySlot::of) | ||
47 | + .collect(GuavaCollectors.toImmutableSet()); | ||
48 | + } | ||
49 | + | ||
50 | + private static Set<TributarySlot> getEntireOdu4TributarySlots() { | ||
51 | + return IntStream.rangeClosed(1, TOTAL_ODU4_TRIBUTARY_SLOTS) | ||
52 | + .mapToObj(TributarySlot::of) | ||
53 | + .collect(GuavaCollectors.toImmutableSet()); | ||
54 | + } | ||
55 | + | ||
56 | + private static final Set<TributarySlot> ENTIRE_ODU2_TRIBUTARY_SLOTS = getEntireOdu2TributarySlots(); | ||
57 | + private static final Set<TributarySlot> ENTIRE_ODU4_TRIBUTARY_SLOTS = getEntireOdu4TributarySlots(); | ||
58 | + | ||
59 | + @Override | ||
60 | + public Set<TributarySlot> queryTributarySlots(PortNumber port) { | ||
61 | + // currently return all slots by default. | ||
62 | + DeviceService deviceService = this.handler().get(DeviceService.class); | ||
63 | + Port p = deviceService.getPort(this.data().deviceId(), port); | ||
64 | + | ||
65 | + if (!(p instanceof OchPort)) { | ||
66 | + return Collections.emptySet(); | ||
67 | + } | ||
68 | + OduSignalType signalType = ((OchPort) p).signalType(); | ||
69 | + switch (signalType) { | ||
70 | + case ODU2: | ||
71 | + return ENTIRE_ODU2_TRIBUTARY_SLOTS; | ||
72 | + case ODU4: | ||
73 | + return ENTIRE_ODU4_TRIBUTARY_SLOTS; | ||
74 | + default: | ||
75 | + log.error("Unsupported signal type {}", signalType); | ||
76 | + return Collections.emptySet(); | ||
77 | + } | ||
78 | + } | ||
79 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -173,6 +173,8 @@ | ... | @@ -173,6 +173,8 @@ |
173 | manufacturer="ECI Telecom" hwVersion="Optical.*" swVersion="V_1_0"> | 173 | manufacturer="ECI Telecom" hwVersion="Optical.*" swVersion="V_1_0"> |
174 | <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" | 174 | <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" |
175 | impl="org.onosproject.driver.handshaker.OFOpticalSwitch13"/> | 175 | impl="org.onosproject.driver.handshaker.OFOpticalSwitch13"/> |
176 | + <behaviour api="org.onosproject.net.behaviour.TributarySlotQuery" | ||
177 | + impl="org.onosproject.driver.query.DefaultTributarySlotQuery" /> | ||
176 | </driver> | 178 | </driver> |
177 | <driver name="aos" extends="ofdpa" | 179 | <driver name="aos" extends="ofdpa" |
178 | manufacturer="Accton" hwVersion=".*" swVersion="1.*"> | 180 | manufacturer="Accton" hwVersion=".*" swVersion="1.*"> | ... | ... |
-
Please register or login to post a comment