2 * Copyright (c) 2014 Contextream, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.lispflowmapping.lisp.serializer.address;
10 import java.net.Inet6Address;
11 import java.net.InetAddress;
12 import java.net.UnknownHostException;
13 import java.nio.ByteBuffer;
15 import org.opendaylight.lispflowmapping.lisp.type.AddressFamilyNumberEnum;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispAFIAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.LispIpv6Address;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv6.Ipv6AddressBuilder;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
21 public class LispIpv6AddressSerializer extends LispAddressSerializer {
23 private static final LispIpv6AddressSerializer INSTANCE = new LispIpv6AddressSerializer();
25 // Private constructor prevents instantiation from other classes
26 private LispIpv6AddressSerializer() {
29 public static LispIpv6AddressSerializer getInstance() {
34 public int getAddressSize(LispAFIAddress lispAddress) {
39 protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
40 LispIpv6Address lispIpvAddress = (LispIpv6Address) lispAddress;
42 buffer.put(Inet6Address.getByName(lispIpvAddress.getIpv6Address().getValue()).getAddress());
43 } catch (UnknownHostException e) {
48 protected LispIpv6Address deserializeData(ByteBuffer buffer) {
49 byte[] ipBuffer = new byte[16];
50 InetAddress address = null;
53 address = InetAddress.getByAddress(ipBuffer);
54 } catch (UnknownHostException e) {
56 return new Ipv6AddressBuilder().setIpv6Address(new Ipv6Address(address.getHostAddress())).setAfi((short) AddressFamilyNumberEnum.IP6.getIanaCode())
60 private interface Length {