Marc De Leenheer
Committed by Yuta HIGUCHI

Lambda queries don't rely on driver state, and have separate package.

Lambda query returns unsorted set.

fix for ONOS-3620

Change-Id: Ifffd03271f9c8c02be8897c3891c80148342757e
...@@ -21,7 +21,7 @@ import org.onosproject.net.OchSignal; ...@@ -21,7 +21,7 @@ import org.onosproject.net.OchSignal;
21 import org.onosproject.net.PortNumber; 21 import org.onosproject.net.PortNumber;
22 import org.onosproject.net.driver.HandlerBehaviour; 22 import org.onosproject.net.driver.HandlerBehaviour;
23 23
24 -import java.util.SortedSet; 24 +import java.util.Set;
25 25
26 /** 26 /**
27 * A HandlerBehaviour to retrieve available wavelength resources. 27 * A HandlerBehaviour to retrieve available wavelength resources.
...@@ -29,12 +29,11 @@ import java.util.SortedSet; ...@@ -29,12 +29,11 @@ import java.util.SortedSet;
29 @Beta 29 @Beta
30 public interface LambdaQuery extends HandlerBehaviour { 30 public interface LambdaQuery extends HandlerBehaviour {
31 31
32 - // Currently returns set of FLEX GridType ochSignal instances
33 /** 32 /**
34 - * Returns set of Lambda instances which can be used at the port. 33 + * Returns set of OchSignal instances which can be used at the port.
35 * 34 *
36 * @param port to be checked for the available resources. 35 * @param port to be checked for the available resources.
37 - * @return Set of OchSignals which can be used at the port. 36 + * @return set of OchSignals which can be used at the port.
38 */ 37 */
39 - SortedSet<OchSignal> queryLambdas(PortNumber port); 38 + Set<OchSignal> queryLambdas(PortNumber port);
40 } 39 }
......
...@@ -20,7 +20,6 @@ import com.google.common.collect.Lists; ...@@ -20,7 +20,6 @@ import com.google.common.collect.Lists;
20 import org.onlab.packet.MplsLabel; 20 import org.onlab.packet.MplsLabel;
21 import org.onlab.packet.VlanId; 21 import org.onlab.packet.VlanId;
22 import org.onlab.util.ItemNotFoundException; 22 import org.onlab.util.ItemNotFoundException;
23 -import org.onosproject.net.DefaultOchSignalComparator;
24 import org.onosproject.net.Device; 23 import org.onosproject.net.Device;
25 import org.onosproject.net.DeviceId; 24 import org.onosproject.net.DeviceId;
26 import org.onosproject.net.Port; 25 import org.onosproject.net.Port;
...@@ -46,7 +45,6 @@ import org.slf4j.LoggerFactory; ...@@ -46,7 +45,6 @@ import org.slf4j.LoggerFactory;
46 import java.util.Collections; 45 import java.util.Collections;
47 import java.util.List; 46 import java.util.List;
48 import java.util.Set; 47 import java.util.Set;
49 -import java.util.SortedSet;
50 import java.util.concurrent.ExecutorService; 48 import java.util.concurrent.ExecutorService;
51 import java.util.stream.Collectors; 49 import java.util.stream.Collectors;
52 import java.util.stream.IntStream; 50 import java.util.stream.IntStream;
...@@ -150,7 +148,7 @@ final class ResourceDeviceListener implements DeviceListener { ...@@ -150,7 +148,7 @@ final class ResourceDeviceListener implements DeviceListener {
150 } 148 }
151 149
152 // for Lambdas 150 // for Lambdas
153 - SortedSet<OchSignal> lambdas = queryLambdas(device.id(), port.number()); 151 + Set<OchSignal> lambdas = queryLambdas(device.id(), port.number());
154 if (!lambdas.isEmpty()) { 152 if (!lambdas.isEmpty()) {
155 adminService.registerResources(lambdas.stream() 153 adminService.registerResources(lambdas.stream()
156 .map(portPath::child) 154 .map(portPath::child)
...@@ -188,28 +186,28 @@ final class ResourceDeviceListener implements DeviceListener { ...@@ -188,28 +186,28 @@ final class ResourceDeviceListener implements DeviceListener {
188 executor.submit(() -> adminService.unregisterResources(resource)); 186 executor.submit(() -> adminService.unregisterResources(resource));
189 } 187 }
190 188
191 - private SortedSet<OchSignal> queryLambdas(DeviceId did, PortNumber port) { 189 + private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) {
192 try { 190 try {
193 // DriverHandler does not provide a way to check if a 191 // DriverHandler does not provide a way to check if a
194 // behaviour is supported. 192 // behaviour is supported.
195 Driver driver = driverService.getDriver(did); 193 Driver driver = driverService.getDriver(did);
196 if (driver == null || !driver.hasBehaviour(LambdaQuery.class)) { 194 if (driver == null || !driver.hasBehaviour(LambdaQuery.class)) {
197 - return Collections.emptySortedSet(); 195 + return Collections.emptySet();
198 } 196 }
199 DriverHandler handler = driverService.createHandler(did); 197 DriverHandler handler = driverService.createHandler(did);
200 if (handler == null) { 198 if (handler == null) {
201 - return Collections.emptySortedSet(); 199 + return Collections.emptySet();
202 } 200 }
203 LambdaQuery query = handler.behaviour(LambdaQuery.class); 201 LambdaQuery query = handler.behaviour(LambdaQuery.class);
204 if (query != null) { 202 if (query != null) {
205 return query.queryLambdas(port).stream() 203 return query.queryLambdas(port).stream()
206 .flatMap(x -> OchSignal.toFlexGrid(x).stream()) 204 .flatMap(x -> OchSignal.toFlexGrid(x).stream())
207 - .collect(Collectors.toCollection(DefaultOchSignalComparator::newOchSignalTreeSet)); 205 + .collect(Collectors.toSet());
208 } else { 206 } else {
209 - return Collections.emptySortedSet(); 207 + return Collections.emptySet();
210 } 208 }
211 } catch (ItemNotFoundException e) { 209 } catch (ItemNotFoundException e) {
212 - return Collections.emptySortedSet(); 210 + return Collections.emptySet();
213 } 211 }
214 } 212 }
215 213
......
...@@ -17,14 +17,7 @@ package org.onosproject.driver.handshaker; ...@@ -17,14 +17,7 @@ package org.onosproject.driver.handshaker;
17 17
18 import com.google.common.collect.ImmutableList; 18 import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.ImmutableSet; 19 import com.google.common.collect.ImmutableSet;
20 -import org.onlab.util.Spectrum;
21 -import org.onosproject.net.ChannelSpacing;
22 -import org.onosproject.net.DefaultOchSignalComparator;
23 import org.onosproject.net.Device; 20 import org.onosproject.net.Device;
24 -import org.onosproject.net.GridType;
25 -import org.onosproject.net.OchSignal;
26 -import org.onosproject.net.PortNumber;
27 -import org.onosproject.net.behaviour.LambdaQuery;
28 import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; 21 import org.onosproject.openflow.controller.OpenFlowOpticalSwitch;
29 import org.onosproject.openflow.controller.PortDescPropertyType; 22 import org.onosproject.openflow.controller.PortDescPropertyType;
30 import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; 23 import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
...@@ -48,10 +41,7 @@ import java.io.IOException; ...@@ -48,10 +41,7 @@ import java.io.IOException;
48 import java.util.ArrayList; 41 import java.util.ArrayList;
49 import java.util.List; 42 import java.util.List;
50 import java.util.Set; 43 import java.util.Set;
51 -import java.util.SortedSet;
52 import java.util.concurrent.atomic.AtomicBoolean; 44 import java.util.concurrent.atomic.AtomicBoolean;
53 -import java.util.stream.Collectors;
54 -import java.util.stream.IntStream;
55 45
56 /** 46 /**
57 * Driver for Calient S160 Optical Circuit Switch. Untested on Calient S320 but probably works ok. 47 * Driver for Calient S160 Optical Circuit Switch. Untested on Calient S320 but probably works ok.
...@@ -59,12 +49,9 @@ import java.util.stream.IntStream; ...@@ -59,12 +49,9 @@ import java.util.stream.IntStream;
59 * Driver implements custom handshaker, and rewrites flow stats as expected by the device. Port stats are currently 49 * Driver implements custom handshaker, and rewrites flow stats as expected by the device. Port stats are currently
60 * not supported. 50 * not supported.
61 * 51 *
62 - * The device consists of OMS ports only, and each port exposes lambda resources covering the whole 52 + * The device consists of OMS ports only.
63 - * usable optical spectrum (U to O band, see {@link Spectrum} for spectrum definitions).
64 */ 53 */
65 -public class CalientFiberSwitchHandshaker 54 +public class CalientFiberSwitchHandshaker extends AbstractOpenFlowSwitch implements OpenFlowOpticalSwitch {
66 - extends AbstractOpenFlowSwitch
67 - implements OpenFlowOpticalSwitch, LambdaQuery {
68 55
69 private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false); 56 private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false);
70 private List<OFCalientPortDescStatsEntry> fiberPorts = new ArrayList<>(); 57 private List<OFCalientPortDescStatsEntry> fiberPorts = new ArrayList<>();
...@@ -198,20 +185,4 @@ public class CalientFiberSwitchHandshaker ...@@ -198,20 +185,4 @@ public class CalientFiberSwitchHandshaker
198 185
199 super.sendMsg(newMsg); 186 super.sendMsg(newMsg);
200 } 187 }
201 -
202 - @Override
203 - public SortedSet<OchSignal> queryLambdas(PortNumber port) {
204 - // S160 data sheet
205 - // Wavelength range: 1260 - 1630 nm
206 - long startSpacingMultiplier = Spectrum.U_BAND_MIN.subtract(Spectrum.CENTER_FREQUENCY).asHz() /
207 - ChannelSpacing.CHL_12P5GHZ.frequency().asHz();
208 - long stopSpacingMultiplier = Spectrum.O_BAND_MAX.subtract(Spectrum.CENTER_FREQUENCY).asHz() /
209 - ChannelSpacing.CHL_12P5GHZ.frequency().asHz();
210 -
211 - // Only consider odd values for the multiplier (for easy mapping to fixed grid)
212 - return IntStream.rangeClosed((int) startSpacingMultiplier, (int) stopSpacingMultiplier)
213 - .filter(i -> i % 2 == 1)
214 - .mapToObj(i -> new OchSignal(GridType.FLEX, ChannelSpacing.CHL_6P25GHZ, i, 1))
215 - .collect(Collectors.toCollection(DefaultOchSignalComparator::newOchSignalTreeSet));
216 - }
217 } 188 }
......
...@@ -16,13 +16,7 @@ ...@@ -16,13 +16,7 @@
16 package org.onosproject.driver.handshaker; 16 package org.onosproject.driver.handshaker;
17 17
18 import com.google.common.collect.ImmutableSet; 18 import com.google.common.collect.ImmutableSet;
19 -import org.onosproject.net.ChannelSpacing;
20 -import org.onosproject.net.DefaultOchSignalComparator;
21 import org.onosproject.net.Device; 19 import org.onosproject.net.Device;
22 -import org.onosproject.net.GridType;
23 -import org.onosproject.net.OchSignal;
24 -import org.onosproject.net.PortNumber;
25 -import org.onosproject.net.behaviour.LambdaQuery;
26 import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; 20 import org.onosproject.openflow.controller.OpenFlowOpticalSwitch;
27 import org.onosproject.openflow.controller.PortDescPropertyType; 21 import org.onosproject.openflow.controller.PortDescPropertyType;
28 import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; 22 import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
...@@ -56,10 +50,7 @@ import java.util.Collections; ...@@ -56,10 +50,7 @@ import java.util.Collections;
56 import java.util.LinkedList; 50 import java.util.LinkedList;
57 import java.util.List; 51 import java.util.List;
58 import java.util.Set; 52 import java.util.Set;
59 -import java.util.SortedSet;
60 import java.util.concurrent.atomic.AtomicBoolean; 53 import java.util.concurrent.atomic.AtomicBoolean;
61 -import java.util.stream.Collectors;
62 -import java.util.stream.IntStream;
63 54
64 /** 55 /**
65 * LINC-OE Optical Emulator switch class. 56 * LINC-OE Optical Emulator switch class.
...@@ -72,14 +63,9 @@ import java.util.stream.IntStream; ...@@ -72,14 +63,9 @@ import java.util.stream.IntStream;
72 * 63 *
73 * As LINC implements custom OF optical extensions (in contrast to the final standard as specified in 64 * As LINC implements custom OF optical extensions (in contrast to the final standard as specified in
74 * ONF TS-022 (March 15, 2015), we need to rewrite flow stat requests and flow mods in {@link #sendMsg(OFMessage)}. 65 * ONF TS-022 (March 15, 2015), we need to rewrite flow stat requests and flow mods in {@link #sendMsg(OFMessage)}.
75 - *
76 - * LINC exposes OchSignal resources: 80 lambdas of 50 GHz (fixed grid) around ITU-T G.694.1 center frequency 193.1 GHz.
77 - *
78 */ 66 */
79 -public class OfOpticalSwitchImplLinc13 67 +public class OfOpticalSwitchImplLinc13 extends AbstractOpenFlowSwitch implements OpenFlowOpticalSwitch {
80 - extends AbstractOpenFlowSwitch implements OpenFlowOpticalSwitch, LambdaQuery {
81 68
82 - private static final int LAMBDA_COUNT = 80;
83 private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false); 69 private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false);
84 private long barrierXidToWaitFor = -1; 70 private long barrierXidToWaitFor = -1;
85 71
...@@ -361,17 +347,4 @@ public class OfOpticalSwitchImplLinc13 ...@@ -361,17 +347,4 @@ public class OfOpticalSwitchImplLinc13
361 public Set<PortDescPropertyType> getPortTypes() { 347 public Set<PortDescPropertyType> getPortTypes() {
362 return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT); 348 return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT);
363 } 349 }
364 -
365 - @Override
366 - public SortedSet<OchSignal> queryLambdas(PortNumber port) {
367 - // OCh ports don't have lambdas
368 - if (isOChPort(port.toLong())) {
369 - return Collections.emptySortedSet();
370 - }
371 -
372 - // OMS ports expose 80 fixed grid lambdas of 50GHz width, centered around the ITU-T center frequency 193.1 THz.
373 - return IntStream.range(0, LAMBDA_COUNT)
374 - .mapToObj(x -> new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, x - (LAMBDA_COUNT / 2), 4))
375 - .collect(Collectors.toCollection(DefaultOchSignalComparator::newOchSignalTreeSet));
376 - }
377 } 350 }
......
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.Spectrum;
19 +import org.onosproject.net.ChannelSpacing;
20 +import org.onosproject.net.GridType;
21 +import org.onosproject.net.OchSignal;
22 +import org.onosproject.net.PortNumber;
23 +import org.onosproject.net.behaviour.LambdaQuery;
24 +import org.onosproject.net.driver.AbstractHandlerBehaviour;
25 +
26 +import java.util.Set;
27 +import java.util.stream.Collectors;
28 +import java.util.stream.IntStream;
29 +
30 +/**
31 + * Lambda query implementation for Calient S160 and S320 Optical Circuit Switch.
32 + *
33 + * The device consists of OMS ports only, and each port exposes lambda resources covering the whole
34 + * usable optical spectrum (U to O band, see {@link Spectrum} for spectrum definitions).
35 + */
36 +public class CalientLambdaQuery extends AbstractHandlerBehaviour implements LambdaQuery {
37 +
38 + @Override
39 + public Set<OchSignal> queryLambdas(PortNumber port) {
40 + // S160 data sheet
41 + // Wavelength range: 1260 - 1630 nm
42 + long startSpacingMultiplier = Spectrum.U_BAND_MIN.subtract(Spectrum.CENTER_FREQUENCY).asHz() /
43 + ChannelSpacing.CHL_12P5GHZ.frequency().asHz();
44 + long stopSpacingMultiplier = Spectrum.O_BAND_MAX.subtract(Spectrum.CENTER_FREQUENCY).asHz() /
45 + ChannelSpacing.CHL_12P5GHZ.frequency().asHz();
46 +
47 + // Only consider odd values for the multiplier (for easy mapping to fixed grid)
48 + return IntStream.rangeClosed((int) startSpacingMultiplier, (int) stopSpacingMultiplier)
49 + .filter(i -> i % 2 == 1)
50 + .mapToObj(i -> new OchSignal(GridType.FLEX, ChannelSpacing.CHL_6P25GHZ, i, 1))
51 + .collect(Collectors.toSet());
52 + }
53 +}
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.onosproject.net.ChannelSpacing;
19 +import org.onosproject.net.GridType;
20 +import org.onosproject.net.OchSignal;
21 +import org.onosproject.net.Port;
22 +import org.onosproject.net.PortNumber;
23 +import org.onosproject.net.behaviour.LambdaQuery;
24 +import org.onosproject.net.device.DeviceService;
25 +import org.onosproject.net.driver.AbstractHandlerBehaviour;
26 +
27 +import java.util.Collections;
28 +import java.util.Set;
29 +import java.util.stream.Collectors;
30 +import java.util.stream.IntStream;
31 +
32 +/**
33 + * Lambda query implementation for LINC-OE Optical Emulator switch.
34 + *
35 + * The LINC ROADM emulator exposes two types of ports: OCh ports connect to ports in the packet layer,
36 + * while OMS ports connect to an OMS port on a neighbouring ROADM.
37 + *
38 + * LINC exposes OchSignal resources: 80 lambdas of 50 GHz (fixed grid) around ITU-T G.694.1 center frequency 193.1 GHz.
39 + */
40 +
41 +public class LincOELambdaQuery extends AbstractHandlerBehaviour implements LambdaQuery {
42 +
43 + private static final int LAMBDA_COUNT = 80;
44 +
45 + @Override
46 + public Set<OchSignal> queryLambdas(PortNumber port) {
47 + DeviceService deviceService = this.handler().get(DeviceService.class);
48 + Port p = deviceService.getPort(this.data().deviceId(), port);
49 +
50 + // OCh ports don't expose lambda resources
51 + if (!p.type().equals(Port.Type.OMS)) {
52 + return Collections.emptySet();
53 + }
54 +
55 + // OMS ports expose 80 fixed grid lambdas of 50GHz width, centered around the ITU-T center frequency 193.1 THz.
56 + return IntStream.range(0, LAMBDA_COUNT)
57 + .mapToObj(x -> new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, x - (LAMBDA_COUNT / 2), 4))
58 + .collect(Collectors.toSet());
59 + }
60 +}
...@@ -15,6 +15,6 @@ ...@@ -15,6 +15,6 @@
15 */ 15 */
16 16
17 /** 17 /**
18 - * Implementations of the query driver behaviours. 18 + * Implementations of the resource query behaviours.
19 */ 19 */
20 package org.onosproject.driver.query; 20 package org.onosproject.driver.query;
......
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
85 <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" 85 <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
86 impl="org.onosproject.driver.handshaker.OfOpticalSwitchImplLinc13"/> 86 impl="org.onosproject.driver.handshaker.OfOpticalSwitchImplLinc13"/>
87 <behaviour api="org.onosproject.net.behaviour.LambdaQuery" 87 <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
88 - impl="org.onosproject.driver.handshaker.OfOpticalSwitchImplLinc13"/> 88 + impl="org.onosproject.driver.query.LincOELambdaQuery"/>
89 </driver> 89 </driver>
90 <driver name="corsa" 90 <driver name="corsa"
91 manufacturer="Corsa" hwVersion="Corsa Element" swVersion="2.3.1"> 91 manufacturer="Corsa" hwVersion="Corsa Element" swVersion="2.3.1">
...@@ -162,7 +162,7 @@ ...@@ -162,7 +162,7 @@
162 <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" 162 <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
163 impl="org.onosproject.driver.handshaker.CalientFiberSwitchHandshaker"/> 163 impl="org.onosproject.driver.handshaker.CalientFiberSwitchHandshaker"/>
164 <behaviour api="org.onosproject.net.behaviour.LambdaQuery" 164 <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
165 - impl="org.onosproject.driver.handshaker.CalientFiberSwitchHandshaker"/> 165 + impl="org.onosproject.driver.query.CalientLambdaQuery"/>
166 </driver> 166 </driver>
167 <driver name="onosfw" extends="ovs" 167 <driver name="onosfw" extends="ovs"
168 manufacturer="" hwVersion="" swVersion=""> 168 manufacturer="" hwVersion="" swVersion="">
......