Jian Li
Committed by Thomas Vachuska

[ONOS-4718] Add several data types used for addressing LISP locator

Change-Id: If6263957b2ce1d9a6a07bbc12f4fb9c9e2fa7616
/*
* 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;
/**
* Address Family Identifier (AFI) Enumeration class.
*
* An enumeration of AFIs defined by iana.
* Now, we only declare 10 enums, more enums will be declared later on.
*
* http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml
*/
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);
private short ianaCode;
AddressFamilyIdentifierEnum(int ianaCode) {
this.ianaCode = (short) ianaCode;
}
/**
* Obtains iana code value.
*
* @return iana code value
*/
public short getIanaCode() {
return ianaCode;
}
/**
* Obtains AFI enum by providing iana code value.
*
* @param ianaCode iana code value
* @return AFI enum
*/
public static AddressFamilyIdentifierEnum valueOf(short ianaCode) {
for (AddressFamilyIdentifierEnum val : values()) {
if (val.getIanaCode() == ianaCode) {
return val;
}
}
return UNKNOWN;
}
}
/*
* 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;
/**
* LISP Locator address typed by Address Family Identifier (AFI).
*/
public abstract class LispAfiAddress {
private final AddressFamilyIdentifierEnum afi;
/**
* Initializes AFI enumeration value.
*
* @param afi address family identifier
*/
protected LispAfiAddress(AddressFamilyIdentifierEnum afi) {
this.afi = afi;
}
/**
* Obtains AFI enumeration value.
*
* @return AFI enumeration value
*/
public AddressFamilyIdentifierEnum getAfi() {
return afi;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((afi == null) ? 0 : afi.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
LispAfiAddress other = (LispAfiAddress) obj;
if (afi != other.afi) {
return false;
}
return true;
}
}
/*
* 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;
/**
* The identifier of Autonomous System (AS).
*/
public class LispAsAddress extends LispAfiAddress {
private final int asNum;
/**
* Initializes AS identifier number.
*
* @param num AS number
*/
public LispAsAddress(int num) {
super(AddressFamilyIdentifierEnum.AS);
this.asNum = num;
}
/**
* Obtains AS identifier number.
*
* @return AS number
*/
public int getASNum() {
return asNum;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + asNum;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
LispAsAddress other = (LispAsAddress) obj;
if (asNum != other.asNum) {
return false;
}
return true;
}
@Override
public String toString() {
return String.valueOf(asNum);
}
}
/*
* 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 org.onlab.packet.IpAddress;
/**
* IP address that is used by LISP Locator.
*/
public abstract class LispIpAddress extends LispAfiAddress {
protected final IpAddress address;
/**
* Initializes LISP locator's IP address with AFI enum.
*
* @param address IP address
* @param afi AFI enum
*/
protected LispIpAddress(IpAddress address, AddressFamilyIdentifierEnum afi) {
super(afi);
this.address = address;
}
/**
* Obtains LISP locator's IP address.
*
* @return IP address
*/
public IpAddress getAddress() {
return address;
}
@Override
public int hashCode() {
return address.hashCode();
}
@Override
public boolean equals(Object obj) {
return address.equals(obj);
}
@Override
public String toString() {
return address.toString();
}
}
/*
* 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 org.onlab.packet.IpAddress;
import static com.google.common.base.Preconditions.checkArgument;
/**
* IPv4 address that is used by LISP Locator.
*/
public class LispIpv4Address extends LispIpAddress {
/**
* Initializes LISP locator's IPv4 address.
*
* @param address IP address
*/
public LispIpv4Address(IpAddress address) {
super(address, AddressFamilyIdentifierEnum.IP);
checkArgument(address.isIp4());
}
}
/*
* 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 org.onlab.packet.IpAddress;
import static com.google.common.base.Preconditions.checkArgument;
/**
* IPv6 address that is used by LISP Locator.
*/
public class LispIpv6Address extends LispIpAddress {
/**
* Initializes LISP locator's IPv6 address.
*
* @param address IP address
*/
public LispIpv6Address(IpAddress address) {
super(address, AddressFamilyIdentifierEnum.IP);
checkArgument(address.isIp6());
}
}
/*
* 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 org.onlab.packet.MacAddress;
/**
* MAC address that is used by LISP Locator.
*/
public class LispMacAddress extends LispAfiAddress {
protected final MacAddress address;
/**
* Initializes MAC address.
*
* @param address MAC address
*/
public LispMacAddress(MacAddress address) {
super(AddressFamilyIdentifierEnum.MAC);
this.address = address;
}
/**
* Obtains LISP locator's MAC address.
*
* @return MAC address
*/
public MacAddress getAddress() {
return address;
}
@Override
public int hashCode() {
return address.hashCode();
}
@Override
public boolean equals(Object obj) {
return address.equals(obj);
}
@Override
public String toString() {
return address.toString();
}
}
/*
* 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;
/**
* No address.
*/
public class LispNoAddress extends LispAfiAddress {
/**
* Initializes no address.
*/
public LispNoAddress() {
super(AddressFamilyIdentifierEnum.NO_ADDRESS);
}
}
......@@ -13,12 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.lisp.msg;
/**
* Remove me.
* LISP message data type.
*/
@Deprecated
public abstract class PlaceHolder {
}
package org.onosproject.lisp.msg.types;
\ No newline at end of file
......