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;
*/
public enum AddressFamilyIdentifierEnum {
NO_ADDRESS(0), IP(1), IP6(2), DNS(16), DISTINGUISHED_NAME(17), AS(18), LCAF(16387),
MAC(16389), OUI(16391), UNKNOWN(-1);
NO_ADDRESS(0), // Reserved
IP(1), // IP (IP version 4)
IP6(2), // IP6 (IP version 6)
DNS(16), // Domain Name System
DISTINGUISHED_NAME(17), // Distinguished Name
AS(18), // AS Number
LCAF(16387), // LISP Canonical Address Format (LCAF)
MAC(16389), // 48-bit MAC
OUI(16391), // 24-bit Organizationally Unique Identifier
UNKNOWN(-1); // Other Enums for internal use
private short ianaCode;
private final short ianaCode;
AddressFamilyIdentifierEnum(int ianaCode) {
this.ianaCode = (short) ianaCode;
......
......@@ -15,6 +15,8 @@
*/
package org.onosproject.lisp.msg.types;
import java.util.Objects;
/**
* LISP Locator address typed by Address Family Identifier (AFI).
*/
......@@ -42,10 +44,7 @@ public abstract class LispAfiAddress {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((afi == null) ? 0 : afi.hashCode());
return result;
return Objects.hash(afi);
}
@Override
......
......@@ -126,14 +126,7 @@ public class LispAppDataLcafAddress extends LispLcafAddress {
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((address == null) ? 0 : address.hashCode());
result = prime * result + protocol;
result = prime * result + ipTos;
result = prime * result + localPort;
result = prime * result + remotePort;
return result;
return Objects.hash(address, protocol, ipTos, localPort, remotePort);
}
@Override
......
......@@ -15,6 +15,8 @@
*/
package org.onosproject.lisp.msg.types;
import java.util.Objects;
/**
* The identifier of Autonomous System (AS).
*/
......@@ -43,10 +45,7 @@ public class LispAsAddress extends LispAfiAddress {
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + asNum;
return result;
return Objects.hash(asNum);
}
@Override
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.lisp.msg.types;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Distinguished name address that is used by LISP Locator.
*/
public class LispDistinguishedNameAddress extends LispAfiAddress {
private final String distinguishedName;
/**
* Initializes LISP locator's distinguished name address with AFI enum.
*
* @param distinguishedName distinguished name address
*/
public LispDistinguishedNameAddress(String distinguishedName) {
super(AddressFamilyIdentifierEnum.DISTINGUISHED_NAME);
this.distinguishedName = distinguishedName;
}
/**
* Obtains LISP locator's distinguished name address.
*
* @return distinguished name address
*/
public String getDistinguishedName() {
return distinguishedName;
}
@Override
public int hashCode() {
return Objects.hash(distinguishedName);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof LispDistinguishedNameAddress) {
final LispDistinguishedNameAddress other = (LispDistinguishedNameAddress) obj;
return Objects.equals(this.distinguishedName, other.distinguishedName);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this)
.add("distinguished name", distinguishedName)
.toString();
}
}
......@@ -168,14 +168,7 @@ public class LispLcafAddress extends LispAfiAddress {
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((lcafType == null) ? 0 : lcafType.hashCode());
result = prime * result + reserved1;
result = prime * result + reserved2;
result = prime * result + flag;
result = prime * result + length;
return result;
return Objects.hash(lcafType, reserved1, reserved2, flag, length);
}
@Override
......
......@@ -71,10 +71,7 @@ public class LispListLcafAddress extends LispLcafAddress {
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((addresses == null) ? 0 : addresses.hashCode());
return result;
return Objects.hash(addresses);
}
@Override
......
......@@ -83,12 +83,7 @@ public class LispSegmentLcafAddress extends LispLcafAddress {
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((address == null) ? 0 : address.hashCode());
result = prime * result + instanceId;
result = prime * result + reserved2;
return result;
return Objects.hash(address, instanceId, reserved2);
}
@Override
......
......@@ -124,14 +124,7 @@ public class LispSourceDestLcafAddress extends LispLcafAddress {
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((srcPrefix == null) ? 0 : srcPrefix.hashCode());
result = prime * result + ((dstPrefix == null) ? 0 : dstPrefix.hashCode());
result = prime * result + srcMaskLength;
result = prime * result + dstMaskLength;
result = prime * result + reserved;
return result;
return Objects.hash(srcPrefix, dstPrefix, srcMaskLength, dstMaskLength, reserved);
}
@Override
......