Move integration tests to mdsal-it-parent
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / util / LispPrimitiveAddressStringifier.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.lispflowmapping.implementation.util;
9
10 import org.opendaylight.lispflowmapping.implementation.util.LispAddressStringifier.Destination;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispsimpleaddress.PrimitiveAddress;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispsimpleaddress.primitiveaddress.AS;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispsimpleaddress.primitiveaddress.DistinguishedName;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispsimpleaddress.primitiveaddress.Ipv4;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispsimpleaddress.primitiveaddress.Ipv6;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispsimpleaddress.primitiveaddress.Mac;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispsimpleaddress.primitiveaddress.No;
18
19 import com.google.common.base.Preconditions;
20
21 /**
22  * Utility class with static methods returning string representations of
23  * supported LISP simple address types
24  *
25  * @author Lorand Jakab
26  *
27  */
28 public class LispPrimitiveAddressStringifier {
29
30     public static String getString(PrimitiveAddress addr) {
31         return getString(Destination.USER, addr);
32     }
33
34     public static String getString(Destination dst, PrimitiveAddress addr) {
35         Preconditions.checkNotNull(addr, "address should not be null");
36
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";
50             } else {
51                 return "" + LispAddressStringifier.noAddrSeq++;
52             }
53         }
54
55         return null;
56     }
57
58     protected static String getURLPrefix(PrimitiveAddress addr) {
59         Preconditions.checkNotNull(addr, "address should not be null");
60
61         if (addr instanceof Ipv4) {
62             return "ipv4";
63         } else if (addr instanceof Ipv6) {
64             return "ipv6";
65         } else if (addr instanceof Mac) {
66             return "mac";
67         } else if (addr instanceof DistinguishedName) {
68             return "dn";
69         } else if (addr instanceof AS) {
70             return "as";
71         } else if (addr instanceof No) {
72             return "no";
73         }
74
75         return null;
76     }
77
78 }