blob: 0d5cd81c5da13d16d9824b186b66f63814d45e7a [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Marc De Leenheer49087752014-10-23 13:54:09 -070016package org.onlab.onos.net.flow.instructions;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19
20import java.util.Objects;
21
22public abstract class L0ModificationInstruction implements Instruction {
23
24 /**
25 * Represents the type of traffic treatment.
26 */
27 public enum L0SubType {
28 /**
29 * Lambda modification.
30 */
31 LAMBDA
32
33 //TODO: remaining types
34 }
35
36 public abstract L0SubType subtype();
37
38 @Override
39 public Type type() {
40 return Type.L0MODIFICATION;
41 }
42
43 /**
44 * Represents a L0 lambda modification instruction.
45 */
46 public static final class ModLambdaInstruction extends L0ModificationInstruction {
47
48 private final L0SubType subtype;
49 private final short lambda;
50
51 public ModLambdaInstruction(L0SubType subType, short lambda) {
52 this.subtype = subType;
53 this.lambda = lambda;
54 }
55
56 @Override
57 public L0SubType subtype() {
58 return this.subtype;
59 }
60
61 public short lambda() {
62 return this.lambda;
63 }
64
65 @Override
66 public String toString() {
67 return toStringHelper(subtype().toString())
68 .add("lambda", lambda).toString();
69 }
70
71 @Override
72 public int hashCode() {
73 return Objects.hash(lambda, type(), subtype);
74 }
75
76 @Override
77 public boolean equals(Object obj) {
78 if (this == obj) {
79 return true;
80 }
81 if (obj instanceof ModLambdaInstruction) {
82 ModLambdaInstruction that = (ModLambdaInstruction) obj;
83 return Objects.equals(lambda, that.lambda) &&
84 Objects.equals(this.type(), that.type()) &&
85 Objects.equals(subtype, that.subtype);
86 }
87 return false;
88 }
89 }
90}