1 package org.opendaylight.lispflowmapping.implementation.serializer.address;
3 import java.nio.ByteBuffer;
5 import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
6 import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
7 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
8 import org.opendaylight.lispflowmapping.type.lisp.address.LispApplicationDataLCAFAddress;
9 import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
11 public class LispApplicationDataLCAFAddressSerializer extends LispLCAFAddressSerializer {
13 private static final LispApplicationDataLCAFAddressSerializer INSTANCE = new LispApplicationDataLCAFAddressSerializer();
15 // Private constructor prevents instantiation from other classes
16 private LispApplicationDataLCAFAddressSerializer() {
19 public static LispApplicationDataLCAFAddressSerializer getInstance() {
24 public short getLcafLength(LispAddress lispAddress) {
25 LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(((LispApplicationDataLCAFAddress) lispAddress).getAddress()
27 return (short) (Length.ALL_FIELDS + serializer.getAddressSize(lispAddress));
31 public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
32 super.internalSerialize(buffer, lispAddress);
33 LispApplicationDataLCAFAddress applicationDataAddress = ((LispApplicationDataLCAFAddress) lispAddress);
34 buffer.put(ByteUtil.partialIntToByteArray(applicationDataAddress.getIPTos(), Length.TOC));
35 buffer.put(applicationDataAddress.getProtocol());
36 buffer.putShort(applicationDataAddress.getLocalPort());
37 buffer.putShort(applicationDataAddress.getRemotePort());
38 LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(applicationDataAddress.getAddress().getAfi());
39 if (serializer == null) {
40 throw new LispSerializationException("Unknown AFI type=" + ((LispSegmentLCAFAddress) lispAddress).getAddress().getAfi());
42 serializer.serialize(buffer, ((LispApplicationDataLCAFAddress) lispAddress).getAddress());
46 public LispApplicationDataLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
48 LispApplicationDataLCAFAddress applicationDataAddress = new LispApplicationDataLCAFAddress(res2);
49 byte[] rawIPTos = new byte[3];
51 applicationDataAddress.setIPTos(ByteUtil.getPartialInt(rawIPTos));
52 applicationDataAddress.setProtocol(buffer.get());
53 applicationDataAddress.setLocalPort(buffer.getShort());
54 applicationDataAddress.setRemotePort(buffer.getShort());
55 LispAddress address = LispAddressSerializer.getInstance().deserialize(buffer);
56 applicationDataAddress.setAddress(address);
58 return applicationDataAddress;
61 private interface Length {
66 int ALL_FIELDS = LOCAL_PORT + REMOTE_PORT + TOC + PROTOCOL;