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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AsNumber;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedName;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.NoAddress;
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 LispSimpleAddressStringifier {
30 public static String getString(SimpleAddress addr) {
31 return getString(Destination.USER, addr);
34 public static String getString(Destination dst, SimpleAddress addr) {
35 Preconditions.checkNotNull(addr, "address should not be null");
37 if (addr instanceof Ipv4) {
38 return ((Ipv4) addr).getIpv4().getValue();
39 } else if (addr instanceof Ipv6) {
40 return ((Ipv6) addr).getIpv6().getValue();
41 } else if (addr instanceof Mac) {
42 return ((Mac) addr).getMac().getValue();
43 } else if (addr instanceof DistinguishedName) {
44 return ((DistinguishedName) addr).getDistinguishedName().getValue();
45 } else if (addr instanceof AsNumber) {
46 return "AS" + ((AsNumber) addr).getAsNumber().getValue();
47 } else if (addr instanceof NoAddress) {
48 if (dst == Destination.USER) {
49 return "No Address Present";
51 return "" + LispAddressStringifier.noAddrSeq++;
58 protected static String getURLPrefix(SimpleAddress 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 AsNumber) {
71 } else if (addr instanceof NoAddress) {