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 com.google.common.collect.ImmutableSet;
11 import java.nio.ByteBuffer;
13 import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
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.SimpleAddress;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.afi.list.AfiList;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.afi.list.AfiListBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder;
26 public final class AfiListSerializer extends LcafSerializer {
27 private static final AfiListSerializer INSTANCE = new AfiListSerializer();
29 // Private constructor prevents instantiation from other classes
30 private AfiListSerializer() {
33 public static AfiListSerializer getInstance() {
38 protected byte getLcafType() {
39 return LispCanonicalAddressFormatEnum.LIST.getLispCode();
43 protected short getLcafLength(LispAddress lispAddress) {
45 AfiList afiList = ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
46 .lisp.address.address.AfiList) lispAddress.getAddress()).getAfiList();
47 for (SimpleAddress address : afiList.getAddressList()) {
48 totalSize += SimpleAddressSerializer.getInstance().getAddressSize(address);
54 protected short getAfi() {
55 return (short) AddressFamily.LispCanonicalAddressFormat.getIntValue();
59 protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
60 AfiList afiList = (((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105
61 .lisp.address.address.AfiList) lispAddress.getAddress()).getAfiList());
62 for (SimpleAddress address : afiList.getAddressList()) {
63 SimpleAddressSerializer.getInstance().serialize(buffer, address);
68 public Eid deserializeLcafEidData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
69 EidBuilder eb = new EidBuilder();
70 eb.setAddressType(AfiListLcaf.class);
71 eb.setVirtualNetworkId(getVni(ctx));
72 eb.setAddress(deserializeData(buffer, length, ctx));
77 public Rloc deserializeLcafRlocData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
78 RlocBuilder rb = new RlocBuilder();
79 rb.setAddressType(AfiListLcaf.class);
80 rb.setVirtualNetworkId(getVni(ctx));
81 rb.setAddress(deserializeData(buffer, length, ctx));
85 private static Address deserializeData(ByteBuffer buffer, short lcafLength, LispAddressSerializerContext ctx) {
86 final Set<SimpleAddress> addresses;
88 ImmutableSet.Builder<SimpleAddress> builder = ImmutableSet.builderWithExpectedSize(lcafLength);
89 short length = lcafLength;
91 SimpleAddress address = SimpleAddressSerializer.getInstance().deserialize(buffer, ctx);
92 length -= SimpleAddressSerializer.getInstance().getAddressSize(address);
95 addresses = builder.build();
100 return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp
101 .address.address.AfiListBuilder().setAfiList(new AfiListBuilder().setAddressList(addresses).build())