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.util;
10 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier.Destination;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.PrimitiveAddress;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.AS;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.DistinguishedName;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv6;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Mac;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.No;
19 import com.google.common.base.Preconditions;
22 * Utility class with static methods returning string representations of
23 * supported LISP simple address types
25 * @author Lorand Jakab
28 public class LispPrimitiveAddressStringifier {
30 public static String getString(PrimitiveAddress addr) {
31 return getString(Destination.USER, addr);
34 public static String getString(Destination dst, PrimitiveAddress addr) {
35 Preconditions.checkNotNull(addr, "address should not be null");
37 if (addr instanceof Ipv4) {
38 return ((Ipv4) addr).getIpv4Address().getIpv4Address().getValue();
39 } else if (addr instanceof Ipv6) {
40 return ((Ipv6) addr).getIpv6Address().getIpv6Address().getValue();
41 } else if (addr instanceof Mac) {
42 return ((Mac) addr).getMacAddress().getMacAddress().getValue();
43 } else if (addr instanceof DistinguishedName) {
44 return ((DistinguishedName) addr).getDistinguishedNameAddress().getDistinguishedName();
45 } else if (addr instanceof AS) {
46 return "AS" + ((AS) addr).getASAddress().getAS();
47 } else if (addr instanceof No) {
48 if (dst == Destination.USER) {
49 return "No Address Present";
51 return "" + LispAddressStringifier.noAddrSeq++;
58 protected static String getURLPrefix(PrimitiveAddress addr) {
59 Preconditions.checkNotNull(addr, "address should not be null");
61 if (addr instanceof Ipv4) {
63 } else if (addr instanceof Ipv6) {
65 } else if (addr instanceof Mac) {
67 } else if (addr instanceof DistinguishedName) {
69 } else if (addr instanceof AS) {
71 } else if (addr instanceof No) {