Sho SHIMIZU
Committed by Ray Milkey

Define an Instruction for OchSignal and its static factory method

Resolve ONOS-1873

Change-Id: Ia1d0a97fd820ce7a9b7e2b48ce8d07174bcc1af9
...@@ -21,6 +21,7 @@ import org.onlab.packet.MacAddress; ...@@ -21,6 +21,7 @@ import org.onlab.packet.MacAddress;
21 import org.onlab.packet.MplsLabel; 21 import org.onlab.packet.MplsLabel;
22 import org.onlab.packet.VlanId; 22 import org.onlab.packet.VlanId;
23 import org.onosproject.core.GroupId; 23 import org.onosproject.core.GroupId;
24 +import org.onosproject.net.OchSignal;
24 import org.onosproject.net.PortNumber; 25 import org.onosproject.net.PortNumber;
25 import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType; 26 import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType;
26 import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; 27 import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
...@@ -87,6 +88,17 @@ public final class Instructions { ...@@ -87,6 +88,17 @@ public final class Instructions {
87 } 88 }
88 89
89 /** 90 /**
91 + * Creates an L0 modification with the specified OCh signal.
92 + *
93 + * @param lambda OCh signal
94 + * @return an L0 modification
95 + */
96 + public static L0ModificationInstruction modL0OchSignal(OchSignal lambda) {
97 + checkNotNull(lambda, "L0 OCh signal cannot be null");
98 + return new L0ModificationInstruction.ModOchSignalInstruction(lambda);
99 + }
100 +
101 + /**
90 * Creates a l2 src modification. 102 * Creates a l2 src modification.
91 * 103 *
92 * @param addr the mac address to modify to 104 * @param addr the mac address to modify to
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
15 */ 15 */
16 package org.onosproject.net.flow.instructions; 16 package org.onosproject.net.flow.instructions;
17 17
18 +import com.google.common.base.MoreObjects;
19 +import org.onosproject.net.OchSignal;
20 +
18 import static com.google.common.base.MoreObjects.toStringHelper; 21 import static com.google.common.base.MoreObjects.toStringHelper;
19 22
20 import java.util.Objects; 23 import java.util.Objects;
...@@ -28,9 +31,11 @@ public abstract class L0ModificationInstruction implements Instruction { ...@@ -28,9 +31,11 @@ public abstract class L0ModificationInstruction implements Instruction {
28 /** 31 /**
29 * Lambda modification. 32 * Lambda modification.
30 */ 33 */
31 - LAMBDA 34 + LAMBDA,
32 - 35 + /**
33 - //TODO: remaining types 36 + * OCh (Optical Channel) modification.
37 + */
38 + OCH,
34 } 39 }
35 40
36 public abstract L0SubType subtype(); 41 public abstract L0SubType subtype();
...@@ -86,4 +91,49 @@ public abstract class L0ModificationInstruction implements Instruction { ...@@ -86,4 +91,49 @@ public abstract class L0ModificationInstruction implements Instruction {
86 return false; 91 return false;
87 } 92 }
88 } 93 }
94 +
95 + /**
96 + * Represents an L0 OCh (Optical Channel) modification instruction.
97 + */
98 + public static final class ModOchSignalInstruction extends L0ModificationInstruction {
99 +
100 + private final OchSignal lambda;
101 +
102 + ModOchSignalInstruction(OchSignal lambda) {
103 + this.lambda = lambda;
104 + }
105 +
106 + @Override
107 + public L0SubType subtype() {
108 + return L0SubType.OCH;
109 + }
110 +
111 + public OchSignal lambda() {
112 + return lambda;
113 + }
114 +
115 + @Override
116 + public int hashCode() {
117 + return Objects.hash(lambda);
118 + }
119 +
120 + @Override
121 + public boolean equals(Object obj) {
122 + if (this == obj) {
123 + return true;
124 + }
125 + if (!(obj instanceof ModOchSignalInstruction)) {
126 + return false;
127 + }
128 + final ModOchSignalInstruction that = (ModOchSignalInstruction) obj;
129 + return Objects.equals(this.lambda, that.lambda);
130 + }
131 +
132 + @Override
133 + public String toString() {
134 + return MoreObjects.toStringHelper(this)
135 + .add("lambda", lambda)
136 + .toString();
137 + }
138 + }
89 } 139 }
......