Bug 5795: Fix SourceDestKey type check 58/38058/3
authorMiroslav Toth <mirtoth@cisco.com>
Mon, 25 Apr 2016 13:35:54 +0000 (15:35 +0200)
committerMiroslav Toth <mirtoth@cisco.com>
Tue, 26 Apr 2016 09:03:00 +0000 (11:03 +0200)
Change-Id: I5e0a0c839210b4a720de4cf9f187cb42fa9be49d
Signed-off-by: Miroslav Toth <mirtoth@cisco.com>
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/MappingMergeUtil.java

index ed7a8f18257b5fae0ef07576502544b78834f501..3bdb712cc928290321acd33ba6d45479c6d3ece2 100644 (file)
@@ -18,7 +18,10 @@ import java.util.Set;
 
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
@@ -237,15 +240,18 @@ public final class MappingMergeUtil {
             short sbMask = MaskUtil.getMaskForAddress(sbMapping.getEid().getAddress());
             short nbMask = MaskUtil.getMaskForAddress(nbMapping.getEid().getAddress());
 
-            if (nbMapping.getEid().getAddress() instanceof SourceDestKey) {
+            if (nbMapping.getEid().getAddress() instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
+                    .ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey) {
                 nbMask = SourceDestKeyHelper.getDstMask(nbMapping.getEid());
                 if ( nbMask < sbMask) {
                     // We have to create a new SourceDest EID, where the source is same as the
                     // one in NB record, and dest EID is the more specific from SB mapping record.
 
-                    SourceDestKeyBuilder sdb = new SourceDestKeyBuilder(
-                            ((SourceDestKey) nbMapping.getEid().getAddress()));
-                    sdb.setDest(new SimpleAddress ((IpPrefix) sbMapping.getEid().getAddress()));
+                    SourceDestKey srcDstKey = ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp
+                            .address.types.rev151105.lisp.address.address.SourceDestKey) nbMapping.getEid()
+                            .getAddress()).getSourceDestKey();
+                    SourceDestKeyBuilder sdb = new SourceDestKeyBuilder(srcDstKey);
+                    sdb.setDest(new SimpleAddress(getIpPrefix(sbMapping.getEid().getAddress())));
                     mrb.setEid(LispAddressUtil.asSrcDstEid(sdb.build(), nbMapping.getEid().getVirtualNetworkId()));
                 }
             } else if (nbMask < sbMask) {
@@ -304,4 +310,28 @@ public final class MappingMergeUtil {
         return commonLocators;
     }
 
+    private static IpPrefix getIpPrefix(Address address) {
+        IpPrefix ipPrefix = null;
+
+        if (address instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns
+                .yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix) {
+            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp
+                    .address.address.Ipv4Prefix lispPrefix = (org.opendaylight.yang.gen.v1.urn.ietf.params
+                    .xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix) address;
+
+            Ipv4Prefix inetPrefix = new Ipv4Prefix(lispPrefix.getIpv4Prefix());
+            ipPrefix = new IpPrefix(inetPrefix);
+        } else if (address instanceof org.opendaylight.yang.gen.v1.urn.ietf.params
+                .xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix) {
+            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp
+                    .address.address.Ipv6Prefix lispPrefix = (org.opendaylight.yang.gen.v1.urn.ietf.params
+                    .xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix) address;
+
+            Ipv6Prefix inetPrefix = new Ipv6Prefix(lispPrefix.getIpv6Prefix());
+            ipPrefix = new IpPrefix(inetPrefix);
+        } else {
+            LOG.warn("Southbound mapping address is not an IpPrefix");
+        }
+        return ipPrefix;
+    }
 }