blob: 2f33ff9747cd85c0adde75d085dead755ce4d09c [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 /**
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070031 * OCh (Optical Channel) modification.
32 */
33 OCH,
Marc De Leenheer49087752014-10-23 13:54:09 -070034 }
35
36 public abstract L0SubType subtype();
37
38 @Override
Yuta HIGUCHI6a479642015-02-08 01:28:50 -080039 public final Type type() {
Marc De Leenheer49087752014-10-23 13:54:09 -070040 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
Yuta HIGUCHI6a479642015-02-08 01:28:50 -080051 ModLambdaInstruction(L0SubType subType, short lambda) {
Marc De Leenheer49087752014-10-23 13:54:09 -070052 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() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -080067 return subtype().toString() + SEPARATOR + lambda;
Marc De Leenheer49087752014-10-23 13:54:09 -070068 }
69
70 @Override
71 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -080072 return Objects.hash(type(), subtype, lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -070073 }
74
75 @Override
76 public boolean equals(Object obj) {
77 if (this == obj) {
78 return true;
79 }
80 if (obj instanceof ModLambdaInstruction) {
81 ModLambdaInstruction that = (ModLambdaInstruction) obj;
82 return Objects.equals(lambda, that.lambda) &&
Marc De Leenheer49087752014-10-23 13:54:09 -070083 Objects.equals(subtype, that.subtype);
84 }
85 return false;
86 }
87 }
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070088
89 /**
90 * Represents an L0 OCh (Optical Channel) modification instruction.
91 */
92 public static final class ModOchSignalInstruction extends L0ModificationInstruction {
93
94 private final OchSignal lambda;
95
96 ModOchSignalInstruction(OchSignal lambda) {
97 this.lambda = lambda;
98 }
99
100 @Override
101 public L0SubType subtype() {
102 return L0SubType.OCH;
103 }
104
105 public OchSignal lambda() {
106 return lambda;
107 }
108
109 @Override
110 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -0700111 return lambda.hashCode();
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700112 }
113
114 @Override
115 public boolean equals(Object obj) {
116 if (this == obj) {
117 return true;
118 }
119 if (!(obj instanceof ModOchSignalInstruction)) {
120 return false;
121 }
122 final ModOchSignalInstruction that = (ModOchSignalInstruction) obj;
123 return Objects.equals(this.lambda, that.lambda);
124 }
125
126 @Override
127 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -0800128 return subtype().toString() + SEPARATOR + lambda;
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700129 }
130 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700131}