1 package org.opendaylight.lispflowmapping.implementation.serializer.address;
3 import java.nio.ByteBuffer;
5 import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
6 import org.opendaylight.lispflowmapping.implementation.util.LispAFIConvertor;
7 import org.opendaylight.lispflowmapping.implementation.util.NumberUtil;
8 import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
9 import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
10 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LcafApplicationDataAddress;
11 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LispAFIAddress;
12 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lcafapplicationdataaddress.AddressBuilder;
13 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.LcafApplicationDataBuilder;
14 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispsimpleaddress.PrimitiveAddress;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
17 public class LispApplicationDataLCAFAddressSerializer extends LispLCAFAddressSerializer {
19 private static final LispApplicationDataLCAFAddressSerializer INSTANCE = new LispApplicationDataLCAFAddressSerializer();
21 // Private constructor prevents instantiation from other classes
22 private LispApplicationDataLCAFAddressSerializer() {
25 public static LispApplicationDataLCAFAddressSerializer getInstance() {
30 protected short getLcafLength(LispAFIAddress lispAddress) {
31 return (short) (Length.ALL_FIELDS + LispAddressSerializer.getInstance().getAddressSize(
32 (LispAFIAddress) ((LcafApplicationDataAddress) lispAddress).getAddress().getPrimitiveAddress()));
36 protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
37 LcafApplicationDataAddress applicationDataAddress = ((LcafApplicationDataAddress) lispAddress);
38 buffer.put(ByteUtil.partialIntToByteArray(applicationDataAddress.getIpTos(), Length.TOC));
39 buffer.put(NumberUtil.asByte(applicationDataAddress.getProtocol().byteValue()));
40 buffer.putShort(applicationDataAddress.getLocalPort().getValue().shortValue());
41 buffer.putShort(applicationDataAddress.getRemotePort().getValue().shortValue());
42 LispAddressSerializer.getInstance().serialize(buffer,
43 (LispAFIAddress) ((LcafApplicationDataAddress) lispAddress).getAddress().getPrimitiveAddress());
47 protected LcafApplicationDataAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
49 LcafApplicationDataBuilder builder = new LcafApplicationDataBuilder();
50 byte[] rawIPTos = new byte[3];
52 builder.setIpTos(ByteUtil.getPartialInt(rawIPTos));
53 builder.setProtocol((short) buffer.get());
54 builder.setLocalPort(new PortNumber(new Integer(buffer.getShort())));
55 builder.setRemotePort(new PortNumber(new Integer(buffer.getShort())));
56 LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(buffer);
57 builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType((short) LispCanonicalAddressFormatEnum.APPLICATION_DATA.getLispCode())
58 .setAddress(new AddressBuilder().setPrimitiveAddress((PrimitiveAddress) LispAFIConvertor.toPrimitive(address)).build());
60 return builder.build();
63 private interface Length {
68 int ALL_FIELDS = LOCAL_PORT + REMOTE_PORT + TOC + PROTOCOL;