Jian Li | 2c4e9a9 | 2017-03-13 16:45:53 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jian Li | 2c4e9a9 | 2017-03-13 16:45:53 +0900 | [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 | */ |
| 16 | package org.onosproject.mapping.addresses; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | /** |
| 23 | * Type of mapping address extensions. |
| 24 | */ |
| 25 | public class ExtensionMappingAddressType { |
| 26 | |
| 27 | /** |
| 28 | * A list of well-known named extension mapping address type codes. |
| 29 | * These numbers have no impact on the actual LISP type id. |
| 30 | */ |
| 31 | public enum ExtensionMappingAddressTypes { |
| 32 | LIST_ADDRESS(1), |
| 33 | SEGMENT_ADDRESS(2), |
| 34 | AS_ADDRESS(3), |
| 35 | APPLICATION_DATA_ADDRESS(4), |
| 36 | GEO_COORDINATE_ADDRESS(5), |
| 37 | NAT_ADDRESS(7), |
| 38 | NONCE_ADDRESS(8), |
| 39 | MULTICAST_ADDRESS(9), |
| 40 | TRAFFIC_ENGINEERING_ADDRESS(10), |
| 41 | SECURITY_ADDRESS(11), |
| 42 | SOURCE_DEST_ADDRESS(12), |
| 43 | |
| 44 | UNRESOLVED_TYPE(200); |
| 45 | |
| 46 | private ExtensionMappingAddressType type; |
| 47 | |
| 48 | /** |
| 49 | * Creates a new named extension mapping address type. |
| 50 | * |
| 51 | * @param type type code |
| 52 | */ |
| 53 | ExtensionMappingAddressTypes(int type) { |
| 54 | this.type = new ExtensionMappingAddressType(type); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Obtains the extension type object for this named type code. |
| 59 | * |
| 60 | * @return extension type object |
| 61 | */ |
| 62 | public ExtensionMappingAddressType type() { |
| 63 | return type; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | private final int type; |
| 68 | |
| 69 | /** |
| 70 | * Creates an extension type with the given int type code. |
| 71 | * |
| 72 | * @param type type code |
| 73 | */ |
| 74 | public ExtensionMappingAddressType(int type) { |
| 75 | this.type = type; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Obtains the integer value associated with this type. |
| 80 | * |
| 81 | * @return an integer value |
| 82 | */ |
| 83 | public int toInt() { |
| 84 | return this.type; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public int hashCode() { |
| 89 | return Objects.hash(type); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public boolean equals(Object obj) { |
| 94 | if (this == obj) { |
| 95 | return true; |
| 96 | } |
| 97 | if (obj instanceof ExtensionMappingAddressType) { |
| 98 | final ExtensionMappingAddressType that = (ExtensionMappingAddressType) obj; |
| 99 | return this.type == that.type; |
| 100 | } |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public String toString() { |
| 106 | return MoreObjects.toStringHelper(ExtensionMappingAddressType.class) |
| 107 | .add("type", type) |
| 108 | .toString(); |
| 109 | } |
| 110 | } |