Introduce standard C-band lambda queries for transponders (ONOS-6496)

Change-Id: Id18cf450880de8bd91499019c287589c6bf26233
diff --git a/drivers/ciena/src/main/resources/ciena-drivers.xml b/drivers/ciena/src/main/resources/ciena-drivers.xml
index ff65d82..b1334d4 100644
--- a/drivers/ciena/src/main/resources/ciena-drivers.xml
+++ b/drivers/ciena/src/main/resources/ciena-drivers.xml
@@ -15,11 +15,14 @@
   ~ limitations under the License.
   -->
 <drivers>
+    <!-- Waveserver supports flex grid, although this driver only enables 50 GHz fixed grid. -->
     <driver name="restCiena" manufacturer="Ciena" hwVersion="1.0.0" swVersion="1.0.0">
         <behaviour api="org.onosproject.net.optical.OpticalDevice"
                    impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
         <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
                    impl="org.onosproject.drivers.ciena.CienaWaveserverDeviceDescription"/>
+        <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
+                   impl="org.onosproject.driver.optical.query.CBand50LambdaQuery"/>
     </driver>
 </drivers>
 
diff --git a/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml b/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml
index 233560c..620911c 100644
--- a/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml
+++ b/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml
@@ -15,11 +15,15 @@
   ~ limitations under the License.
   -->
 <drivers>
+    <!-- T100 supports 96 (50 GHz) or 128 (37.5 GHz) C-band channels,
+     although this driver only enables 80 50 GHz channels. -->
     <driver name="fujitsu-netconf" manufacturer="Fujitsu" hwVersion="T100" swVersion="01-01-X">
         <behaviour api="org.onosproject.net.optical.OpticalDevice"
                    impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
         <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
                    impl="org.onosproject.drivers.fujitsu.FujitsuT100DeviceDescription"/>
+        <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
+                   impl="org.onosproject.driver.optical.query.CBand50LambdaQuery"/>
     </driver>
     <driver name="fujitsu-volt-netconf" manufacturer="Fujitsu" hwVersion="svkOLT" swVersion="v1.0">
         <behaviour api="org.onosproject.net.behaviour.ControllerConfig"
diff --git a/drivers/lumentum/src/main/resources/lumentum-drivers.xml b/drivers/lumentum/src/main/resources/lumentum-drivers.xml
index d8ec9cd..628ee7e 100644
--- a/drivers/lumentum/src/main/resources/lumentum-drivers.xml
+++ b/drivers/lumentum/src/main/resources/lumentum-drivers.xml
@@ -34,7 +34,8 @@
                    impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
         <behaviour api="org.onosproject.net.flow.FlowRuleProgrammable"
                    impl="org.onosproject.driver.optical.config.ConfigFlowRuleProgrammable"/>
-
+        <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
+                   impl="org.onosproject.driver.optical.query.CBand50LambdaQuery"/>
     </driver>
 </drivers>
 
