[Emu] Defining classes for ODU SIGID and SIGTYPE Fields in Flow Criteria and Instruction - Data Model and Tests only

Change-Id: I3a71520caa286a1fcc509c581036ef4848de9b5b
diff --git a/core/api/src/main/java/org/onosproject/net/OduSignalId.java b/core/api/src/main/java/org/onosproject/net/OduSignalId.java
new file mode 100644
index 0000000..e19a673
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/OduSignalId.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2015 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.net;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+import org.onlab.util.HexString;
+
+import com.google.common.base.MoreObjects;
+/**
+ * Implementation of ODU Signal ID.
+ *
+ * <p>
+ * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)".
+ * </p>
+ */
+public class OduSignalId {
+
+    private final int tributaryPortNumber;     // Tributary Port number
+    private final int tributarySlotLength;        // Number of Tributary Slots included in tsmap
+    private final byte[] tributarySlotBitmap; // Tributary slot bitmap
+
+    public static final int TRIBUTARY_SLOT_BITMAP_SIZE = 10;
+
+    /**
+     * Creates an instance with the specified arguments.
+     *
+     * @param tributaryPortNumber   tributary port number
+     * @param tributarySlotLen      tributary slot len
+     * @param tributarySlotBitmap   tributary slot bitmap
+     */
+    public OduSignalId(int tributaryPortNumber, int tributarySlotLen,
+            byte[] tributarySlotBitmap) {
+
+        checkArgument(tributaryPortNumber <= 80  ,
+                "tributaryPortNumber %s must be <= 80 ",
+                 tributaryPortNumber);
+
+        checkArgument(tributarySlotBitmap.length == TRIBUTARY_SLOT_BITMAP_SIZE,
+                "number of elements in list " + HexString.toHexString(tributarySlotBitmap)
+                + " must be equal to " + TRIBUTARY_SLOT_BITMAP_SIZE);
+
+        checkArgument(tributarySlotLen <= 80  ,
+                "tributarySlotLen %s must be <= 80 ",
+                tributarySlotLen);
+
+        this.tributaryPortNumber = tributaryPortNumber;
+        this.tributarySlotLength = tributarySlotLen;
+        this.tributarySlotBitmap = Arrays.copyOf(tributarySlotBitmap, tributarySlotBitmap.length);
+    }
+
+    /**
+     * Returns the OduSignalId representing the specified parameters.
+     *
+     * @param tributaryPortNumber   tributary port number
+     * @param tributarySlotLen      tributary slot len
+     * @param tributarySlotBitmap   tributary slot bitmap
+     * @return OduSignalId
+     */
+    public static OduSignalId oduSignalId(int tributaryPortNumber, int tributarySlotLen,
+            byte[] tributarySlotBitmap) {
+        return new OduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap);
+    }
+
+
+    /**
+     * Returns tributary port number.
+     *
+     * @return the tributaryPortNumber
+     */
+    public int tributaryPortNumber() {
+        return tributaryPortNumber;
+    }
+
+    /**
+     * Returns tributary slot length.
+     *
+     * @return the tributarySlotLen
+     */
+    public int tributarySlotLength() {
+        return tributarySlotLength;
+    }
+
+    /**
+     * Returns tributary slot bitmap.
+     *
+     * @return the tributarySlotBitmap
+     */
+    public byte[] tributarySlotBitmap() {
+        return Arrays.copyOf(tributarySlotBitmap, tributarySlotBitmap.length);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(tributaryPortNumber, tributarySlotLength, Arrays.hashCode(tributarySlotBitmap));
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof OduSignalId)) {
+            return false;
+        }
+        final OduSignalId other = (OduSignalId) obj;
+        return   Objects.equals(this.tributaryPortNumber, other.tributaryPortNumber)
+                 && Objects.equals(this.tributarySlotLength, other.tributarySlotLength)
+                 && Arrays.equals(tributarySlotBitmap, other.tributarySlotBitmap);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .omitNullValues()
+                .add("tributaryPortNumber", tributaryPortNumber)
+                .add("tributarySlotLength", tributarySlotLength)
+                .add("tributarySlotBitmap", HexString.toHexString(tributarySlotBitmap))
+                .toString();
+    }
+
+}
+
diff --git a/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java b/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
index 7e1d43a..ae940bd 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
@@ -25,6 +25,8 @@
 import org.onosproject.net.IndexedLambda;
 import org.onosproject.net.Lambda;
 import org.onosproject.net.OchSignal;
