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.implementation.serializer.address;
10 import java.nio.ByteBuffer;
12 import javax.xml.bind.DatatypeConverter;
14 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LispAFIAddress;
15 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LispMacAddress;
16 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.MacBuilder;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
19 public class LispMACAddressSerializer extends LispAddressSerializer {
21 private static final LispMACAddressSerializer INSTANCE = new LispMACAddressSerializer();
23 // Private constructor prevents instantiation from other classes
24 private LispMACAddressSerializer() {
27 public static LispMACAddressSerializer getInstance() {
32 public int getAddressSize(LispAFIAddress lispAddress) {
37 protected LispMacAddress deserializeData(ByteBuffer buffer) {
38 byte[] macBuffer = new byte[6];
39 buffer.get(macBuffer);
40 StringBuilder sb = new StringBuilder(17);
41 for (byte b : macBuffer) {
44 sb.append(String.format("%02x", b));
46 return new MacBuilder().setMacAddress(new MacAddress(sb.toString())).setAfi((short) 16389).build();
50 protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
51 LispMacAddress lispMACAddress = (LispMacAddress) lispAddress;
52 String macString = lispMACAddress.getMacAddress().getValue();
53 macString = macString.replaceAll(":", "");
54 buffer.put(DatatypeConverter.parseHexBinary(macString));
57 private interface Length {