[ODTN] Support of multiple optical bands (L, C, and S band).
- patch 1: first commit
- patch 2: example driver, checkstyle
- patch 3,4,5: checkstyle
- patch 6,7: andrea's comments

Change-Id: I1f872e5df76073f427da8184c4f2a4e18dfbf4bb
diff --git a/core/api/src/main/java/org/onosproject/net/OpticalBandType.java b/core/api/src/main/java/org/onosproject/net/OpticalBandType.java
new file mode 100644
index 0000000..06b5b4f
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/OpticalBandType.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2023-present Open Networking Foundation
+ *
+ * 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.
+ *
+ * This Work is contributed by CNR within the B5G-OPEN project.
+ */
+
+package org.onosproject.net;
+
+
+/**
+ * Represents type of optical bands.
+ *
+ */
+public enum OpticalBandType {
+    L_BAND, // Starts at 184500 GHz ends at 191500 GHz
+    C_BAND, // Starts at 191500 GHz ends at 195500 GHz
+    S_BAND; // Starts at 195500 GHz ends at 205300 GHz
+}
+
diff --git a/core/api/src/main/java/org/onosproject/net/OpticalBandUtils.java b/core/api/src/main/java/org/onosproject/net/OpticalBandUtils.java
new file mode 100644
index 0000000..7f38492
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/OpticalBandUtils.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2023-present Open Networking Foundation
+ *
+ * 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.
+ *
+ * This Work is contributed by CNR within the B5G-OPEN project.
+ */
+
+package org.onosproject.net;
+
+import org.onlab.util.Frequency;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utils to manage OCH signal on multiple optical bands.
+ * Given an OCH signal it is mapped in one band.
+ * Start and End frequency for each band can be queried.
+ */
+public final class OpticalBandUtils {
+
+    private static final Logger log = LoggerFactory.getLogger(OpticalBandUtils.class);
+    private static final Frequency L_BAND_START_FREQ = Frequency.ofGHz(184500);
+    private static final Frequency L_BAND_STOP_FREQ = Frequency.ofGHz(191500);
+    private static final Frequency C_BAND_START_FREQ = Frequency.ofGHz(191500);
+    private static final Frequency C_BAND_STOP_FREQ = Frequency.ofGHz(195500);
+    private static final Frequency S_BAND_START_FREQ = Frequency.ofGHz(195500);
+    private static final Frequency S_BAND_STOP_FREQ = Frequency.ofGHz(205300);
+
+    // prohibit instantiation
+    private OpticalBandUtils() {}
+    /**
+     * Maps the provided OCH signal on optical band type.
+     *
+     * @param ochSignal signal to be mapped
+     * @return OpticalBandType band
+     */
+     public static OpticalBandType computeOpticalBand(OchSignal ochSignal) {
+        if (L_BAND_START_FREQ.isLessThan(ochSignal.centralFrequency())
+                && L_BAND_STOP_FREQ.isGreaterThan(ochSignal.centralFrequency())) {
+            return OpticalBandType.L_BAND;
+        }
+        if (C_BAND_START_FREQ.isLessThan(ochSignal.centralFrequency())
+                && C_BAND_STOP_FREQ.isGreaterThan(ochSignal.centralFrequency())) {
+            return OpticalBandType.C_BAND;
+        }
+        if (S_BAND_START_FREQ.isLessThan(ochSignal.centralFrequency())
+                && S_BAND_STOP_FREQ.isGreaterThan(ochSignal.centralFrequency())) {
+            return OpticalBandType.S_BAND;
+        }
+        return null;
+    }
+
+    /**
+     * Return the start frequency of the specified band.
+     *
+     * @param bandType band type to be considered
+     * @return Frequency
+     */
+    public static Frequency startFrequency(OpticalBandType bandType) {
+        switch (bandType) {
+            case L_BAND:
+                return L_BAND_START_FREQ;
+            case C_BAND:
+                return C_BAND_START_FREQ;
+            case S_BAND:
+                return S_BAND_START_FREQ;
+            default:
+                log.error("Unsupported OpticalBandType {}", bandType);
+                return null;
+        }
+    }
+
+    /**
+     * Return the end frequency of the specified band.
+     *
+     * @param bandType band type to be considered
+     * @return Frequency
+     */
+    public static Frequency stopFrequency(OpticalBandType bandType) {
+        switch (bandType) {
+            case L_BAND:
+                return L_BAND_STOP_FREQ;
+            case C_BAND:
+                return C_BAND_STOP_FREQ;
+            case S_BAND:
+                return S_BAND_STOP_FREQ;
+            default:
+                log.error("Unsupported OpticalBandType {}", bandType);
+                return null;
+        }
+    }
+}
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/openconfig/MultiBand10LambdaQuery.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/openconfig/MultiBand10LambdaQuery.java
new file mode 100644
index 0000000..3d810f0
--- /dev/null
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/openconfig/MultiBand10LambdaQuery.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2023-present Open Networking Foundation
+ *
+ * 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.
+ *
+ * This Work is contributed by CNR within the B5G-OPEN project.
+ */
+
+package org.onosproject.drivers.odtn.openconfig;
+
+import org.onosproject.driver.optical.query.MultiBandLambdaQuery;
+import org.onosproject.net.ChannelSpacing;
+import org.onosproject.net.OchSignal;
+import org.onosproject.net.PortNumber;
+import org.slf4j.Logger;
+
+import java.util.Set;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Example lambda query for multi-band optical devices.
+ */
+public class MultiBand10LambdaQuery extends MultiBandLambdaQuery {
+
+    protected static final Logger log = getLogger(TerminalDeviceLambdaQuery.class);
+
+    @Override
+    public Set<OchSignal> queryLambdas(PortNumber port) {
+        log.debug("OPENCONFIG: queried lambdas for port {}", port);
+
+        channelSpacing = ChannelSpacing.CHL_50GHZ;
+        slotGranularity = 4;
+
+        //Generates 10 channels on each band, each channel is 50 GHz width
+        lBandLambdaCount = 10;
+        cBandLambdaCount = 10;
+        sBandLambdaCount = 10;
+
+        return super.queryLambdas(port);
+    }
+}
+
diff --git a/drivers/optical/src/main/java/org/onosproject/driver/optical/query/MultiBandLambdaQuery.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/MultiBandLambdaQuery.java
new file mode 100644
index 0000000..19ab174
--- /dev/null
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/MultiBandLambdaQuery.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2023-present Open Networking Foundation
+ *
+ * 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.
+ *
+ * This Work is contributed by CNR within the B5G-OPEN project.
+ */
+
+package org.onosproject.driver.optical.query;
+
+import org.onlab.util.Frequency;
+import org.onosproject.net.ChannelSpacing;
+import org.onosproject.net.GridType;
+import org.onosproject.net.OchSignal;
+import org.onosproject.net.OpticalBandType;
+import org.onosproject.net.OpticalBandUtils;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.behaviour.LambdaQuery;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.optical.util.OpticalChannelUtility;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.onosproject.net.OpticalBandType.L_BAND;
+import static org.onosproject.net.OpticalBandType.C_BAND;
+import static org.onosproject.net.OpticalBandType.S_BAND;
+
+
+/**
+ * Abstract multi-band WDM plan lambda query, this is a base class NOT meant to be used as driver.
+ *
+ * It generates a fixed number of channel per band.
+ *
+ */
+public class MultiBandLambdaQuery extends AbstractHandlerBehaviour implements LambdaQuery {
+
+    protected ChannelSpacing channelSpacing;
+    protected int slotGranularity;
+
+    protected int lBandLambdaCount;
+    protected int cBandLambdaCount;
+    protected int sBandLambdaCount;
+
+    @Override
+    public Set<OchSignal> queryLambdas(PortNumber port) {
+
+        Set<OchSignal> lambdas = new HashSet<>();
+
+        addChannelsFromStartFreq(lambdas, L_BAND, lBandLambdaCount);
+        addChannelsFromStartFreq(lambdas, C_BAND, cBandLambdaCount);
+        addChannelsFromStartFreq(lambdas, S_BAND, sBandLambdaCount);
+
+        return lambdas;
+    }
+
+    /**
+     * Adds a number lambdaCount of new channels in band bandType to the set lambdas.
+     *
+     * @param lambdas
+     * @param bandType
+     * @param lambdaCount
+     */
+    private void addChannelsFromStartFreq(Set<OchSignal> lambdas, OpticalBandType bandType, int lambdaCount) {
+
+        Frequency startFreq = OpticalBandUtils.startFrequency(bandType);
+
+        for (int i = 0; i <= lambdaCount; i++) {
+            lambdas.add(OpticalChannelUtility.createOchSignalFromBounds(
+                    startFreq.add(channelSpacing.frequency().multiply(i)),
+                    startFreq.add(channelSpacing.frequency().multiply(i + 1)),
+                    GridType.DWDM,
+                    channelSpacing));
+        }
+    }
+}