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

Change-Id: If6263957b2ce1d9a6a07bbc12f4fb9c9e2fa7616
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/AddressFamilyIdentifierEnum.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/AddressFamilyIdentifierEnum.java
new file mode 100644
index 0000000..136534e
--- /dev/null
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/AddressFamilyIdentifierEnum.java
@@ -0,0 +1,60 @@
+/*
+ * 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;
+    }
+}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispAfiAddress.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispAfiAddress.java
new file mode 100644
index 0000000..c4c49e1
--- /dev/null
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispAfiAddress.java
@@ -0,0 +1,71 @@
+/*
+ * 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;
+    }
+}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispAsAddress.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispAsAddress.java
new file mode 100644
index 0000000..cb31108
--- /dev/null
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispAsAddress.java
@@ -0,0 +1,77 @@
+/*
+ * 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);
+    }
+}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispIpAddress.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispIpAddress.java
new file mode 100644
index 0000000..5af82ac
--- /dev/null
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispIpAddress.java
@@ -0,0 +1,61 @@
+/*
+ * 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();
+    }
+}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispIpv4Address.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispIpv4Address.java
new file mode 100644
index 0000000..3a47063
--- /dev/null
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispIpv4Address.java
@@ -0,0 +1,36 @@
+/*
+ * 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());
+    }
+}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispIpv6Address.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispIpv6Address.java
new file mode 100644
index 0000000..7c2a60e
--- /dev/null
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispIpv6Address.java
@@ -0,0 +1,36 @@
+/*
+ * 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());
+    }
+}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispMacAddress.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispMacAddress.java
new file mode 100644
index 0000000..4c0e539
--- /dev/null
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispMacAddress.java
@@ -0,0 +1,60 @@
+/*
+ * 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();
+    }
+}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/PlaceHolder.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispNoAddress.java
similarity index 71%
copy from protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/PlaceHolder.java
copy to protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispNoAddress.java
index 786c73b..f6e1caf 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/PlaceHolder.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispNoAddress.java
@@ -13,12 +13,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.lisp.msg;
+package org.onosproject.lisp.msg.types;
 
 /**
- * Remove me.
+ * No address.
  */
-@Deprecated
-public abstract class PlaceHolder {
+public class LispNoAddress extends LispAfiAddress {
 
+    /**
+     * Initializes no address.
+     */
+    public LispNoAddress() {
+        super(AddressFamilyIdentifierEnum.NO_ADDRESS);
+    }
 }
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/PlaceHolder.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/package-info.java
similarity index 85%
rename from protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/PlaceHolder.java
rename to protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/package-info.java
index 786c73b..9e55376 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/PlaceHolder.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/package-info.java
@@ -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