WIP: Bug 4822: Infra for merging: store source RLOC 54/31854/2
authorLorand Jakab <lojakab@cisco.com>
Mon, 4 Jan 2016 14:30:30 +0000 (16:30 +0200)
committerLorand Jakab <lojakab@cisco.com>
Mon, 4 Jan 2016 14:30:31 +0000 (16:30 +0200)
Add support for storing a list of source RLOCs inside a mapping record,
to be used for merging locators, more specificly, to send Map-Notify
messages to the appropriate xTRs on merge.

Change-Id: Ifbea9ba9471e7edb89bae7db3695828a98ad3f51
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/authentication/LispAuthenticationTest.java
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServerTest.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/serializer/MapRegisterSerializer.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/serializer/MappingRecordSerializer.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/lfm/lisp/proto/rev151105/IpAddressBinaryBuilder.java [new file with mode: 0644]
mappingservice/lisp-proto/src/main/yang/odl-lisp-proto.yang
mappingservice/lisp-proto/src/test/java/org/opendaylight/lispflowmapping/serializer/MapRegisterSerializationTest.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundService.java

index d4e7a2107fbed2ac3444b626dfb9cc421ee32871..9662400a0cd5593952f8422ba396767693f7aeb5 100644 (file)
@@ -44,7 +44,7 @@ public class LispAuthenticationTest extends BaseTestCase {
                 + "00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 " //
                 + "b0 21 27 a8 21 41 04 f3 46 5a 5a 5b 5c 5d 00 00 " //
                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
         assertFalse(LispAuthenticationUtil.validate(mapRegister, "password"));
     }
