Add LISP Traffic Engineering LCAF address with unit tests

Change-Id: I516f399e54896f923e7fbf25de9a48426e21ea40
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispLcafAddress.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispLcafAddress.java
index 7a1763c..1997bcc 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispLcafAddress.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispLcafAddress.java
@@ -373,6 +373,10 @@
                 return new LispSourceDestLcafAddress.SourceDestLcafAddressReader().readFrom(byteBuf);
             }
 
+            if (lcafType == TRAFFIC_ENGINEERING.getLispCode()) {
+                return new LispTeLcafAddress.TeAddressBuilder.TeLcafAddressReader().readFrom(byteBuf);
+            }
+
             log.warn("Unsupported LCAF type, please specify a correct LCAF type");
 
             return null;
@@ -403,6 +407,10 @@
                     new LispSourceDestLcafAddress.SourceDestLcafAddressWriter().writeTo(byteBuf,
                             (LispSourceDestLcafAddress) address);
                     break;
+                case TRAFFIC_ENGINEERING:
+                    new LispTeLcafAddress.TeAddressBuilder.TeLcafAddressWriter().writeTo(byteBuf,
+                            (LispTeLcafAddress) address);
+                    break;
                 default:
                     log.warn("Unsupported LCAF type, please specify a correct LCAF type");
                     break;
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispTeLcafAddress.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispTeLcafAddress.java
new file mode 100644
index 0000000..4417b94
--- /dev/null
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispTeLcafAddress.java
@@ -0,0 +1,173 @@
+/*
+ * 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.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import io.netty.buffer.ByteBuf;
+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.LispTeRecord.TeRecordWriter;
+
+import java.util.List;
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Traffic Engineering (TE) type LCAF address class.
+ * <p>
+ * Traffic Engineering type is defined in draft-ietf-lisp-lcaf-13
+ * https://tools.ietf.org/html/draft-ietf-lisp-lcaf-13#page-15
+ * <p>
+ * <pre>
+ * {@literal
+ *  0                   1                   2                   3
+ *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |           AFI = 16387         |     Rsvd1     |     Flags     |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |   Type = 10   |     Rsvd2     |               n               |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |           Rsvd3         |L|P|S|           AFI = x             |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |                         Reencap Hop 1  ...                    |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |           Rsvd3         |L|P|S|           AFI = x             |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |                         Reencap Hop k  ...                    |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * }</pre>
+ */
+public final class LispTeLcafAddress extends LispLcafAddress {
+
+    private final List<LispTeRecord> records;
+
+    /**
+     * Initializes Traffic Engineering type LCAF address.
+     *
+     * @param records a collection of Re-encapsulated RLOC addresses
+     */
+    private LispTeLcafAddress(short length, List<LispTeRecord> records) {
+        super(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, length);
+        this.records = records;
+    }
+
+    /**
+     * Obtains a collection of TE records.
+     *
+     * @return a collection of TE records
+     */
+    public List<LispTeRecord> getTeRecords() {
+        return ImmutableList.copyOf(records);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(records);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj instanceof LispTeLcafAddress) {
+            final LispTeLcafAddress other = (LispTeLcafAddress) obj;
+            return Objects.equals(records, other.records);
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("TE records", records).toString();
+    }
+
+    public static final class TeAddressBuilder extends LcafAddressBuilder<TeAddressBuilder> {
+        private List<LispTeRecord> records;
+        private short length;
+        private static final int SIZE_OF_AFI_RECORD = 8;
+
+        /**
+         * Sets a collection of TE records.
+         *
+         * @param records a collection of TE records
+         * @return TeAddressBuilder object
+         */
+        public TeAddressBuilder withTeRecords(List<LispTeRecord> records) {
+            this.records = records;
+            this.length = (short) (records.size() * SIZE_OF_AFI_RECORD);
+            return this;
+        }
+
+        /**
+         * Builds LispTeLcafAddress instance.
+         *
+         * @return LispTeLcafAddress instance
+         */
+        public LispTeLcafAddress build() {
+            return new LispTeLcafAddress(length, records);
+        }
+
+        /**
+         * TE LCAF address reader class.
+         */
+        public static class TeLcafAddressReader implements LispAddressReader<LispTeLcafAddress> {
+
+            private static final int SIZE_OF_AFI_RECORD = 8;
+
+            @Override
+            public LispTeLcafAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException {
+
+                LispLcafAddress lcafAddress = LispLcafAddress.deserializeCommon(byteBuf);
+
+                // TODO: for RTR RLOC is IPv4 only for now
+                int numOfRecords = lcafAddress.getLength() / SIZE_OF_AFI_RECORD;
+
+                List<LispTeRecord> teRecords = Lists.newArrayList();
+                for (int i = 0; i < numOfRecords; i++) {
+                    teRecords.add(new LispTeRecord.TeRecordReader().readFrom(byteBuf));
+                }
+
+                return new TeAddressBuilder()
+                            .withTeRecords(teRecords)
+                            .build();
+            }
+        }
+
+        /**
+         * TE LCAF address writer class.
+         */
+        public static class TeLcafAddressWriter implements LispAddressWriter<LispTeLcafAddress> {
+
+            @Override
+            public void writeTo(ByteBuf byteBuf, LispTeLcafAddress address) throws LispWriterException {
+                LispLcafAddress.serializeCommon(byteBuf, address);
+
+                TeRecordWriter writer = new TeRecordWriter();
+
+                List<LispTeRecord> teRecords = address.getTeRecords();
+                for (int i = 0; i < teRecords.size(); i++) {
+                    writer.writeTo(byteBuf, teRecords.get(i));
+                }
+            }
+        }
+    }
+}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispTeRecord.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispTeRecord.java
new file mode 100644
index 0000000..3c5823c
--- /dev/null
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispTeRecord.java
@@ -0,0 +1,262 @@
+/*
+ * 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 io.netty.buffer.ByteBuf;
+import org.onlab.util.ByteOperator;
+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.LispAfiAddress.AfiAddressReader;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Traffic Engineering record class.
+ */
+public class LispTeRecord {
+
+    private final boolean lookup;
+    private final boolean rlocProbe;
+    private final boolean strict;
+    private final LispAfiAddress rtrRlocAddress;
+
+    /**
+     * Initializes TE record.
+     *
+     * @param lookup     lookup bit
+     * @param rlocProbe  rloc probe bit
+     * @param strict     strict bit
+     * @param rtrAddress RTR address
+     */
+    public LispTeRecord(boolean lookup, boolean rlocProbe, boolean strict, LispAfiAddress rtrAddress) {
+        this.lookup = lookup;
+        this.rlocProbe = rlocProbe;
+        this.strict = strict;
+        this.rtrRlocAddress = rtrAddress;
+    }
+
+    /**
+     * Obtains lookup bit flag.
+     *
+     * @return lookup bit flag
+     */
+    public boolean isLookup() {
+        return lookup;
+    }
+
+    /**
+     * Obtains RLOC probe bit flag.
+     *
+     * @return RLOC probe bit flag
+     */
+    public boolean isRlocProbe() {
+        return rlocProbe;
+    }
+
+    /**
+     * Obtains strict bit flag.
+     *
+     * @return strict bit flag
+     */
+    public boolean isStrict() {
+        return strict;
+    }
+
+    /**
+     * Obtains Re-encapsulated RLOC address.
+     *
+     * @return Re-encapsulated RLOC address
+     */
+    public LispAfiAddress getRtrRlocAddress() {
+        return rtrRlocAddress;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(lookup, rlocProbe, strict, rtrRlocAddress);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj instanceof LispTeRecord) {
+            final LispTeRecord other = (LispTeRecord) obj;
+            return Objects.equals(this.lookup, other.lookup) &&
+                    Objects.equals(this.rlocProbe, other.rlocProbe) &&
+                    Objects.equals(this.strict, other.strict) &&
+                    Objects.equals(this.rtrRlocAddress, other.rtrRlocAddress);
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("Lookup bit", lookup)
+                .add("RLOC probe bit", rlocProbe)
+                .add("strict bit", strict)
+                .add("RTR address", rtrRlocAddress)
+                .toString();
+    }
+
+    public static final class TeRecordBuilder {
+        private boolean lookup;
+        private boolean rlocProbe;
+        private boolean strict;
+        private LispAfiAddress rtrRlocAddress;
+
+        /**
+         * Sets lookup flag.
+         *
+         * @param lookup lookup flag
+         * @return TeRecordBuilder object
+         */
+        public TeRecordBuilder withIsLookup(boolean lookup) {
+            this.lookup = lookup;
+            return this;
+        }
+
+        /**
+         * Sets RLOC probe flag.
+         *
+         * @param rlocProbe RLOC probe flag
+         * @return TeRecordBuilder object
+         */
+        public TeRecordBuilder withIsRlocProbe(boolean rlocProbe) {
+            this.rlocProbe = rlocProbe;
+            return this;
+        }
+
+        /**
+         * Sets strict flag.
+         *
+         * @param strict strict flag
+         * @return TeRecordBuilder object
+         */
+        public TeRecordBuilder withIsStrict(boolean strict) {
+            this.strict = strict;
+            return this;
+        }
+
+        /**
+         * Sets RTR RLOC address.
+         *
+         * @param rtrRlocAddress RTR RLOC address
+         * @return TeRecordBuilder object
+         */
+        public TeRecordBuilder withRtrRlocAddress(LispAfiAddress rtrRlocAddress) {
+            this.rtrRlocAddress = rtrRlocAddress;
+            return this;
+        }
+
+        /**
+         * Builds TeRecord instance.
+         *
+         * @return TeRcord instance
+         */
+        public LispTeRecord build() {
+
+            return new LispTeRecord(lookup, rlocProbe, strict, rtrRlocAddress);
+        }
+    }
+
+    /**
+     * Traffic Engineering record reader class.
+     */
+    public static class TeRecordReader implements LispAddressReader<LispTeRecord> {
+
+        private static final int RESERVED_SKIP_LENGTH = 1;
+
+        private static final int STRICT_INDEX = 1;
+        private static final int RLOC_PROBE_INDEX = 2;
+        private static final int LOOKUP_INDEX = 3;
+
+        @Override
+        public LispTeRecord readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException {
+
+            // let's skip reserved 3
+            byteBuf.skipBytes(RESERVED_SKIP_LENGTH);
+
+            byte flags = byteBuf.readByte();
+
+            // lookup -> 1 bit
+            boolean lookup = ByteOperator.getBit(flags, LOOKUP_INDEX);
+
+            // rlocProbe -> 1 bit
+            boolean rlocProbe = ByteOperator.getBit(flags, RLOC_PROBE_INDEX);
+
+            // strict -> 1 bit
+            boolean strict = ByteOperator.getBit(flags, STRICT_INDEX);
+
+            AfiAddressReader reader = new AfiAddressReader();
+
+            LispAfiAddress rtrAddress = reader.readFrom(byteBuf);
+
+            return new LispTeRecord(lookup, rlocProbe, strict, rtrAddress);
+        }
+    }
+
+    /**
+     * Traffic Engineering record writer class.
+     */
+    public static class TeRecordWriter implements LispAddressWriter<LispTeRecord> {
+
+        private static final int LOOKUP_FLAG_SHIFT_BIT = 3;
+        private static final int RLOC_PROBE_FLAG_SHIFT_BIT = 2;
+        private static final int STRICT_FLAG_SHIFT_BIT = 1;
+
+        private static final int ENABLE_BIT = 1;
+        private static final int DISABLE_BIT = 0;
+
+        private static final int UNUSED_ZERO = 0;
+
+        @Override
+        public void writeTo(ByteBuf byteBuf, LispTeRecord record) throws LispWriterException {
+
+            byteBuf.writeByte(UNUSED_ZERO);
+
+            // lookup flag
+            byte lookup = DISABLE_BIT;
+            if (record.isLookup()) {
+                lookup = (byte) (ENABLE_BIT << LOOKUP_FLAG_SHIFT_BIT);
+            }
+
+            // RLOC probe flag
+            byte rlocProbe = DISABLE_BIT;
+            if (record.isRlocProbe()) {
+                rlocProbe = (byte) (ENABLE_BIT << RLOC_PROBE_FLAG_SHIFT_BIT);
+            }
+
+            // strict flag
+            byte strict = DISABLE_BIT;
+            if (record.isStrict()) {
+                strict = (byte) (ENABLE_BIT << STRICT_FLAG_SHIFT_BIT);
+            }
+
+            byteBuf.writeByte((byte) (lookup + rlocProbe + strict));
+
+            // RTR RLOC address
+            LispAfiAddress.AfiAddressWriter writer = new LispAfiAddress.AfiAddressWriter();
+            writer.writeTo(byteBuf, record.rtrRlocAddress);
+        }
+    }
+}
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispTeLcafAddressTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispTeLcafAddressTest.java
new file mode 100644
index 0000000..1b58f60
--- /dev/null
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispTeLcafAddressTest.java
@@ -0,0 +1,162 @@
+/*
+ * 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.collect.ImmutableList;
+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.LispTeLcafAddress.TeAddressBuilder;
+import org.onosproject.lisp.msg.types.LispTeLcafAddress.TeAddressBuilder.TeLcafAddressReader;
+import org.onosproject.lisp.msg.types.LispTeLcafAddress.TeAddressBuilder.TeLcafAddressWriter;
+import org.onosproject.lisp.msg.types.LispTeRecord.TeRecordBuilder;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+/**
+ * Unit tests for LispTeLcafAddress class.
+ */
+public class LispTeLcafAddressTest {
+
+    private LispTeLcafAddress address1;
+    private LispTeLcafAddress sameAsAddress1;
+    private LispTeLcafAddress address2;
+
+    @Before
+    public void setup() {
+
+        TeAddressBuilder builder1 = new TeAddressBuilder();
+
+        TeRecordBuilder recordBuilder1 = new TeRecordBuilder();
+        LispIpv4Address rtrRloc1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
+
+        recordBuilder1.withIsLookup(false);
+        recordBuilder1.withIsRlocProbe(false);
+        recordBuilder1.withIsStrict(false);
+        recordBuilder1.withRtrRlocAddress(rtrRloc1);
+        LispTeRecord record1 = recordBuilder1.build();
+
+        TeRecordBuilder recordBuilder2 = new TeRecordBuilder();
+        LispIpv4Address rtrRloc2 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
+
+        recordBuilder2.withIsLookup(false);
+        recordBuilder2.withIsRlocProbe(true);
+        recordBuilder2.withIsStrict(false);
+        recordBuilder2.withRtrRlocAddress(rtrRloc2);
+        LispTeRecord record2 = recordBuilder2.build();
+
+        builder1.withTeRecords(ImmutableList.of(record1, record2));
+
+        address1 = builder1.build();
+
+        TeAddressBuilder builder2 = new TeAddressBuilder();
+
+        TeRecordBuilder recordBuilder3 = new TeRecordBuilder();
+        recordBuilder3.withIsLookup(false);
+        recordBuilder3.withIsRlocProbe(false);
+        recordBuilder3.withIsStrict(false);
+        recordBuilder3.withRtrRlocAddress(rtrRloc1);
+        LispTeRecord record3 = recordBuilder3.build();
+
+        TeRecordBuilder recordBuilder4 = new TeRecordBuilder();
+        recordBuilder4.withIsLookup(false);
+        recordBuilder4.withIsRlocProbe(true);
+        recordBuilder4.withIsStrict(false);
+        recordBuilder4.withRtrRlocAddress(rtrRloc2);
+        LispTeRecord record4 = recordBuilder4.build();
+
+        builder2.withTeRecords(ImmutableList.of(record3, record4));
+
+        sameAsAddress1 = builder2.build();
+
+        TeAddressBuilder builder3 = new TeAddressBuilder();
+
+        TeRecordBuilder recordBuilder5 = new TeRecordBuilder();
+        LispIpv4Address rtrRloc3 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1"));
+
+        recordBuilder5.withIsLookup(true);
+        recordBuilder5.withIsRlocProbe(false);
+        recordBuilder5.withIsStrict(true);
+        recordBuilder5.withRtrRlocAddress(rtrRloc3);
+        LispTeRecord record5 = recordBuilder5.build();
+
+        TeRecordBuilder recordBuilder6 = new TeRecordBuilder();
+        LispIpv4Address rtrRloc4 = new LispIpv4Address(IpAddress.valueOf("192.168.2.2"));
+
+        recordBuilder6.withIsLookup(true);
+        recordBuilder6.withIsRlocProbe(true);
+        recordBuilder6.withIsStrict(true);
+        recordBuilder6.withRtrRlocAddress(rtrRloc4);
+        LispTeRecord record6 = recordBuilder6.build();
+
+        builder3.withTeRecords(ImmutableList.of(record5, record6));
+
+        address2 = builder3.build();
+    }
+
+    @Test
+    public void testEquality() {
+        new EqualsTester()
+                .addEqualityGroup(address1, sameAsAddress1)
+                .addEqualityGroup(address2).testEquals();
+    }
+
+    @Test
+    public void testConstruction() {
+        LispTeLcafAddress teLcafAddress = address1;
+        LispIpv4Address rtrRloc1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
+        LispIpv4Address rtrRloc2 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
+
+        assertThat("lookup flag value in TeRecord is not correct",
+                    teLcafAddress.getTeRecords().get(0).isLookup(), is(false));
+        assertThat("RLOC probe flag value in TeRecord is not correct",
+                    teLcafAddress.getTeRecords().get(0).isRlocProbe(), is(false));
+        assertThat("strict flag value in TeRecord is not correct",
+                    teLcafAddress.getTeRecords().get(0).isStrict(), is(false));
+        assertThat("RTR RLOC address in TeRecord is not correct",
+                    teLcafAddress.getTeRecords().get(0).getRtrRlocAddress(), is(rtrRloc1));
+
+        assertThat("lookup flag value in TeRecord in not correct",
+                    teLcafAddress.getTeRecords().get(1).isLookup(), is(false));
+        assertThat("RLOC probe flag value in TeRecord is not correct",
+                    teLcafAddress.getTeRecords().get(1).isRlocProbe(), is(true));
+        assertThat("strict flag value in TeRecord is not correct",
+                    teLcafAddress.getTeRecords().get(1).isStrict(), is(false));
+        assertThat("RTR RLOC address in TeRecord is not correct",
+                    teLcafAddress.getTeRecords().get(1).getRtrRlocAddress(), is(rtrRloc2));
+    }
+
+    @Test
+    public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
+        ByteBuf byteBuf = Unpooled.buffer();
+
+        TeLcafAddressWriter writer = new TeLcafAddressWriter();
+        writer.writeTo(byteBuf, address1);
+
+        TeLcafAddressReader reader = new TeLcafAddressReader();
+        LispTeLcafAddress deserialized = reader.readFrom(byteBuf);
+
+        new EqualsTester()
+                .addEqualityGroup(address1, deserialized).testEquals();
+    }
+}