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 java.util.HashMap;
13 import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ApplicationDataLcaf;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AsNumberAfi;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameAfi;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ExplicitLocatorPathLcaf;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdLcaf;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4PrefixAfi;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6PrefixAfi;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.KeyValueAddressLcaf;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Lcaf;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.NoAddressAfi;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ServicePathLcaf;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4BinaryAfi;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6BinaryAfi;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6PrefixBinaryAfi;
39 * This class contains static HashMaps of AFIs and LCAF types to LispAddressFamily identities.
41 * @author Lorand Jakab
44 public final class AddressTypeMap {
45 private static Map<Short, Class<? extends LispAddressFamily>> afiToAddressTypeMap;
46 private static Map<Short, Class<? extends LispAddressFamily>> lcafToAddressTypeMap;
48 // Utility class, should not be instantiated
49 private AddressTypeMap() {
52 private static void initializeAfiMap() {
53 afiToAddressTypeMap = new HashMap<Short, Class<? extends LispAddressFamily>>();
54 afiToAddressTypeMap.put((short) 0, NoAddressAfi.class);
55 afiToAddressTypeMap.put((short) AddressFamily.IpV4.getIntValue(), Ipv4BinaryAfi.class);
56 afiToAddressTypeMap.put((short) (AddressFamily.IpV4.getIntValue() * -1), Ipv4PrefixBinaryAfi.class);
57 afiToAddressTypeMap.put((short) AddressFamily.IpV6.getIntValue(), Ipv6BinaryAfi.class);
58 afiToAddressTypeMap.put((short) (AddressFamily.IpV6.getIntValue() * -1), Ipv6PrefixBinaryAfi.class);
59 afiToAddressTypeMap.put((short) AddressFamily.DistinguishedName.getIntValue(), DistinguishedNameAfi.class);
60 afiToAddressTypeMap.put((short) AddressFamily.AsNumber.getIntValue(), AsNumberAfi.class);
61 afiToAddressTypeMap.put((short) AddressFamily.LispCanonicalAddressFormat.getIntValue(), Lcaf.class);
62 afiToAddressTypeMap.put((short) AddressFamily._48BitMac.getIntValue(), MacAfi.class);
65 private static void initializeLcafMap() {
66 lcafToAddressTypeMap = new HashMap<Short, Class<? extends LispAddressFamily>>();
67 lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.LIST.getLispCode(), AfiListLcaf.class);
68 lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.SEGMENT.getLispCode(), InstanceIdLcaf.class);
69 lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.APPLICATION_DATA.getLispCode(),
70 ApplicationDataLcaf.class);
71 lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING.getLispCode(),
72 ExplicitLocatorPathLcaf.class);
73 lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode(),
74 SourceDestKeyLcaf.class);
75 lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.KEY_VALUE.getLispCode(),
76 KeyValueAddressLcaf.class);
77 lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.SERVICE_PATH.getLispCode(),
78 ServicePathLcaf.class);
82 public static Class<? extends LispAddressFamily> getAddressType(short afi) {
83 if (afiToAddressTypeMap == null) {
86 return afiToAddressTypeMap.get(afi);
89 public static Class<? extends LispAddressFamily> getLcafType(short lcafType) {
90 if (lcafToAddressTypeMap == null) {
93 return lcafToAddressTypeMap.get(lcafType);
96 public static Class<? extends LispAddressFamily> getSimpleAddressInnerType(SimpleAddress address) {
97 if (address == null) {
99 } else if (address.getIpAddress() != null) {
100 if (address.getIpAddress().getIpv4Address() != null) {
101 return Ipv4Afi.class;
102 } else if (address.getIpAddress().getIpv6Address() != null) {
103 return Ipv6Afi.class;
105 } else if (address.getIpPrefix() != null) {
106 if (address.getIpPrefix().getIpv4Prefix() != null) {
107 return Ipv4PrefixAfi.class;
108 } else if (address.getIpPrefix().getIpv6Prefix() != null) {
109 return Ipv6PrefixAfi.class;
111 } else if (address.getMacAddress() != null) {
113 } else if (address.getAsNumber() != null) {
114 return AsNumberAfi.class;
115 } else if (address.getDistinguishedNameType() != null) {
116 return DistinguishedNameAfi.class;