+import org.onosproject.net.OduSignalId;
+import org.onosproject.net.OduSignalType;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.criteria.Criterion.Type;
 import org.onosproject.net.OchSignalType;
@@ -486,6 +488,26 @@
         return new OchSignalTypeCriterion(signalType);
     }
 
+    /**
+     * Creates a match on ODU (Optical channel Data Unit) signal ID using the specified value.
+     *
+     * @param oduSignalId ODU Signal Id
+     * @return match criterion
+     */
+    public static Criterion matchOduSignalId(OduSignalId oduSignalId) {
+        return new OduSignalIdCriterion(oduSignalId);
+    }
+
+    /**
+     * Creates a match on ODU (Optical channel Data Unit) signal Type using the specified value.
+     *
+     * @param signalType ODU Signal Type
+     * @return match criterion
+     */
+    public static Criterion matchOduSignalType(OduSignalType signalType) {
+        return new OduSignalTypeCriterion(signalType);
+    }
+
     public static Criterion dummy() {
         return new DummyCriterion();
     }
diff --git a/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java b/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java
index 12ab57d..10cb629 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java
@@ -125,6 +125,10 @@
         OCH_SIGID,
         /** Optical channel signal type (fixed or flexible). */
         OCH_SIGTYPE,
+        /** ODU (Optical channel Data Unit) signal ID. */
+        ODU_SIGID,
+        /** ODU (Optical channel Data Unit) signal type. */
+        ODU_SIGTYPE,
 
         /**
          * An empty criterion.
diff --git a/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalIdCriterion.java b/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalIdCriterion.java
new file mode 100644
index 0000000..cb51339
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalIdCriterion.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2015 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.net.flow.criteria;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Objects;
+
+import org.onosproject.net.OduSignalId;
+
+/**
+ * Implementation of ODU (Optical channel Data Unit) signal ID signal criterion.
+ * This criterion is based on the specification of "OFPXMT_EXP_ODU_SIGID" in
+ * Open Networking Foundation "Optical Transport Protocol Extension Version 1.0", but
+ * defined in protocol agnostic way.
+ */
+public final class OduSignalIdCriterion implements Criterion {
+
+    private final OduSignalId oduSignalId;
+
+    /**
+     * Create an instance with the specified ODU signal ID.
+     *
+     * @param oduSignalId - ODU signal ID
+     */
+    OduSignalIdCriterion(OduSignalId oduSignalId) {
+        this.oduSignalId = checkNotNull(oduSignalId);
+    }
+
+    @Override
+    public Type type() {
+        return Type.ODU_SIGID;
+    }
+
+    /**
+     * Returns the ODU Signal to match.
+     *
+     * @return the ODU signal to match
+     */
+    public OduSignalId oduSignalId() {
+        return oduSignalId;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(type(), oduSignalId);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof OduSignalIdCriterion)) {
+            return false;
+        }
+        final OduSignalIdCriterion that = (OduSignalIdCriterion) obj;
+        return Objects.equals(this.oduSignalId, that.oduSignalId);
+    }
+
+    @Override
+    public String toString() {
+        return  toStringHelper(type().toString())
+                .add("oduSignalId", oduSignalId)
+                .toString();
+    }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalTypeCriterion.java b/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalTypeCriterion.java
new file mode 100644
index 0000000..d92880d
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalTypeCriterion.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2015 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.net.flow.criteria;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Objects;
+
+import org.onosproject.net.OduSignalType;
+
+/**
+ * Implementation of ODU (Optical channel Data Unit) signal Type criterion.
+ * This criterion is based on the specification of "OFPXMT_EXP_ODU_SIGTYPE" in
+ * Open Networking Foundation "Optical Transport Protocol Extension Version 1.0", but
+ * defined in protocol agnostic way.
+ */
+public final class OduSignalTypeCriterion implements Criterion {
+
+    private final OduSignalType signalType;
+
+    /**
+     * Create an instance with the specified ODU signal Type.
+     *
+     * @param signalType - ODU signal Type
+     */
+    OduSignalTypeCriterion(OduSignalType signalType) {
+        this.signalType = checkNotNull(signalType);
+    }
+
+    @Override
+    public Type type() {
+        return Type.ODU_SIGTYPE;
+    }
+
+    /**
+     * Returns the ODU Signal Type to match.
+     *
+     * @return the ODU signal Type to match
+     */
+    public OduSignalType signalType() {
+        return signalType;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(type(), signalType);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof OduSignalTypeCriterion)) {
+            return false;
+        }
+        final OduSignalTypeCriterion that = (OduSignalTypeCriterion) obj;
+        return Objects.equals(this.signalType, that.signalType);
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(type().toString())
+                .add("signalType", signalType)
+                .toString();
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java
index d01ea29..eddbbb7 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java
@@ -59,6 +59,11 @@
         L0MODIFICATION,
 
         /**
+         * Signifies that the traffic should be modified in L1 way.
+         */
+        L1MODIFICATION,
+
+        /**
          * Signifies that the traffic should be modified in L2 way.
          */
         L2MODIFICATION,
