[ONOS-4718] Initial implementation of LISP address serializer
Change-Id: I71e1923f6daf1abdf2bf9798a9e421c81926a45c
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispSourceDestLcafAddress.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispSourceDestLcafAddress.java
index 9da4a18..80dd538 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispSourceDestLcafAddress.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/LispSourceDestLcafAddress.java
@@ -18,6 +18,7 @@
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 java.util.Objects;
@@ -200,7 +201,7 @@
/**
* Sets destination address prefix.
*
- * @param dstPrefix
+ * @param dstPrefix destination prefix
* @return SourceDestAddressBuilder object
*/
public SourceDestAddressBuilder withDstPrefix(LispAfiAddress dstPrefix) {
@@ -283,4 +284,25 @@
.build();
}
}
+
+ /**
+ * SourceDest LCAF address writer class.
+ */
+ public static class SourceDestLcafAddressWriter
+ implements LispAddressWriter<LispSourceDestLcafAddress> {
+
+ @Override
+ public void writeTo(ByteBuf byteBuf, LispSourceDestLcafAddress address)
+ throws LispWriterException {
+
+ LispLcafAddress.serializeCommon(byteBuf, address);
+
+ byteBuf.writeShort(address.getReserved());
+ byteBuf.writeByte(address.getSrcMaskLength());
+ byteBuf.writeByte(address.getDstMaskLength());
+ AfiAddressWriter writer = new LispAfiAddress.AfiAddressWriter();
+ writer.writeTo(byteBuf, address.getSrcPrefix());
+ writer.writeTo(byteBuf, address.getDstPrefix());
+ }
+ }
}