Make source-dest-key-lcaf use simple-address 72/30672/1
authorLorand Jakab <lojakab@cisco.com>
Thu, 3 Dec 2015 23:34:48 +0000 (01:34 +0200)
committerLorand Jakab <lojakab@cisco.com>
Thu, 3 Dec 2015 23:34:49 +0000 (01:34 +0200)
Change-Id: I406b0c7babc30dd43db0c5163df8339fb15a9130
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
mappingservice/integrationtest/src/test/java/org/opendaylight/lispflowmapping/integrationtest/MappingServiceIntegrationTest.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/serializer/address/SourceDestKeySerializer.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/util/LispAddressUtil.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/util/SourceDestKeyHelper.java
mappingservice/lisp-proto/src/main/yang/ietf-lisp-address-types.yang
mappingservice/lisp-proto/src/test/java/org/opendaylight/lispflowmapping/serializer/address/SourceDestKeySerializerTest.java

index b000dbf84d9acfcc3168194ee06afbf6506240d0..cb8f4f12e00204ad4b8b06e4999742d7fcfc3fd2 100644 (file)
@@ -29,11 +29,6 @@ import java.util.List;
 
 import javax.inject.Inject;
 
-
-
-
-
-
 //import org.codehaus.jettison.json.JSONException;
 //import org.codehaus.jettison.json.JSONObject;
 //import org.codehaus.jettison.json.JSONTokener;
@@ -109,6 +104,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.addres
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.Hop;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.Hop.LrsBits;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.HopBuilder;
+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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
@@ -1217,41 +1213,42 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase {
     }
 
     // ------------------------------- LCAF Tests ---------------------------