@@ -86,6 +91,7 @@
 
     /**
      * Returns the type of instruction.
+     *
      * @return type of instruction
      */
     Type type();
diff --git a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
index c9f1068..26981e5 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
@@ -25,10 +25,12 @@
 import org.onosproject.net.IndexedLambda;
 import org.onosproject.net.Lambda;
 import org.onosproject.net.OchSignal;
+import org.onosproject.net.OduSignalId;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType;
 import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
 import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction;
+import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction;
 import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
@@ -47,7 +49,6 @@
  */
 public final class Instructions {
 
-
     // Ban construction
     private Instructions() {}
 
@@ -117,6 +118,16 @@
     }
 
     /**
+     * Creates an L1 modification with the specified ODU signal Id.
+     *
+     * @param oduSignalId ODU Signal Id
+     * @return a L1 modification
+     */
+    public static L1ModificationInstruction modL1OduSignalId(OduSignalId oduSignalId) {
+        checkNotNull(oduSignalId, "L1 ODU signal ID cannot be null");
+        return new ModOduSignalIdInstruction(oduSignalId);
+    }
+    /**
      * Creates a l2 src modification.
      *
      * @param addr the mac address to modify to
diff --git a/core/api/src/main/java/org/onosproject/net/flow/instructions/L1ModificationInstruction.java b/core/api/src/main/java/org/onosproject/net/flow/instructions/L1ModificationInstruction.java
new file mode 100644
index 0000000..c6847d1
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/flow/instructions/L1ModificationInstruction.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2014-2015 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.net.flow.instructions;
+
+import org.onosproject.net.OduSignalId;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+import java.util.Objects;
+
+public abstract class L1ModificationInstruction implements Instruction {
+
+    /**
+     * Represents the type of traffic treatment.
+     */
+    public enum L1SubType {
+        /**
+         * ODU (Optical channel Data Unit) Signal Id modification.
+         */
+        ODU_SIGID
+    }
+
+    public abstract L1SubType subtype();
+
+    @Override
+    public final Type type() {
+        return Type.L1MODIFICATION;
+    }
+
+    /**
+     * Represents an L1 ODU (Optical channel Data Unit) Signal Id modification instruction.
+     */
+    public static final class ModOduSignalIdInstruction extends L1ModificationInstruction {
+
+        private final OduSignalId oduSignalId;
+
+        ModOduSignalIdInstruction(OduSignalId oduSignalId) {
+            this.oduSignalId = oduSignalId;
+        }
+
+        @Override
+        public L1SubType subtype() {
+            return L1SubType.ODU_SIGID;
+        }
+
+        public OduSignalId oduSignalId() {
+            return oduSignalId;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(oduSignalId);
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (!(obj instanceof ModOduSignalIdInstruction)) {
+                return false;
+            }
+            final ModOduSignalIdInstruction that = (ModOduSignalIdInstruction) obj;
+            return Objects.equals(this.oduSignalId, that.oduSignalId);
+        }
+
+        @Override
+        public String toString() {
+            return toStringHelper(this)
+                    .add("oduSignalId", oduSignalId)
+                    .toString();
+        }
+    }
+
+}