Jian Li
Committed by Thomas Vachuska

[ONOS-4718] Add LispDistinguishedNameAddress, modify hashCode logic

Change-Id: Ic9b840f6dc0102bed35d3c88b76b6e8b36a051f5
...@@ -25,10 +25,18 @@ package org.onosproject.lisp.msg.types; ...@@ -25,10 +25,18 @@ package org.onosproject.lisp.msg.types;
25 */ 25 */
26 public enum AddressFamilyIdentifierEnum { 26 public enum AddressFamilyIdentifierEnum {
27 27
28 - NO_ADDRESS(0), IP(1), IP6(2), DNS(16), DISTINGUISHED_NAME(17), AS(18), LCAF(16387), 28 + NO_ADDRESS(0), // Reserved
29 - MAC(16389), OUI(16391), UNKNOWN(-1); 29 + IP(1), // IP (IP version 4)
30 + IP6(2), // IP6 (IP version 6)
31 + DNS(16), // Domain Name System
32 + DISTINGUISHED_NAME(17), // Distinguished Name
33 + AS(18), // AS Number
34 + LCAF(16387), // LISP Canonical Address Format (LCAF)
35 + MAC(16389), // 48-bit MAC
36 + OUI(16391), // 24-bit Organizationally Unique Identifier
37 + UNKNOWN(-1); // Other Enums for internal use
30 38
31 - private short ianaCode; 39 + private final short ianaCode;
32 40
33 AddressFamilyIdentifierEnum(int ianaCode) { 41 AddressFamilyIdentifierEnum(int ianaCode) {
34 this.ianaCode = (short) ianaCode; 42 this.ianaCode = (short) ianaCode;
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.lisp.msg.types; 16 package org.onosproject.lisp.msg.types;
17 17
18 +import java.util.Objects;
19 +
18 /** 20 /**
19 * LISP Locator address typed by Address Family Identifier (AFI). 21 * LISP Locator address typed by Address Family Identifier (AFI).
20 */ 22 */
...@@ -42,10 +44,7 @@ public abstract class LispAfiAddress { ...@@ -42,10 +44,7 @@ public abstract class LispAfiAddress {
42 44
43 @Override 45 @Override
44 public int hashCode() { 46 public int hashCode() {
45 - final int prime = 31; 47 + return Objects.hash(afi);
46 - int result = 1;
47 - result = prime * result + ((afi == null) ? 0 : afi.hashCode());
48 - return result;
49 } 48 }
50 49
51 @Override 50 @Override
......
...@@ -126,14 +126,7 @@ public class LispAppDataLcafAddress extends LispLcafAddress { ...@@ -126,14 +126,7 @@ public class LispAppDataLcafAddress extends LispLcafAddress {
126 126
127 @Override 127 @Override
128 public int hashCode() { 128 public int hashCode() {
129 - final int prime = 31; 129 + return Objects.hash(address, protocol, ipTos, localPort, remotePort);
130 - int result = super.hashCode();
131 - result = prime * result + ((address == null) ? 0 : address.hashCode());
132 - result = prime * result + protocol;
133 - result = prime * result + ipTos;
134 - result = prime * result + localPort;
135 - result = prime * result + remotePort;
136 - return result;
137 } 130 }
138 131
139 @Override 132 @Override
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.lisp.msg.types; 16 package org.onosproject.lisp.msg.types;
17 17
18 +import java.util.Objects;
19 +
18 /** 20 /**
19 * The identifier of Autonomous System (AS). 21 * The identifier of Autonomous System (AS).
20 */ 22 */
...@@ -43,10 +45,7 @@ public class LispAsAddress extends LispAfiAddress { ...@@ -43,10 +45,7 @@ public class LispAsAddress extends LispAfiAddress {
43 45
44 @Override 46 @Override
45 public int hashCode() { 47 public int hashCode() {
46 - final int prime = 31; 48 + return Objects.hash(asNum);
47 - int result = super.hashCode();
48 - result = prime * result + asNum;
49 - return result;
50 } 49 }
51 50
52 @Override 51 @Override
......
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 + * Distinguished name address that is used by LISP Locator.
24 + */
25 +public class LispDistinguishedNameAddress extends LispAfiAddress {
26 +
27 + private final String distinguishedName;
28 +
29 + /**
30 + * Initializes LISP locator's distinguished name address with AFI enum.
31 + *
32 + * @param distinguishedName distinguished name address
33 + */
34 + public LispDistinguishedNameAddress(String distinguishedName) {
35 + super(AddressFamilyIdentifierEnum.DISTINGUISHED_NAME);
36 + this.distinguishedName = distinguishedName;
37 + }
38 +
39 + /**
40 + * Obtains LISP locator's distinguished name address.
41 + *
42 + * @return distinguished name address
43 + */
44 + public String getDistinguishedName() {
45 + return distinguishedName;
46 + }
47 +
48 + @Override
49 + public int hashCode() {
50 + return Objects.hash(distinguishedName);
51 + }
52 +
53 + @Override
54 + public boolean equals(Object obj) {
55 + if (this == obj) {
56 + return true;
57 + }
58 +
59 + if (obj instanceof LispDistinguishedNameAddress) {
60 + final LispDistinguishedNameAddress other = (LispDistinguishedNameAddress) obj;
61 + return Objects.equals(this.distinguishedName, other.distinguishedName);
62 + }
63 + return false;
64 + }
65 +
66 + @Override
67 + public String toString() {
68 + return toStringHelper(this)
69 + .add("distinguished name", distinguishedName)
70 + .toString();
71 + }
72 +}
...@@ -168,14 +168,7 @@ public class LispLcafAddress extends LispAfiAddress { ...@@ -168,14 +168,7 @@ public class LispLcafAddress extends LispAfiAddress {
168 168
169 @Override 169 @Override
170 public int hashCode() { 170 public int hashCode() {
171 - final int prime = 31; 171 + return Objects.hash(lcafType, reserved1, reserved2, flag, length);
172 - int result = super.hashCode();
173 - result = prime * result + ((lcafType == null) ? 0 : lcafType.hashCode());
174 - result = prime * result + reserved1;
175 - result = prime * result + reserved2;
176 - result = prime * result + flag;
177 - result = prime * result + length;
178 - return result;
179 } 172 }
180 173
181 @Override 174 @Override
......
...@@ -71,10 +71,7 @@ public class LispListLcafAddress extends LispLcafAddress { ...@@ -71,10 +71,7 @@ public class LispListLcafAddress extends LispLcafAddress {
71 71
72 @Override 72 @Override
73 public int hashCode() { 73 public int hashCode() {
74 - final int prime = 31; 74 + return Objects.hash(addresses);
75 - int result = super.hashCode();
76 - result = prime * result + ((addresses == null) ? 0 : addresses.hashCode());
77 - return result;
78 } 75 }
79 76
80 @Override 77 @Override
......
...@@ -83,12 +83,7 @@ public class LispSegmentLcafAddress extends LispLcafAddress { ...@@ -83,12 +83,7 @@ public class LispSegmentLcafAddress extends LispLcafAddress {
83 83
84 @Override 84 @Override
85 public int hashCode() { 85 public int hashCode() {
86 - final int prime = 31; 86 + return Objects.hash(address, instanceId, reserved2);
87 - int result = super.hashCode();
88 - result = prime * result + ((address == null) ? 0 : address.hashCode());
89 - result = prime * result + instanceId;
90 - result = prime * result + reserved2;
91 - return result;
92 } 87 }
93 88
94 @Override 89 @Override
......
...@@ -124,14 +124,7 @@ public class LispSourceDestLcafAddress extends LispLcafAddress { ...@@ -124,14 +124,7 @@ public class LispSourceDestLcafAddress extends LispLcafAddress {
124 124
125 @Override 125 @Override
126 public int hashCode() { 126 public int hashCode() {
127 - final int prime = 31; 127 + return Objects.hash(srcPrefix, dstPrefix, srcMaskLength, dstMaskLength, reserved);
128 - int result = super.hashCode();
129 - result = prime * result + ((srcPrefix == null) ? 0 : srcPrefix.hashCode());
130 - result = prime * result + ((dstPrefix == null) ? 0 : dstPrefix.hashCode());
131 - result = prime * result + srcMaskLength;
132 - result = prime * result + dstMaskLength;
133 - result = prime * result + reserved;
134 - return result;
135 } 128 }
136 129
137 @Override 130 @Override
......