support lcaf traffic engineering TELSDN-178: #close
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / serializer / address / LispIpv6AddressSerializer.java
1 package org.opendaylight.lispflowmapping.implementation.serializer.address;
2
3 import java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.nio.ByteBuffer;
6
7 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
8 import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
9
10
11 public class LispIpv6AddressSerializer extends LispIPAddressSerializer{
12
13         
14         private static final LispIpv6AddressSerializer INSTANCE = new LispIpv6AddressSerializer();
15
16         // Private constructor prevents instantiation from other classes
17         private LispIpv6AddressSerializer() {
18         }
19
20         public static LispIpv6AddressSerializer getInstance() {
21                 return INSTANCE;
22         }
23         
24         @Override
25     public int getAddressSize(LispAddress lispAddress) {
26         return Length.IPV6;
27     }
28         
29         @Override
30         protected LispIpv6Address deserializeData(ByteBuffer buffer) {
31         byte[] ipBuffer = new byte[16];
32         InetAddress address = null;
33         buffer.get(ipBuffer);
34         try {
35             address = InetAddress.getByAddress(ipBuffer);
36         } catch (UnknownHostException e) {
37             // TODO Auto-generated catch block
38             e.printStackTrace();
39         }
40         return new LispIpv6Address(address);
41     }
42         
43         private interface Length {
44             int IPV6 = 16;
45         }
46
47 }