Committed by
Thomas Vachuska
[ONOS-4718] Add LISP Canonical Address Format Enum and Address class
Change-Id: Ife7f0b98207424b1ce1df390d73b72eb7b5890fe
Showing
2 changed files
with
163 additions
and
0 deletions
protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispCanonicalAddressFormatEnum.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2016-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.lisp.msg.types; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * LISP Canonical Address Format (LCAF) Enumeration class. | ||
| 20 | + * | ||
| 21 | + * LCAF defines a canonical address format encoding used in LISP control message | ||
| 22 | + * and in the encoding of lookup keys for the LISP Mapping Database System. | ||
| 23 | + * | ||
| 24 | + * LCAF is defined in draft-ietf-lisp-lcaf-13 | ||
| 25 | + * https://tools.ietf.org/html/draft-ietf-lisp-lcaf-13 | ||
| 26 | + */ | ||
| 27 | +public enum LispCanonicalAddressFormatEnum { | ||
| 28 | + LIST(1), // AFI LIST Type | ||
| 29 | + SEGMENT(2), // Instance ID Type | ||
| 30 | + AS(3), // AS Number Type | ||
| 31 | + APPLICATION_DATA(4), // Application Data Type | ||
| 32 | + NAT(7), // NAT Traversal Type | ||
| 33 | + MULTICAST(9), // Multi-cast Info Type | ||
| 34 | + SECURITY(11), // Security Key Type | ||
| 35 | + SOURCE_DEST(12), // Source/Dest Key Type | ||
| 36 | + TRAFFIC_ENGINEERING(10), // Explicit Locator Path Type | ||
| 37 | + UNKNOWN(-1); // Unknown Type | ||
| 38 | + | ||
| 39 | + private byte lispCode; | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * Private constructor which avoid instantiating object externally. | ||
| 43 | + * | ||
| 44 | + * @param lispCode lisp code value | ||
| 45 | + */ | ||
| 46 | + LispCanonicalAddressFormatEnum(int lispCode) { | ||
| 47 | + this.lispCode = (byte) lispCode; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * Obtains lisp code value. | ||
| 52 | + * | ||
| 53 | + * @return lisp code value | ||
| 54 | + */ | ||
| 55 | + public byte getLispCode() { | ||
| 56 | + return lispCode; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * Obtains the LCAF enum using given lisp code. | ||
| 61 | + * | ||
| 62 | + * @param lispCode lisp code | ||
| 63 | + * @return LCAP enum | ||
| 64 | + */ | ||
| 65 | + public static LispCanonicalAddressFormatEnum valueOf(int lispCode) { | ||
| 66 | + for (LispCanonicalAddressFormatEnum val : values()) { | ||
| 67 | + if (val.getLispCode() == lispCode) { | ||
| 68 | + return val; | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + return UNKNOWN; | ||
| 72 | + } | ||
| 73 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016-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.lisp.msg.types; | ||
| 17 | + | ||
| 18 | +import java.util.Objects; | ||
| 19 | + | ||
| 20 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * LISP Canonical Address Formatted address class. | ||
| 24 | + */ | ||
| 25 | +public class LispLcafAddress extends LispAfiAddress { | ||
| 26 | + | ||
| 27 | + protected final LispCanonicalAddressFormatEnum lcafType; | ||
| 28 | + protected final byte value; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * Initializes LCAF address. | ||
| 32 | + * | ||
| 33 | + * @param lcafType LCAF type | ||
| 34 | + * @param value LCAF value | ||
| 35 | + */ | ||
| 36 | + protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, byte value) { | ||
| 37 | + super(AddressFamilyIdentifierEnum.LCAF); | ||
| 38 | + this.lcafType = lcafType; | ||
| 39 | + this.value = value; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * Obtains LCAF type. | ||
| 44 | + * | ||
| 45 | + * @return LCAF type | ||
| 46 | + */ | ||
| 47 | + public LispCanonicalAddressFormatEnum getType() { | ||
| 48 | + return lcafType; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * Obtains LCAF value. | ||
| 53 | + * | ||
| 54 | + * @return LCAF value | ||
| 55 | + */ | ||
| 56 | + public byte getValue() { | ||
| 57 | + return value; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @Override | ||
| 61 | + public int hashCode() { | ||
| 62 | + final int prime = 31; | ||
| 63 | + int result = super.hashCode(); | ||
| 64 | + result = prime * result + ((lcafType == null) ? 0 : lcafType.hashCode()); | ||
| 65 | + result = prime * result + value; | ||
| 66 | + return result; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @Override | ||
| 70 | + public boolean equals(Object obj) { | ||
| 71 | + if (this == obj) { | ||
| 72 | + return true; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + if (obj instanceof LispLcafAddress) { | ||
| 76 | + final LispLcafAddress other = (LispLcafAddress) obj; | ||
| 77 | + return Objects.equals(this.lcafType, other.lcafType) && | ||
| 78 | + Objects.equals(this.value, other.value); | ||
| 79 | + } | ||
| 80 | + return false; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 84 | + public String toString() { | ||
| 85 | + return toStringHelper(this) | ||
| 86 | + .add("lcafType", lcafType) | ||
| 87 | + .add("lcafValue", value) | ||
| 88 | + .toString(); | ||
| 89 | + } | ||
| 90 | +} |
-
Please register or login to post a comment