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 static java.util.Objects.requireNonNull;
12 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier.Destination;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
16 * Utility class with static methods returning string representations of
17 * supported LISP simple address types.
19 * @author Lorand Jakab
22 public final class LispSimpleAddressStringifier {
23 // Utility class, should not be instantiated
24 private LispSimpleAddressStringifier() {
27 public static String getString(SimpleAddress addr) {
28 return getString(Destination.USER, addr);
31 public static String getString(Destination dst, SimpleAddress addr) {
32 requireNonNull(addr, "address should not be null");
34 if (addr.getIpAddress() != null) {
35 if (addr.getIpAddress().getIpv4Address() != null) {
36 return addr.getIpAddress().getIpv4Address().getValue();
37 } else if (addr.getIpAddress().getIpv6Address() != null) {
38 return addr.getIpAddress().getIpv6Address().getValue();
40 } else if (addr.getIpPrefix() != null) {
41 if (addr.getIpPrefix().getIpv4Prefix() != null) {
42 return addr.getIpPrefix().getIpv4Prefix().getValue();
43 } else if (addr.getIpPrefix().getIpv6Prefix() != null) {
44 return addr.getIpPrefix().getIpv6Prefix().getValue();
46 } else if (addr.getMacAddress() != null) {
47 return addr.getMacAddress().getValue();
48 } else if (addr.getDistinguishedNameType() != null) {
49 return addr.getDistinguishedNameType().getValue();
50 } else if (addr.getAsNumber() != null) {
51 return "AS" + addr.getAsNumber().getValue();
57 protected static String getURLPrefix(SimpleAddress addr) {
58 requireNonNull(addr, "address should not be null");
60 if (addr.getIpAddress() != null) {
61 if (addr.getIpAddress().getIpv4Address() != null) {
63 } else if (addr.getIpAddress().getIpv6Address() != null) {
66 } else if (addr.getIpPrefix() != null) {
67 if (addr.getIpPrefix().getIpv4Prefix() != null) {
69 } else if (addr.getIpPrefix().getIpv6Prefix() != null) {
72 } else if (addr.getMacAddress() != null) {
74 } else if (addr.getDistinguishedNameType() != null) {
76 } else if (addr.getAsNumber() != null) {