Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.flow.instructions; |
| 2 | |
| 3 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 4 | |
| 5 | import java.util.Objects; |
| 6 | |
| 7 | public abstract class L0ModificationInstruction implements Instruction { |
| 8 | |
| 9 | /** |
| 10 | * Represents the type of traffic treatment. |
| 11 | */ |
| 12 | public enum L0SubType { |
| 13 | /** |
| 14 | * Lambda modification. |
| 15 | */ |
| 16 | LAMBDA |
| 17 | |
| 18 | //TODO: remaining types |
| 19 | } |
| 20 | |
| 21 | public abstract L0SubType subtype(); |
| 22 | |
| 23 | @Override |
| 24 | public Type type() { |
| 25 | return Type.L0MODIFICATION; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Represents a L0 lambda modification instruction. |
| 30 | */ |
| 31 | public static final class ModLambdaInstruction extends L0ModificationInstruction { |
| 32 | |
| 33 | private final L0SubType subtype; |
| 34 | private final short lambda; |
| 35 | |
| 36 | public ModLambdaInstruction(L0SubType subType, short lambda) { |
| 37 | this.subtype = subType; |
| 38 | this.lambda = lambda; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public L0SubType subtype() { |
| 43 | return this.subtype; |
| 44 | } |
| 45 | |
| 46 | public short lambda() { |
| 47 | return this.lambda; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public String toString() { |
| 52 | return toStringHelper(subtype().toString()) |
| 53 | .add("lambda", lambda).toString(); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public int hashCode() { |
| 58 | return Objects.hash(lambda, type(), subtype); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public boolean equals(Object obj) { |
| 63 | if (this == obj) { |
| 64 | return true; |
| 65 | } |
| 66 | if (obj instanceof ModLambdaInstruction) { |
| 67 | ModLambdaInstruction that = (ModLambdaInstruction) obj; |
| 68 | return Objects.equals(lambda, that.lambda) && |
| 69 | Objects.equals(this.type(), that.type()) && |
| 70 | Objects.equals(subtype, that.subtype); |
| 71 | } |
| 72 | return false; |
| 73 | } |
| 74 | } |
| 75 | } |