-/*
+
     @Test
     public void registerAndQuery__SrcDestLCAF() throws SocketTimeoutException {
         cleanUP();
-        String ipString = "10.20.30.200";
+        String ipPrefix = "10.20.30.200/32";
         String macString = "01:02:03:04:05:06";
-        org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Ipv4 addrToSend1 = LispAddressUtil.asPrimitiveIPv4AfiPrefix(ipString, 32);
-        org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lispsimpleaddress.primitiveaddress.Mac addrToSend2 = LispAddressUtil.asPrimitiveMacAfiAddress(macString);
-        LcafSourceDestAddrBuilder builder = new LcafSourceDestAddrBuilder();
-        builder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode());
-        builder.setLcafType((short) LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode());
-        builder.setSrcMaskLength((short) 32);
-        builder.setDstMaskLength((short) 0);
-        builder.setSrcAddress(new SrcAddressBuilder().setPrimitiveAddress(addrToSend1).build());
-        builder.setDstAddress(new DstAddressBuilder().setPrimitiveAddress(addrToSend2).build());
-
-        MapReply reply = registerAddressAndQuery(builder.build());
+
+        SourceDestKeyBuilder builder = new SourceDestKeyBuilder();
+        builder.setSource(new SimpleAddress(new IpPrefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix(ipPrefix))));
+        builder.setDest(new SimpleAddress(new MacAddress(macString)));
+
+        EidBuilder eb = new EidBuilder();
+        eb.setAddressType(SourceDestKeyLcaf.class);
+        eb.setVirtualNetworkId(null);
+        eb.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKeyBuilder()
+                .setSourceDestKey(builder.build()).build());
+
+        MapReply reply = registerAddressAndQuery(eb.build());
 
         Eid fromNetwork = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
-        assertTrue(fromNetwork.getAddress() instanceof LcafSourceDest);
-        LcafSourceDest sourceDestFromNetwork = (LcafSourceDest) fromNetwork.getAddress();
+        assertEquals(SourceDestKeyLcaf.class, fromNetwork.getAddressType());
+        SourceDestKey sourceDestFromNetwork = (SourceDestKey) fromNetwork.getAddress();
 
-        LispAFIAddress receivedAddr1 = LispAddressUtil.toAFIfromPrimitive(sourceDestFromNetwork.getLcafSourceDestAddr().getSrcAddress().getPrimitiveAddress());
-        LispAFIAddress receivedAddr2 = LispAddressUtil.toAFIfromPrimitive(sourceDestFromNetwork.getLcafSourceDestAddr().getDstAddress().getPrimitiveAddress());
+        SimpleAddress receivedAddr1 = sourceDestFromNetwork.getSourceDestKey().getSource();
+        SimpleAddress receivedAddr2 = sourceDestFromNetwork.getSourceDestKey().getDest();
 
-        assertTrue(receivedAddr1 instanceof LispIpv4Address);
-        assertTrue(receivedAddr2 instanceof LispMacAddress);
+        assertNotNull(receivedAddr1.getIpPrefix().getIpv4Prefix());
+        assertNotNull(receivedAddr2.getMacAddress());
 
-        LispIpv4Address receivedIP = (LispIpv4Address) receivedAddr1;
-        LispMacAddress receivedMAC = (LispMacAddress) receivedAddr2;
+        IpPrefix receivedIP = receivedAddr1.getIpPrefix();
+        MacAddress receivedMAC = receivedAddr2.getMacAddress();
 
-        assertEquals(ipString, receivedIP.getIpv4Address().getValue());
-        assertEquals(macString, receivedMAC.getMacAddress().getValue());
+        assertEquals(ipPrefix, receivedIP.getIpv4Prefix().getValue());
+        assertEquals(macString, receivedMAC.getValue());
     }
-*/
+
     @Test
     public void registerAndQuery__SrcDestLCAFOverlap() throws SocketTimeoutException {
         cleanUP();
@@ -1271,8 +1268,8 @@ public class MappingServiceIntegrationTest extends AbstractMdsalTestBase {
         assertEquals(SourceDestKeyLcaf.class, fromNetwork.getAddressType());
         SourceDestKey sourceDestFromNetwork = (SourceDestKey) fromNetwork.getAddress();
 
-        IpPrefix receivedAddr1 = sourceDestFromNetwork.getSourceDestKey().getSource();
-        IpPrefix receivedAddr2 = sourceDestFromNetwork.getSourceDestKey().getDest();
+        IpPrefix receivedAddr1 = sourceDestFromNetwork.getSourceDestKey().getSource().getIpPrefix();
+        IpPrefix receivedAddr2 = sourceDestFromNetwork.getSourceDestKey().getDest().getIpPrefix();
 
         assertNotNull(receivedAddr1.getIpv4Prefix());
         assertNotNull(receivedAddr2.getIpv4Prefix());
index dd595c35eed1a67402556fc0374e32712cc7e2a5..85aadc6ebd7ed97759a5f6889c567f41b5e9e5f0 100644 (file)
@@ -58,8 +58,19 @@ public class SourceDestKeySerializer extends LcafSerializer {
     protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
         SourceDestKey sdk = (SourceDestKey) lispAddress.getAddress();
         buffer.putShort((short) 0);
-        buffer.put((byte) MaskUtil.getMaskForIpPrefix(sdk.getSourceDestKey().getSource()));
-        buffer.put((byte) MaskUtil.getMaskForIpPrefix(sdk.getSourceDestKey().getDest()));
+        short srcMaskLength = MaskUtil.getMaskForAddress(sdk.getSourceDestKey().getSource());
+        short dstMaskLength = MaskUtil.getMaskForAddress(sdk.getSourceDestKey().getDest());
+        // TODO need to use LispAddressSerializerContext.MASK_LEN_MISSING everywhere instead of -1 but move that from
+        // LispAddressSerializerContext to some more generic place, maybe
+        // org.opendaylight.lispflowmammping.type.Constants
+        if (srcMaskLength == -1) {
+            srcMaskLength = 0;
+        }
+        if (dstMaskLength == -1) {
+            dstMaskLength = 0;
+        }
+        buffer.put((byte) srcMaskLength);
+        buffer.put((byte) dstMaskLength);
         SimpleAddressSerializer.getInstance().serialize(buffer, new SimpleAddress(sdk.getSourceDestKey().getSource()));
         SimpleAddressSerializer.getInstance().serialize(buffer, new SimpleAddress(sdk.getSourceDestKey().getDest()));
     }
@@ -91,8 +102,8 @@ public class SourceDestKeySerializer extends LcafSerializer {
         ctx.setMaskLen(dstMaskLength);
         SimpleAddress dstAddress = SimpleAddressSerializer.getInstance().deserialize(buffer, ctx);
         SourceDestKeyBuilder sdb = new SourceDestKeyBuilder();
-        sdb.setSource(srcAddress.getIpPrefix());
-        sdb.setDest(dstAddress.getIpPrefix());
+        sdb.setSource(srcAddress);
+        sdb.setDest(dstAddress);
         return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKeyBuilder()
                 .setSourceDestKey(sdb.build()).build();
     }
index 96de8cbebb7a4b80ae397e126b14e2bbc13cdf89..0f51e55b08be10d0a594c693e533af0580a12c7d 100644 (file)
@@ -15,6 +15,7 @@ import java.util.List;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 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.Ipv4Address;
@@ -37,6 +38,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.addres
 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.SourceDestKeyLcaf;
 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.AsNumberBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedNameBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder;
@@ -93,8 +95,13 @@ public class LispAddressUtil {
             return addressFromIpAddress(address.getIpAddress());
         } else if (address.getIpPrefix() != null) {
             return addressFromIpPrefix(address.getIpPrefix());
+        } else if (address.getMacAddress() != null) {
+            return addressFromMacAddress(address.getMacAddress());
+        } else if (address.getDistinguishedNameType() != null) {
+            return addressFromDistinguishedName(address.getDistinguishedNameType());
+        } else if (address.getAsNumber() != null) {
+            return addressFromAsNumber(address.getAsNumber());
         }
-        // TODO the rest of the types
         return null;
     }
 
@@ -162,6 +169,29 @@ public class LispAddressUtil {
         return null;
     }
 
+    public static Address addressFromMacAddress(MacAddress address) {
+        if (address == null) {
+            return null;
+        } else {
+            return (Address) new MacBuilder().setMac(address).build();
+        }
+    }
+
+    public static Address addressFromDistinguishedName(DistinguishedNameType address) {
+        if (address == null) {
+            return null;
+        } else {
+            return (Address) new DistinguishedNameBuilder().setDistinguishedName(address).build();
+        }
+    }
+
+    public static Address addressFromAsNumber(AsNumber address) {
+        if (address == null) {
+            return null;
+        } else {
+            return (Address) new AsNumberBuilder().setAsNumber(address).build();
+        }
+    }
     public static Rloc toRloc(SimpleAddress address) {
         RlocBuilder builder = new RlocBuilder();
         builder.setAddressType(addressTypeFromSimpleAddress(address));
@@ -218,12 +248,12 @@ public class LispAddressUtil {
         return builder.build();
     }
 
-    public static Eid toEid(Eid eid, IpPrefix prefix) {
+    public static Eid toEid(Eid eid, SimpleAddress address) {
         EidBuilder builder = new EidBuilder();
         builder.setAddressType(eid.getAddressType());
         builder.setVirtualNetworkId(eid.getVirtualNetworkId());
         // XXX Not sure if the below actually works as expected... also, what happens to AFI?
-        builder.setAddress(addressFromIpPrefix(prefix));
+        builder.setAddress(addressFromSimpleAddress(address));
         return builder.build();
     }
 
@@ -391,8 +421,8 @@ public class LispAddressUtil {
 
     public static SourceDestKey asSrcDst(String src, String dst, int smask, int dmask) {
         SourceDestKeyBuilder builder = new SourceDestKeyBuilder();
-        builder.setSource(asIpPrefix(src, smask));
-        builder.setDest(asIpPrefix(dst, dmask));
+        builder.setSource(new SimpleAddress(asIpPrefix(src, smask)));
+        builder.setDest(new SimpleAddress(asIpPrefix(dst, dmask)));
         return builder.build();
     }
 
index 8873d217ed603681f4b2a9c04b218b618e07a401..3aa1999a44f870f1aac58a6704467a47fea53dee 100644 (file)
@@ -44,7 +44,7 @@ public class SourceDestKeyHelper {
         if (!isSrcDst(addr)) {
             return 0;
         }
-        return MaskUtil.getMaskForIpPrefix(((SourceDestKey)addr).getSourceDestKey().getSource());
+        return MaskUtil.getMaskForAddress(((SourceDestKey)addr).getSourceDestKey().getSource());
     }
 
     public static short getDstMask(Eid eid) {
@@ -52,7 +52,7 @@ public class SourceDestKeyHelper {
         if (!isSrcDst(addr)) {
             return 0;
         }
-        return MaskUtil.getMaskForIpPrefix(((SourceDestKey)addr).getSourceDestKey().getDest());
+        return MaskUtil.getMaskForAddress(((SourceDestKey)addr).getSourceDestKey().getDest());
     }
 
     private static boolean isSrcDst(Address addr) {
index d4ea01f52efa2218ab58d6157ecd2d1517f92eed..ce2c537404073d7a05338204b12f1375e6c46394 100644 (file)
@@ -614,14 +614,14 @@ module ietf-lisp-address-types {
             "http://tools.ietf.org/html/draft-ietf-lisp-lcaf-10
             #section-4.11";
         leaf source {
-          type inet:ip-prefix;
+          type simple-address;
           description
-            "Source prefix.";
+            "Source address.";
         }
         leaf dest {
-          type inet:ip-prefix;
+          type simple-address;
           description
-            "Destination prefix.";
+            "Destination address.";
         }
       }
       container key-value-address {
index cd9338642b66ad133fc688d4bdecbc17720b0f82..7fbc3cb22800859c5a4efc1cfd0ab74426b8779a 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
 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.lisp.address.types.rev151105.SimpleAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
 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.SourceDestKey;
@@ -42,8 +43,8 @@ public class SourceDestKeySerializerTest extends BaseTestCase {
         assertEquals(SourceDestKeyLcaf.class, address.getAddressType());
         SourceDestKey srcDestAddress = (SourceDestKey) address.getAddress();
 
-        assertEquals((byte) 0x10, MaskUtil.getMaskForIpPrefix(srcDestAddress.getSourceDestKey().getSource()));
-        assertEquals((byte) 0x18, MaskUtil.getMaskForIpPrefix(srcDestAddress.getSourceDestKey().getDest()));
+        assertEquals((byte) 0x10, MaskUtil.getMaskForAddress(srcDestAddress.getSourceDestKey().getSource()));
+        assertEquals((byte) 0x18, MaskUtil.getMaskForAddress(srcDestAddress.getSourceDestKey().getDest()));
 
         assertEquals("17.34.51.68/16", String.valueOf(srcDestAddress.getSourceDestKey().getSource().getValue()));
         assertEquals("34.51.68.85/24", String.valueOf(srcDestAddress.getSourceDestKey().getDest().getValue()));
@@ -85,8 +86,8 @@ public class SourceDestKeySerializerTest extends BaseTestCase {
     @Test
     public void serialize__Simple() throws Exception {
         SourceDestKeyBuilder addressBuilder = new SourceDestKeyBuilder();
-        addressBuilder.setSource(new IpPrefix(new Ipv4Prefix("17.34.51.68/8")));
-        addressBuilder.setDest(new IpPrefix(new Ipv4Prefix("34.51.68.85/16")));
+        addressBuilder.setSource(new SimpleAddress(new IpPrefix(new Ipv4Prefix("17.34.51.68/8"))));
+        addressBuilder.setDest(new SimpleAddress(new IpPrefix(new Ipv4Prefix("34.51.68.85/16"))));
 
         EidBuilder eb = new EidBuilder();
         eb.setAddressType(SourceDestKeyLcaf.class);