[ONOS-5427] Add LISP NAT LCAF address class along with unit tests

Change-Id: I27e792d32aa2b30bf42ca0687161e9df9352cb6b
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispNatLcafAddressTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispNatLcafAddressTest.java
new file mode 100644
index 0000000..f8584bdc
--- /dev/null
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispNatLcafAddressTest.java
@@ -0,0 +1,128 @@
+/*
+ * 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 com.google.common.testing.EqualsTester;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onosproject.lisp.msg.exceptions.LispParseError;
+import org.onosproject.lisp.msg.exceptions.LispReaderException;
+import org.onosproject.lisp.msg.exceptions.LispWriterException;
+import org.onosproject.lisp.msg.types.LispNatLcafAddress.NatAddressBuilder;
+import org.onosproject.lisp.msg.types.LispNatLcafAddress.NatLcafAddressReader;
+import org.onosproject.lisp.msg.types.LispNatLcafAddress.NatLcafAddressWriter;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+/**
+ * Unit tests for LispNatLcafAddress class.
+ */
+public class LispNatLcafAddressTest {
+
+    private LispNatLcafAddress address1;
+    private LispNatLcafAddress sameAsAddress1;
+    private LispNatLcafAddress address2;
+
+    @Before
+    public void setup() {
+
+        NatAddressBuilder builder1 = new NatAddressBuilder();
+
+        short msUdpPortNumber1 = 80;
+        short etrUdpPortNumber1 = 100;
+        LispIpv4Address globalEtrRlocAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
+        LispIpv4Address msRlocAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
+        LispIpv4Address privateEtrRlocAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.3"));
+
+        address1 = builder1
+                        .withLength((short) 0)
+                        .withMsUdpPortNumber(msUdpPortNumber1)
+                        .withEtrUdpPortNumber(etrUdpPortNumber1)
+                        .withGlobalEtrRlocAddress(globalEtrRlocAddress1)
+                        .withMsRlocAddress(msRlocAddress1)
+                        .withPrivateEtrRlocAddress(privateEtrRlocAddress1)
+                        .build();
+
+        NatAddressBuilder builder2 = new NatAddressBuilder();
+
+        sameAsAddress1 = builder2
+                        .withLength((short) 0)
+                        .withMsUdpPortNumber(msUdpPortNumber1)
+                        .withEtrUdpPortNumber(etrUdpPortNumber1)
+                        .withGlobalEtrRlocAddress(globalEtrRlocAddress1)
+                        .withMsRlocAddress(msRlocAddress1)
+                        .withPrivateEtrRlocAddress(privateEtrRlocAddress1)
+                        .build();
+
+        NatAddressBuilder builder3 = new NatAddressBuilder();
+
+        short msUdpPortNumber2 = 81;
+        short etrUdpPortNumber2 = 101;
+        LispIpv4Address globalEtrRlocAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1"));
+        LispIpv4Address msRlocAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.2"));
+        LispIpv4Address privateEtrRlocAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.3"));
+
+        address2 = builder3
+                        .withLength((short) 0)
+                        .withMsUdpPortNumber(msUdpPortNumber2)
+                        .withEtrUdpPortNumber(etrUdpPortNumber2)
+                        .withGlobalEtrRlocAddress(globalEtrRlocAddress2)
+                        .withMsRlocAddress(msRlocAddress2)
+                        .withPrivateEtrRlocAddress(privateEtrRlocAddress2)
+                        .build();
+    }
+
+    @Test
+    public void testEquality() {
+        new EqualsTester()
+                .addEqualityGroup(address1, sameAsAddress1)
+                .addEqualityGroup(address2).testEquals();
+    }
+
+    @Test
+    public void testConstruction() {
+        LispNatLcafAddress natLcafAddress = address1;
+
+        LispIpv4Address globalEtrRlocAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
+        LispIpv4Address msRlocAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
+        LispIpv4Address privateEtrRlocAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.3"));
+
+        assertThat(natLcafAddress.getLength(), is((short) 0));
+        assertThat(natLcafAddress.getMsUdpPortNumber(), is((short) 80));
+        assertThat(natLcafAddress.getEtrUdpPortNumber(), is((short) 100));
+        assertThat(natLcafAddress.getGlobalEtrRlocAddress(), is(globalEtrRlocAddress1));
+        assertThat(natLcafAddress.getMsRlocAddress(), is(msRlocAddress1));
+        assertThat(natLcafAddress.getPrivateEtrRlocAddress(), is(privateEtrRlocAddress1));
+    }
+
+    @Test
+    public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
+        ByteBuf byteBuf = Unpooled.buffer();
+
+        NatLcafAddressWriter writer = new NatLcafAddressWriter();
+        writer.writeTo(byteBuf, address1);
+
+        NatLcafAddressReader reader = new NatLcafAddressReader();
+        LispNatLcafAddress deserialized = reader.readFrom(byteBuf);
+
+        new EqualsTester()
+                .addEqualityGroup(address1, deserialized).testEquals();
+    }
+}