blob: d8570c1a825472dfbf078b2d5546940d2c7c2364 [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 org.onosproject.net.OchSignal;
19
Marc De Leenheer49087752014-10-23 13:54:09 -070020import java.util.Objects;
21
22public abstract class L0ModificationInstruction implements Instruction {
23
Sho SHIMIZU602edca2016-03-11 17:20:38 -080024 private static final String SEPARATOR = ":";
Jonathan Hartc7840bd2016-01-21 23:26:29 -080025
Marc De Leenheer49087752014-10-23 13:54:09 -070026 /**
27 * Represents the type of traffic treatment.
28 */
29 public enum L0SubType {
30 /**
31 * Lambda modification.
32 */
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070033 LAMBDA,
34 /**
35 * OCh (Optical Channel) modification.
36 */
37 OCH,
Marc De Leenheer49087752014-10-23 13:54:09 -070038 }
39
40 public abstract L0SubType subtype();
41
42 @Override
Yuta HIGUCHI6a479642015-02-08 01:28:50 -080043 public final Type type() {
Marc De Leenheer49087752014-10-23 13:54:09 -070044 return Type.L0MODIFICATION;
45 }
46
47 /**
48 * Represents a L0 lambda modification instruction.
49 */
50 public static final class ModLambdaInstruction extends L0ModificationInstruction {
51
52 private final L0SubType subtype;
53 private final short lambda;
54
Yuta HIGUCHI6a479642015-02-08 01:28:50 -080055 ModLambdaInstruction(L0SubType subType, short lambda) {
Marc De Leenheer49087752014-10-23 13:54:09 -070056 this.subtype = subType;
57 this.lambda = lambda;
58 }
59
60 @Override
61 public L0SubType subtype() {
62 return this.subtype;
63 }
64
65 public short lambda() {
66 return this.lambda;
67 }
68
69 @Override
70 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -080071 return subtype().toString() + SEPARATOR + lambda;
Marc De Leenheer49087752014-10-23 13:54:09 -070072 }
73
74 @Override
75 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -080076 return Objects.hash(type(), subtype, lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -070077 }
78
79 @Override
80 public boolean equals(Object obj) {
81 if (this == obj) {
82 return true;
83 }
84 if (obj instanceof ModLambdaInstruction) {
85 ModLambdaInstruction that = (ModLambdaInstruction) obj;
86 return Objects.equals(lambda, that.lambda) &&
Marc De Leenheer49087752014-10-23 13:54:09 -070087 Objects.equals(subtype, that.subtype);
88 }
89 return false;
90 }
91 }
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070092
93 /**
94 * Represents an L0 OCh (Optical Channel) modification instruction.
95 */
96 public static final class ModOchSignalInstruction extends L0ModificationInstruction {
97
98 private final OchSignal lambda;
99
100 ModOchSignalInstruction(OchSignal lambda) {
101 this.lambda = lambda;
102 }
103
104 @Override
105 public L0SubType subtype() {
106 return L0SubType.OCH;
107 }
108
109 public OchSignal lambda() {
110 return lambda;
111 }
112
113 @Override
114 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -0700115 return lambda.hashCode();
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700116 }
117
118 @Override
119 public boolean equals(Object obj) {
120 if (this == obj) {
121 return true;
122 }
123 if (!(obj instanceof ModOchSignalInstruction)) {
124 return false;
125 }
126 final ModOchSignalInstruction that = (ModOchSignalInstruction) obj;
127 return Objects.equals(this.lambda, that.lambda);
128 }
129
130 @Override
131 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -0800132 return subtype().toString() + SEPARATOR + lambda;
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700133 }
134 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700135}