Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
| 17 | package org.onosproject.net.flow.instructions; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | |
| 22 | import java.util.Objects; |
| 23 | |
| 24 | /** |
| 25 | * Type of extension instructions. |
| 26 | */ |
| 27 | @Beta |
| 28 | public final class ExtensionType { |
| 29 | |
| 30 | /** |
| 31 | * A list of well-known named extension instruction type codes. |
| 32 | */ |
| 33 | public enum ExtensionTypes { |
| 34 | // TODO fix type numbers to include experimenter id |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 35 | NICIRA_SET_TUNNEL_DST(31), |
| 36 | NICIRA_RESUBMIT(32); |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 37 | |
| 38 | private ExtensionType type; |
| 39 | |
| 40 | /** |
| 41 | * Creates a new named extension instruction type. |
| 42 | * |
| 43 | * @param type type code |
| 44 | */ |
| 45 | ExtensionTypes(int type) { |
| 46 | this.type = new ExtensionType(type); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Gets the extension type object for this named type code. |
| 51 | * |
| 52 | * @return extension type object |
| 53 | */ |
| 54 | public ExtensionType type() { |
| 55 | return type; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | private final int type; |
| 60 | |
| 61 | /** |
| 62 | * Creates an extension type with the given int type code. |
| 63 | * |
| 64 | * @param type type code |
| 65 | */ |
| 66 | public ExtensionType(int type) { |
| 67 | this.type = type; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public int hashCode() { |
| 72 | return Objects.hash(type); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public boolean equals(Object obj) { |
| 77 | if (this == obj) { |
| 78 | return true; |
| 79 | } |
| 80 | if (obj instanceof ExtensionType) { |
| 81 | final ExtensionType that = (ExtensionType) obj; |
| 82 | return this.type == that.type; |
| 83 | } |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public String toString() { |
| 89 | return MoreObjects.toStringHelper(ExtensionType.class) |
| 90 | .add("type", type) |
| 91 | .toString(); |
| 92 | } |
| 93 | } |