Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow.instructions; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 17 | |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.onosproject.net.OchSignal; |
| 20 | |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 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 | */ |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 34 | LAMBDA, |
| 35 | /** |
| 36 | * OCh (Optical Channel) modification. |
| 37 | */ |
| 38 | OCH, |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | public abstract L0SubType subtype(); |
| 42 | |
| 43 | @Override |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 44 | public final Type type() { |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 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 | |
Yuta HIGUCHI | 6a47964 | 2015-02-08 01:28:50 -0800 | [diff] [blame] | 56 | ModLambdaInstruction(L0SubType subType, short lambda) { |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 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() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 78 | return Objects.hash(type(), subtype, lambda); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 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) && |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 89 | Objects.equals(subtype, that.subtype); |
| 90 | } |
| 91 | return false; |
| 92 | } |
| 93 | } |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 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() { |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 117 | return lambda.hashCode(); |
Sho SHIMIZU | e9e1275 | 2015-05-05 14:45:40 -0700 | [diff] [blame] | 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 | } |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 139 | } |