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.Inet4Address;
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.LispIpv4Address;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispaddress.lispaddresscontainer.address.ipv4.Ipv4AddressBuilder;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
21 public class LispIpv4AddressSerializer extends LispAddressSerializer {
23 private static final LispIpv4AddressSerializer INSTANCE = new LispIpv4AddressSerializer();
25 // Private constructor prevents instantiation from other classes
26 private LispIpv4AddressSerializer() {
29 public static LispIpv4AddressSerializer getInstance() {
34 public int getAddressSize(LispAFIAddress lispAddress) {
39 protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
40 LispIpv4Address lispIpvAddress = (LispIpv4Address) lispAddress;
42 buffer.put(Inet4Address.getByName(lispIpvAddress.getIpv4Address().getValue()).getAddress());
43 } catch (UnknownHostException e) {
48 protected LispIpv4Address deserializeData(ByteBuffer buffer) {
49 byte[] ipBuffer = new byte[4];
50 InetAddress address = null;
53 address = InetAddress.getByAddress(ipBuffer);
54 } catch (UnknownHostException e) {
56 return new Ipv4AddressBuilder().setIpv4Address(new Ipv4Address(address.getHostAddress())).setAfi(AddressFamilyNumberEnum.IP.getIanaCode()).build();
59 private interface Length {