Jian Li | 136fd6c | 2017-02-10 14:54:59 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present 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.mapping.instructions; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | /** |
| 21 | * Abstraction of an action mapping instruction. |
| 22 | */ |
| 23 | public abstract class ActionMappingInstruction implements MappingInstruction { |
| 24 | |
| 25 | /** |
| 26 | * Represents the type of mapping action. |
| 27 | */ |
| 28 | public enum ActionType { |
| 29 | |
| 30 | /** |
| 31 | * Signifies that the traffic requires no action. |
| 32 | */ |
| 33 | NO_ACTION, |
| 34 | |
| 35 | /** |
| 36 | * Signifies that the traffic requires native forwarding. |
| 37 | */ |
| 38 | NATIVE_FORWARD, |
| 39 | |
| 40 | /** |
| 41 | * Signifies that the traffic requires forwarding with mapping information. |
| 42 | */ |
| 43 | FORWARD, |
| 44 | |
| 45 | /** |
| 46 | * Signifies that the traffic should be dropped. |
| 47 | */ |
Jon Hall | 8c7b06a | 2017-02-22 13:37:33 -0800 | [diff] [blame^] | 48 | DROP |
Jian Li | 136fd6c | 2017-02-10 14:54:59 +0900 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | public abstract ActionType subtype(); |
| 52 | |
| 53 | @Override |
| 54 | public final Type type() { |
| 55 | return Type.ACTION; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Represents a No Action mapping instruction. |
| 60 | */ |
| 61 | public static final class NoActionMappingInstruction |
| 62 | extends ActionMappingInstruction { |
| 63 | |
| 64 | NoActionMappingInstruction() { |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public ActionType subtype() { |
| 69 | return ActionType.NO_ACTION; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public String toString() { |
| 74 | return subtype().toString(); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public int hashCode() { |
| 79 | return Objects.hash(type(), subtype()); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public boolean equals(Object obj) { |
| 84 | if (this == obj) { |
| 85 | return true; |
| 86 | } |
| 87 | if (obj instanceof NoActionMappingInstruction) { |
| 88 | return true; |
| 89 | } |
| 90 | return false; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Represents a Native Forward mapping instruction. |
| 96 | */ |
| 97 | public static final class NativeForwardMappingInstruction |
| 98 | extends ActionMappingInstruction { |
| 99 | |
| 100 | NativeForwardMappingInstruction() { |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public ActionType subtype() { |
| 105 | return ActionType.NATIVE_FORWARD; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public String toString() { |
| 110 | return subtype().toString(); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public int hashCode() { |
| 115 | return Objects.hash(type(), subtype()); |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public boolean equals(Object obj) { |
| 120 | if (this == obj) { |
| 121 | return true; |
| 122 | } |
| 123 | if (obj instanceof NativeForwardMappingInstruction) { |
| 124 | return true; |
| 125 | } |
| 126 | return false; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Represents a Forward mapping instruction. |
| 132 | */ |
| 133 | public static final class ForwardMappingInstruction |
| 134 | extends ActionMappingInstruction { |
| 135 | |
| 136 | ForwardMappingInstruction() { |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public ActionType subtype() { |
| 141 | return ActionType.FORWARD; |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public String toString() { |
| 146 | return subtype().toString(); |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public int hashCode() { |
| 151 | return Objects.hash(type(), subtype()); |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public boolean equals(Object obj) { |
| 156 | if (this == obj) { |
| 157 | return true; |
| 158 | } |
| 159 | if (obj instanceof ForwardMappingInstruction) { |
| 160 | return true; |
| 161 | } |
| 162 | return false; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Represents a Drop mapping instruction. |
| 168 | */ |
| 169 | public static final class DropMappingInstruction |
| 170 | extends ActionMappingInstruction { |
| 171 | |
| 172 | DropMappingInstruction() { |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public ActionType subtype() { |
| 177 | return ActionType.DROP; |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public String toString() { |
| 182 | return subtype().toString(); |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | public int hashCode() { |
| 187 | return Objects.hash(type(), subtype()); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public boolean equals(Object obj) { |
| 192 | if (this == obj) { |
| 193 | return true; |
| 194 | } |
| 195 | if (obj instanceof DropMappingInstruction) { |
| 196 | return true; |
| 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | } |
| 201 | } |