a6e5903cc55e52fd0fb186d027138a3fd8a91e7c
[onosfw.git] /
1 /*
2  * Copyright 2014-2015 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  */
16 package org.onosproject.net.flow.instructions;
17
18 import com.google.common.base.MoreObjects;
19 import org.onosproject.net.OchSignal;
20
21 import static com.google.common.base.MoreObjects.toStringHelper;
22
23 import java.util.Objects;
24
25 public abstract class L0ModificationInstruction implements Instruction {
26
27     /**
28      * Represents the type of traffic treatment.
29      */
30     public enum L0SubType {
31         /**
32          * Lambda modification.
33          */
34         LAMBDA,
35         /**
36          * OCh (Optical Channel) modification.
37          */
38         OCH,
39     }
40
41     public abstract L0SubType subtype();
42
43     @Override
44     public final Type type() {
45         return Type.L0MODIFICATION;
46     }
47
48     /**
49      * Represents a L0 lambda modification instruction.
50      */
51     public static final class ModLambdaInstruction extends L0ModificationInstruction {
52
53         private final L0SubType subtype;
54         private final short lambda;
55
56         ModLambdaInstruction(L0SubType subType, short lambda) {
57             this.subtype = subType;
58             this.lambda = lambda;
59         }
60
61         @Override
62         public L0SubType subtype() {
63             return this.subtype;
64         }
65
66         public short lambda() {
67             return this.lambda;
68         }
69
70         @Override
71         public String toString() {
72             return toStringHelper(subtype().toString())
73                     .add("lambda", lambda).toString();
74         }
75
76         @Override
77         public int hashCode() {
78             return Objects.hash(type(), subtype, lambda);
79         }
80
81         @Override
82         public boolean equals(Object obj) {
83             if (this == obj) {
84                 return true;
85             }
86             if (obj instanceof ModLambdaInstruction) {
87                 ModLambdaInstruction that = (ModLambdaInstruction) obj;
88                 return  Objects.equals(lambda, that.lambda) &&
89                         Objects.equals(subtype, that.subtype);
90             }
91             return false;
92         }
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     }
139 }