@@ -65,7 +65,7 @@ public class LispAuthenticationTest extends BaseTestCase {
         MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
                 + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
         assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
         assertFalse(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
@@ -91,7 +91,7 @@ public class LispAuthenticationTest extends BaseTestCase {
                         hexToByteBuffer("38 00 01 01 FF BB " //
                                 + "00 00 00 00 00 00 00 02 00 20 70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d 68 a5 bf 32 11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 00 00 " //
                                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+                                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
         assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
         assertFalse(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
@@ -113,7 +113,7 @@ public class LispAuthenticationTest extends BaseTestCase {
                 + "00 00 00 00 00 00 00 00 00 00 " //
                 + "00 00 " //
                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
         assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
         assertTrue(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
index f797a674396f4e313df5e226215581fc18f51006..fc6d9bb581acee326c65e2dcba737cd403bbf887 100644 (file)
@@ -104,7 +104,7 @@ public class MapServerTest extends BaseTestCase {
                 + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 " //
                 + "ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
         mappingEntriesSaver = new ValueSaverAction<MappingEntry<?>[]>();
     }
index 3569a82e3fd62d865390c7f0a524b02621d899a8..9b6d258cd18535c1161149d53f4ca87a7e98015c 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.lispflowmapping.lisp.serializer;
 
+import java.net.InetAddress;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
@@ -15,6 +16,8 @@ import org.apache.commons.lang3.BooleanUtils;
 import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
 import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
 import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.IpAddressBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.IpAddressBinaryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MessageType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
@@ -77,7 +80,7 @@ public final class MapRegisterSerializer {
         return registerBuffer;
     }
 
-    public MapRegister deserialize(ByteBuffer registerBuffer) {
+    public MapRegister deserialize(ByteBuffer registerBuffer, InetAddress sourceRloc) {
         try {
             MapRegisterBuilder builder = new MapRegisterBuilder();
             builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
@@ -111,6 +114,7 @@ public final class MapRegisterSerializer {
                 for (MappingRecordBuilder mrb : mrbs) {
                     mrb.setXtrId(xtrId);
                     mrb.setSiteId(siteId);
+                    mrb.setSourceRloc(getSourceRloc(sourceRloc));
                     builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(
                             mrb.build()).build());
                 }
@@ -132,6 +136,17 @@ public final class MapRegisterSerializer {
 
     }
 
+    private static IpAddressBinary getSourceRloc(InetAddress sourceRloc) {
+        byte[] srcRloc;
+        if (sourceRloc == null) {
+            srcRloc = InetAddress.getLoopbackAddress().getAddress();
+        } else {
+            srcRloc = sourceRloc.getAddress();
+        }
+
+        return IpAddressBinaryBuilder.getDefaultInstance(srcRloc);
+    }
+
     private interface Flags {
         byte PROXY = 0x08;
         byte XTRSITEID = 0x02;
index d1d4ce7b1b72a5ca9ff5463c5fcad190b1518365..6f7e1b52c0b992613dbc9e1e508d666caa47559a 100644 (file)
@@ -37,7 +37,7 @@ public final class MappingRecordSerializer {
         return deserializeToBuilder(buffer).build();
     }
 
-        public MappingRecordBuilder deserializeToBuilder(ByteBuffer buffer) {
+    public MappingRecordBuilder deserializeToBuilder(ByteBuffer buffer) {
         MappingRecordBuilder builder = new MappingRecordBuilder();
         builder.setRecordTtl(buffer.getInt());
         byte locatorCount = (byte) ByteUtil.getUnsignedByte(buffer);
diff --git a/mappingservice/lisp-proto/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/lfm/lisp/proto/rev151105/IpAddressBinaryBuilder.java b/mappingservice/lisp-proto/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/lfm/lisp/proto/rev151105/IpAddressBinaryBuilder.java
new file mode 100644 (file)
index 0000000..810d6cf
--- /dev/null
@@ -0,0 +1,28 @@
+package org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105;
+
+
+/**
+ * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
+ * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
+ *
+ * The reason behind putting it under src/main/java is:
+ * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
+ * loss of user code.
+ *
+ */
+public class IpAddressBinaryBuilder {
+
+    public static IpAddressBinary getDefaultInstance(java.lang.String defaultValue) {
+        return new IpAddressBinary(Ipv4AddressBinary.getDefaultInstance(defaultValue));
+    }
+
+    public static IpAddressBinary getDefaultInstance(byte[] defaultValue) {
+        if (defaultValue.length == 4) {
+            return new IpAddressBinary(new Ipv4AddressBinary(defaultValue));
+        } else if (defaultValue.length == 16) {
+            return new IpAddressBinary(new Ipv6AddressBinary(defaultValue));
+        }
+        return null;
+    }
+
+}
index aa5588d35184b2f127b6b73f48d69744c0a1abe8..8f1cc423185f156dc8d127b5e77878c3d53a8197 100644 (file)
@@ -21,6 +21,35 @@ module odl-lisp-proto {
         reference "https://tools.ietf.org/html/rfc6830";
     }
 
+    typedef ipv4-address-binary {
+        type binary {
+            length "4";
+        }
+        description
+            "The ipv4-address-binary type represents an IPv4 address in binary
+             in network byte order.";
+    }
+
+    typedef ipv6-address-binary {
+        type binary {
+            length "16";
+        }
+        description
+            "The ipv6-address-binary type represents an IPv6 address in binary
+             in network byte order.";
+    }
+
+    typedef ip-address-binary {
+        type union {
+            type ipv4-address-binary;
+            type ipv6-address-binary;
+        }
+        description
+            "The ip-address-binary type represents an IP address in binary
+             in network byte order, and is IP version neutral.  The length of
+             the byte array implies the IP version.";
+    }
+
     grouping transport-address {
         container transport-address {
             leaf ipAddress {
@@ -88,6 +117,38 @@ module odl-lisp-proto {
         }
     }
 
+    grouping mapping-record-metadata {
+        leaf xtr-id {
+            type binary {
+                length "16";
+            }
+            description
+                "128 bit xTR identifier.";
+        }
+        leaf site-id {
+            type binary {
+                length "8";
+            }
+            description
+                "64 bit site identifier.";
+        }
+        leaf source-rloc {
+            type ip-address-binary;
+            description
+                "The Source IP address used for sending the enclosing control
+                 packet in RLOC space.";
+        }
+        leaf timestamp {
+            type int64;
+            description
+                "Milliseconds since January 1, 1970, 00:00:00 GMT";
+        }
+        description
+            "This is a collection of fields which are not present in the actual
+            mapping record defined in RFC 6830, but are used internally in
+            OpenDaylight";
+    }
+
     grouping mapping-record-container {
         container mapping-record {
             leaf recordTtl {
@@ -116,24 +177,8 @@ module odl-lisp-proto {
             // locator record list
             uses LocatorRecords;
 
-            leaf xtr-id {
-                description "128 bit xTR identifier";
-                type binary {
-                    length "16";
-                }
-            }
-
-            leaf site-id {
-                description "64 bit site identifier";
-                type binary {
-                    length "8";
-                }
-            }
-
-            leaf timestamp {
-                description "Milliseconds since January 1, 1970, 00:00:00 GMT";
-                type int64;
-            }
+            // metadata
+            uses mapping-record-metadata;
         }
     }
 
index b4bcc3ca109b446387d4ae6ece48783eef2cb4b8..d7a35e86d635c1665145467354d5ab633ef6cd68 100644 (file)
@@ -123,7 +123,7 @@ public class MapRegisterSerializationTest extends BaseTestCase {
         ArrayAssert.assertEquals(
                 MapRegisterSerializer.getInstance().serialize(mapRegister).array(),
                 MapRegisterSerializer.getInstance()
-                        .serialize(MapRegisterSerializer.getInstance().deserialize(MapRegisterSerializer.getInstance().serialize(mapRegister)))
+                        .serialize(MapRegisterSerializer.getInstance().deserialize(MapRegisterSerializer.getInstance().serialize(mapRegister), null))
                         .array());
     }
 
@@ -195,7 +195,7 @@ public class MapRegisterSerializationTest extends BaseTestCase {
         //
                 + "00 00 00 00 00 00 00 00 00 00 00 00 " //
                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
         assertTrue(mr.isProxyMapReply());
         assertTrue(mr.isWantMapNotify());
@@ -216,7 +216,7 @@ public class MapRegisterSerializationTest extends BaseTestCase {
                 + "00 00 00 01 00 01 c3 a8 c8 01 0a 32 ff 00 00 04 "
                 + "00 01 ac 10 01 02 15 1a 39 80 e3 35 e6 c4 49 a6 "
                 + "90 87 20 65 9a b7 00 00 00 00 00 00 00 00 ");
-        MapRegister mr = MapRegisterSerializer.getInstance().deserialize(bb);
+        MapRegister mr = MapRegisterSerializer.getInstance().deserialize(bb, null);
 
         assertTrue(mr.isXtrSiteIdPresent());
 
@@ -249,7 +249,7 @@ public class MapRegisterSerializationTest extends BaseTestCase {
                 + "00 00 00 0a 01 20 10 00 00 00 00 01 96 10 fe 01 01 64 " // Record
                 // 4
                 + "ff 00 00 05 00 01 c0 a8 88 0d " // contd
-        ));
+        ), null);
 
         assertEquals(4, mr.getMappingRecordItem().size());
         assertEquals(LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32"), mr.getMappingRecordItem().get(0)
@@ -283,7 +283,7 @@ public class MapRegisterSerializationTest extends BaseTestCase {
                 + "60 11 34 A4 " // priorities + weights
                 + "00 03 " // Flags
                 + "00 01 c0 a8 88 0a " // Locator
-        ));
+        ), null);
 
         assertEquals(1, mr.getMappingRecordItem().size());
         MappingRecordItem eidToLocator = mr.getMappingRecordItem().get(0);
@@ -349,7 +349,7 @@ public class MapRegisterSerializationTest extends BaseTestCase {
                 + "00 00 00 0d 01 20 20 00 03 33 00 01 96 10 fe 01 01 64 " // Record
                 // 3
                 + "ff 00 00 05 00 01 c0 a8 88 0d " // contd
-        ));
+        ), null);
 
         assertEquals(4, mr.getMappingRecordItem().size());
 
@@ -387,7 +387,7 @@ public class MapRegisterSerializationTest extends BaseTestCase {
                 + "00 00 00 00 00 00 00 01 00 14 ec 47 1e 53 25 91 " //
                 + "2f 68 10 75 13 dd 2c e8 6e 3c ac 94 ed e4 00 00 " //
                 + "00 0a 01 20 F0 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
         assertEquals(1, mr.getMappingRecordItem().size());
         assertEquals(Action.NoAction, mr.getMappingRecordItem().get(0).getMappingRecord().getAction());
@@ -411,7 +411,7 @@ public class MapRegisterSerializationTest extends BaseTestCase {
                 + "00 00 00 00 00 00 00 00 00 14 e8 f5 0b c5 c5 f2 " //
                 + "b0 21 27 a8 21 a5 68 89 ec 00 00 " //
                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
     }
 
     @Test
@@ -432,7 +432,7 @@ public class MapRegisterSerializationTest extends BaseTestCase {
                 + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 " //
                 + "ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
         assertTrue(mr.isProxyMapReply());
         assertTrue(mr.isWantMapNotify());
@@ -466,7 +466,7 @@ public class MapRegisterSerializationTest extends BaseTestCase {
                 //
                 + "11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 00 00 " //
                 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
         assertTrue(mr.isProxyMapReply());
         assertTrue(mr.isWantMapNotify());
index f6f21a5e86e2575fb49f929fa45b83d3927904f9..1d87f6ce3c5662db90a21726e47a0485716a8232 100644 (file)
@@ -140,7 +140,7 @@ public class LispSouthboundService implements ILispSouthboundService {
 
     private void handleMapRegister(ByteBuffer inBuffer, InetAddress sourceAddress, int port) {
         try {
-            MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(inBuffer);
+            MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(inBuffer, sourceAddress);
             AddMappingBuilder addMappingBuilder = new AddMappingBuilder();
             addMappingBuilder.setMapRegister(LispNotificationHelper.convertMapRegister(mapRegister));
             TransportAddressBuilder transportAddressBuilder = new TransportAddressBuilder();