blob: 4af3d1680aa7085746fa2aef95c37aeac4c5d224 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow.instructions;
Marc De Leenheer49087752014-10-23 13:54:09 -070017
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070018import com.google.common.base.MoreObjects;
19import org.onosproject.net.OchSignal;
20
Marc De Leenheer49087752014-10-23 13:54:09 -070021import static com.google.common.base.MoreObjects.toStringHelper;
22
23import java.util.Objects;
24
25public abstract class L0ModificationInstruction implements Instruction {
26
27 /**
28 * Represents the type of traffic treatment.
29 */
30 public enum L0SubType {
31 /**
32 * Lambda modification.
33 */
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070034 LAMBDA,
35 /**
36 * OCh (Optical Channel) modification.
37 */
38 OCH,
Marc De Leenheer49087752014-10-23 13:54:09 -070039 }
40
41 public abstract L0SubType subtype();
42
43 @Override
Yuta HIGUCHI6a479642015-02-08 01:28:50 -080044 public final Type type() {
Marc De Leenheer49087752014-10-23 13:54:09 -070045 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
Yuta HIGUCHI6a479642015-02-08 01:28:50 -080056 ModLambdaInstruction(L0SubType subType, short lambda) {
Marc De Leenheer49087752014-10-23 13:54:09 -070057 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() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -080078 return Objects.hash(type(), subtype, lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -070079 }
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) &&
Marc De Leenheer49087752014-10-23 13:54:09 -070089 Objects.equals(subtype, that.subtype);
90 }
91 return false;
92 }
93 }
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070094
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() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -0700117 return lambda.hashCode();
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700118 }
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 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700139}