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 com.google.common.base.Preconditions;
11 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier.Destination;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
15 * Utility class with static methods returning string representations of
16 * supported LISP simple address types.
18 * @author Lorand Jakab
21 public final class LispSimpleAddressStringifier {
22 // Utility class, should not be instantiated
23 private LispSimpleAddressStringifier() {
26 public static String getString(SimpleAddress addr) {
27 return getString(Destination.USER, addr);
30 public static String getString(Destination dst, SimpleAddress addr) {
31 Preconditions.checkNotNull(addr, "address should not be null");
33 if (addr.getIpAddress() != null) {
34 if (addr.getIpAddress().getIpv4Address() != null) {
35 return addr.getIpAddress().getIpv4Address().getValue();
36 } else if (addr.getIpAddress().getIpv6Address() != null) {
37 return addr.getIpAddress().getIpv6Address().getValue();
39 } else if (addr.getIpPrefix() != null) {
40 if (addr.getIpPrefix().getIpv4Prefix() != null) {
41 return addr.getIpPrefix().getIpv4Prefix().getValue();
42 } else if (addr.getIpPrefix().getIpv6Prefix() != null) {
43 return addr.getIpPrefix().getIpv6Prefix().getValue();
45 } else if (addr.getMacAddress() != null) {
46 return addr.getMacAddress().getValue();
47 } else if (addr.getDistinguishedNameType() != null) {
48 return (addr.getDistinguishedNameType().getValue());
49 } else if (addr.getAsNumber() != null) {
50 return "AS" + addr.getAsNumber().getValue();
56 protected static String getURLPrefix(SimpleAddress addr) {
57 Preconditions.checkNotNull(addr, "address should not be null");
59 if (addr.getIpAddress() != null) {
60 if (addr.getIpAddress().getIpv4Address() != null) {
62 } else if (addr.getIpAddress().getIpv6Address() != null) {
65 } else if (addr.getIpPrefix() != null) {
66 if (addr.getIpPrefix().getIpv4Prefix() != null) {
68 } else if (addr.getIpPrefix().getIpv6Prefix() != null) {
71 } else if (addr.getMacAddress() != null) {
73 } else if (addr.getDistinguishedNameType() != null) {
75 } else if (addr.getAsNumber() != null) {