Sho SHIMIZU

Make Instructions.modL0Lambda(short) deprecated

Integrate static factory method for indexed lambda and OCh

Change-Id: I80074f7ce2e1703a4ebc7d6f552b52bffc970193
...@@ -22,20 +22,29 @@ import com.google.common.base.MoreObjects; ...@@ -22,20 +22,29 @@ import com.google.common.base.MoreObjects;
22 */ 22 */
23 public class IndexedLambda implements Lambda { 23 public class IndexedLambda implements Lambda {
24 24
25 - private final long lambda; 25 + private final long index;
26 26
27 /** 27 /**
28 * Creates an instance representing the wavelength specified by the given index number. 28 * Creates an instance representing the wavelength specified by the given index number.
29 * 29 *
30 - * @param lambda index number of wavelength 30 + * @param index index number of wavelength
31 */ 31 */
32 - IndexedLambda(long lambda) { 32 + IndexedLambda(long index) {
33 - this.lambda = lambda; 33 + this.index = index;
34 + }
35 +
36 + /**
37 + * Returns the index number of lambda.
38 + *
39 + * @return the index number of lambda
40 + */
41 + public long index() {
42 + return index;
34 } 43 }
35 44
36 @Override 45 @Override
37 public int hashCode() { 46 public int hashCode() {
38 - return (int) (lambda ^ (lambda >>> 32)); 47 + return (int) (index ^ (index >>> 32));
39 } 48 }
40 49
41 @Override 50 @Override
...@@ -48,13 +57,13 @@ public class IndexedLambda implements Lambda { ...@@ -48,13 +57,13 @@ public class IndexedLambda implements Lambda {
48 } 57 }
49 58
50 final IndexedLambda that = (IndexedLambda) obj; 59 final IndexedLambda that = (IndexedLambda) obj;
51 - return this.lambda == that.lambda; 60 + return this.index == that.index;
52 } 61 }
53 62
54 @Override 63 @Override
55 public String toString() { 64 public String toString() {
56 return MoreObjects.toStringHelper(this) 65 return MoreObjects.toStringHelper(this)
57 - .add("lambda", lambda) 66 + .add("lambda", index)
58 .toString(); 67 .toString();
59 } 68 }
60 } 69 }
......
...@@ -21,10 +21,13 @@ import org.onlab.packet.MacAddress; ...@@ -21,10 +21,13 @@ 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.IndexedLambda;
25 +import org.onosproject.net.Lambda;
24 import org.onosproject.net.OchSignal; 26 import org.onosproject.net.OchSignal;
25 import org.onosproject.net.PortNumber; 27 import org.onosproject.net.PortNumber;
26 import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType; 28 import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType;
27 import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; 29 import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
30 +import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction;
28 import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; 31 import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
29 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; 32 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
30 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; 33 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
...@@ -81,7 +84,9 @@ public final class Instructions { ...@@ -81,7 +84,9 @@ public final class Instructions {
81 * 84 *
82 * @param lambda the lambda to modify to 85 * @param lambda the lambda to modify to
83 * @return a l0 modification 86 * @return a l0 modification
87 + * @deprecated in Cardinal Release. Use {@link #modL0Lambda(Lambda)} instead.
84 */ 88 */
89 + @Deprecated
85 public static L0ModificationInstruction modL0Lambda(short lambda) { 90 public static L0ModificationInstruction modL0Lambda(short lambda) {
86 checkNotNull(lambda, "L0 lambda cannot be null"); 91 checkNotNull(lambda, "L0 lambda cannot be null");
87 return new ModLambdaInstruction(L0SubType.LAMBDA, lambda); 92 return new ModLambdaInstruction(L0SubType.LAMBDA, lambda);
...@@ -93,9 +98,16 @@ public final class Instructions { ...@@ -93,9 +98,16 @@ public final class Instructions {
93 * @param lambda OCh signal 98 * @param lambda OCh signal
94 * @return an L0 modification 99 * @return an L0 modification
95 */ 100 */
96 - public static L0ModificationInstruction modL0OchSignal(OchSignal lambda) { 101 + public static L0ModificationInstruction modL0Lambda(Lambda lambda) {
97 checkNotNull(lambda, "L0 OCh signal cannot be null"); 102 checkNotNull(lambda, "L0 OCh signal cannot be null");
98 - return new L0ModificationInstruction.ModOchSignalInstruction(lambda); 103 +
104 + if (lambda instanceof IndexedLambda) {
105 + return new ModLambdaInstruction(L0SubType.LAMBDA, (short) ((IndexedLambda) lambda).index());
106 + } else if (lambda instanceof OchSignal) {
107 + return new ModOchSignalInstruction((OchSignal) lambda);
108 + } else {
109 + throw new UnsupportedOperationException(String.format("Unsupported type: %s", lambda));
110 + }
99 } 111 }
100 112
101 /** 113 /**
......