2 * Copyright (c) 2015 Cisco Systems, Inc. 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.nio.ByteBuffer;
12 import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
13 import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
14 import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ServicePathIdType;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ServicePathLcaf;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.service.path.ServicePathBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
26 * Class to (de)serialize Service Path data type.
28 * @author Lorand Jakab
31 public class ServicePathSerializer extends LcafSerializer {
33 private static final ServicePathSerializer INSTANCE = new ServicePathSerializer();
35 // Private constructor prevents instantiation from other classes
36 private ServicePathSerializer() {
39 public static ServicePathSerializer getInstance() {
44 protected byte getLcafType() {
45 return LispCanonicalAddressFormatEnum.SERVICE_PATH.getLispCode();
49 protected short getLcafLength(LispAddress lispAddress) {
50 return (short) (Length.SPI + Length.SI);
54 protected short getAfi() {
55 return (short) AddressFamily.LispCanonicalAddressFormat.getIntValue();
59 protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
60 ServicePath sp = (ServicePath) lispAddress.getAddress();
61 buffer.put(ByteUtil.partialIntToByteArray(NumberUtil.asInt(
62 sp.getServicePath().getServicePathId().getValue().intValue()), Length.SPI));
63 buffer.put((byte) NumberUtil.asShort(sp.getServicePath().getServiceIndex()));
67 protected Eid deserializeLcafEidData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
68 EidBuilder eb = new EidBuilder();
69 eb.setAddressType(ServicePathLcaf.class);
70 eb.setVirtualNetworkId(getVni(ctx));
71 eb.setAddress(deserializeData(buffer));
75 private Address deserializeData(ByteBuffer buffer) {
76 ServicePathBuilder spb = new ServicePathBuilder();
77 byte[] spi = new byte[3];
79 spb.setServicePathId(new ServicePathIdType((long) ByteUtil.getPartialInt(spi)));
80 spb.setServiceIndex((short) ByteUtil.getUnsignedByte(buffer));
81 return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
82 .lisp.address.address.ServicePathBuilder().setServicePath(spb.build()).build();
85 private interface Length {