1 package org.opendaylight.lispflowmapping.southbound.serializer.address;
3 import java.nio.ByteBuffer;
5 import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
6 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
7 import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
9 public class LispSegmentLCAFAddressSerializer extends LispLCAFAddressSerializer{
11 private static final LispSegmentLCAFAddressSerializer INSTANCE = new LispSegmentLCAFAddressSerializer();
13 // Private constructor prevents instantiation from other classes
14 private LispSegmentLCAFAddressSerializer() {
17 public static LispSegmentLCAFAddressSerializer getInstance() {
23 public short getLcafLength(LispAddress lispAddress) {
24 LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
25 return (short) (Length.INSTANCE + serializer.getAddressSize(((LispSegmentLCAFAddress)lispAddress).getAddress()));
29 public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
30 super.internalSerialize(buffer, lispAddress);
31 buffer.putInt(((LispSegmentLCAFAddress)lispAddress).getInstanceId());
32 LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
33 if (serializer == null) {
34 throw new LispMalformedPacketException("Unknown AFI type=" + ((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
36 serializer.serialize(buffer, ((LispSegmentLCAFAddress)lispAddress).getAddress());
40 public LispSegmentLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
41 int instanceId = buffer.getInt();
42 LispAddress address = LispAddressSerializer.getInstance().deserialize(buffer);
44 return new LispSegmentLCAFAddress(res2, instanceId, address);
47 private interface Length {