diff --git a/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBand100LambdaQuery.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBand100LambdaQuery.java
new file mode 100644
index 0000000..5ead68f
--- /dev/null
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBand100LambdaQuery.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.driver.optical.query;
+
+import org.onosproject.net.ChannelSpacing;
+import org.onosproject.net.OchSignal;
+import org.onosproject.net.PortNumber;
+
+import java.util.Set;
+
+/**
+ * C-band DWDM channel plan for 100 GHz fixed grid and centered around 193.1 GHz.
+ *
+ * This supports up to 40 optical channels.
+ */
+public class CBand100LambdaQuery extends CBandLambdaQuery {
+    @Override
+    public Set<OchSignal> queryLambdas(PortNumber port) {
+        channelSpacing = ChannelSpacing.CHL_100GHZ;
+        lambdaCount = 40;
+        slotGranularity = 8;
+
+        return super.queryLambdas(port);
+    }
+}
diff --git a/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBand25LambdaQuery.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBand25LambdaQuery.java
new file mode 100644
index 0000000..171bae3
--- /dev/null
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBand25LambdaQuery.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.driver.optical.query;
+
+import org.onosproject.net.ChannelSpacing;
+import org.onosproject.net.OchSignal;
+import org.onosproject.net.PortNumber;
+
+import java.util.Set;
+
+/**
+ * C-band DWDM channel plan for 25 GHz fixed grid and centered around 193.1 GHz.
+ *
+ * This supports up to 160 optical channels.
+ */
+public class CBand25LambdaQuery extends CBandLambdaQuery {
+    @Override
+    public Set<OchSignal> queryLambdas(PortNumber port) {
+        channelSpacing = ChannelSpacing.CHL_25GHZ;
+        lambdaCount = 160;
+        slotGranularity = 2;
+
+        return super.queryLambdas(port);
+    }
+}
diff --git a/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBand50LambdaQuery.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBand50LambdaQuery.java
new file mode 100644
index 0000000..b412f51
--- /dev/null
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBand50LambdaQuery.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.driver.optical.query;
+
+import org.onosproject.net.ChannelSpacing;
+import org.onosproject.net.OchSignal;
+import org.onosproject.net.PortNumber;
+
+import java.util.Set;
+
+/**
+ * C-band DWDM channel plan for 50 GHz fixed grid and centered around 193.1 GHz.
+ *
+ * This supports up to 80 optical channels.
+ */
+public class CBand50LambdaQuery extends CBandLambdaQuery {
+    @Override
+    public Set<OchSignal> queryLambdas(PortNumber port) {
+        channelSpacing = ChannelSpacing.CHL_50GHZ;
+        lambdaCount = 80;
+        slotGranularity = 4;
+
+        return super.queryLambdas(port);
+    }
+}
diff --git a/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBandLambdaQuery.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBandLambdaQuery.java
new file mode 100644
index 0000000..b5af6f5
--- /dev/null
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/CBandLambdaQuery.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.driver.optical.query;
+
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.net.ChannelSpacing;
+import org.onosproject.net.GridType;
+import org.onosproject.net.OchSignal;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.behaviour.LambdaQuery;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+
+import java.util.Set;
+import java.util.stream.IntStream;
+
+/**
+ * Abstract C-band DWDM plan lambda query, this is a base class NOT meant to be used as driver.
+ *
+ * Instead, use the subclasses to access the fixed grid (25, 50 and 100 GHz) implementations.
+ */
+public abstract class CBandLambdaQuery extends AbstractHandlerBehaviour implements LambdaQuery {
+    protected ChannelSpacing channelSpacing;
+    protected int lambdaCount;
+    protected int slotGranularity;
+
+    @Override
+    public Set<OchSignal> queryLambdas(PortNumber port) {
+        return IntStream.range(0, lambdaCount)
+                .mapToObj(x -> new OchSignal(GridType.DWDM, channelSpacing, x - (lambdaCount / 2), slotGranularity))
+                .collect(ImmutableSet.toImmutableSet());
+    }
+}
diff --git a/drivers/optical/src/main/java/org/onosproject/driver/optical/query/LincOELambdaQuery.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/LincOELambdaQuery.java
deleted file mode 100644
index 4a86085..0000000
--- a/drivers/optical/src/main/java/org/onosproject/driver/optical/query/LincOELambdaQuery.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.driver.optical.query;
-
-import org.onosproject.net.ChannelSpacing;
-import org.onosproject.net.GridType;
-import org.onosproject.net.OchSignal;
-import org.onosproject.net.Port;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.behaviour.LambdaQuery;
-import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.driver.AbstractHandlerBehaviour;
-
-import com.google.common.collect.ImmutableSet;
-
-import java.util.Set;
-import java.util.stream.IntStream;
-
-/**
- * Lambda query implementation for LINC-OE Optical Emulator switch.
- *
- * The LINC ROADM emulator exposes two types of ports: OCh ports connect to ports in the packet layer,
- * while OMS ports connect to an OMS port on a neighbouring ROADM.
- *
- * LINC exposes OchSignal resources: 80 lambdas of 50 GHz (fixed grid) around ITU-T G.694.1 center frequency 193.1 GHz.
- */
-
-public class LincOELambdaQuery extends AbstractHandlerBehaviour implements LambdaQuery {
-
-    private static final int LAMBDA_COUNT = 80;
-
-    /**
-     * OMS ports expose 80 fixed grid lambdas of 50GHz width,
-     * centered around the ITU-T center frequency 193.1 THz.
-     */
-    private static final Set<OchSignal> OMS_LAMBDAS = IntStream.range(0, LAMBDA_COUNT)
-            .mapToObj(x -> new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, x - (LAMBDA_COUNT / 2), 4))
-            .collect(ImmutableSet.toImmutableSet());
-
-    @Override
-    public Set<OchSignal> queryLambdas(PortNumber port) {
-        DeviceService deviceService = this.handler().get(DeviceService.class);
-
-        Port p = deviceService.getPort(this.data().deviceId(), port);
-
-        // OCh ports don't expose lambda resources
-        if (p == null ||
-            !p.type().equals(Port.Type.OMS)) {
-            return ImmutableSet.of();
-        }
-
-        return OMS_LAMBDAS;
-    }
-}
diff --git a/drivers/optical/src/main/resources/optical-drivers.xml b/drivers/optical/src/main/resources/optical-drivers.xml
index 35563e0..344436e 100644
--- a/drivers/optical/src/main/resources/optical-drivers.xml
+++ b/drivers/optical/src/main/resources/optical-drivers.xml
@@ -21,7 +21,7 @@
         <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
                    impl="org.onosproject.driver.optical.handshaker.OfOpticalSwitchImplLinc13"/>
         <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
-                   impl="org.onosproject.driver.optical.query.LincOELambdaQuery"/>
+                   impl="org.onosproject.driver.optical.query.CBand50LambdaQuery"/>
         <behaviour api="org.onosproject.net.optical.OpticalDevice"
                    impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
     </driver>