Create typedefs for xTR-ID and Site-ID 41/35841/2
authorLorand Jakab <lojakab@cisco.com>
Fri, 4 Mar 2016 19:06:02 +0000 (11:06 -0800)
committerLorand Jakab <lojakab@cisco.com>
Mon, 7 Mar 2016 22:59:39 +0000 (14:59 -0800)
There were a few places where we had site-id and xtr-id leaves, an they
used binary types, not a common type. This patch creates a typedef for
the two data types and uses it consistently throughout the code, for
better type safety.

The patch is in preparation for xTR-ID data store support for
southbound.

Change-Id: Ia45541b4f82fd2697e05686d995a219524e49e99
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
13 files changed:
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/mappingservice/IMappingService.java
mappingservice/api/src/main/yang/odl-mappingservice.yang
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/MappingService.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/MappingSystem.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/mapcache/SimpleMapCache.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/DSBEInputUtil.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/LispNotificationHelper.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/MappingMergeUtil.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/serializer/MapNotifySerializer.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/serializer/MapRegisterSerializer.java
mappingservice/lisp-proto/src/main/yang/odl-lisp-proto.yang
mappingservice/lisp-proto/src/test/java/org/opendaylight/lispflowmapping/serializer/MapRegisterSerializationTest.java

index f81f53d87d9ad8633bc2e11f1b4f9f6490446eba..454970e45401c6e51acb5ff963dfcb0ea312e392 100644 (file)
@@ -8,9 +8,9 @@
 
 package org.opendaylight.lispflowmapping.interfaces.mappingservice;
 
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
 
 /**
index 868f72dcd975d08e5fc03d9b4649e8ee59a8deec..6824323260a0621063b6a1930a685477b07419e9 100644 (file)
@@ -41,13 +41,6 @@ module odl-mappingservice {
         }
     }
 
-    typedef site-id {
-        description "64 bit site identifier";
-        type binary {
-            length "8";
-        }
-    }
-
     typedef vni-uri {
         description "VNI as a string lookup key in a URI";
         type inet:uri;
@@ -126,7 +119,7 @@ module odl-mappingservice {
             }
             leaf-list site-id {
                 description "Site ID";
-                type site-id;
+                type lisp-proto:site-id;
             }
             uses lisp-proto:mapping-record-container;
         }
index 1aa6bd5875a502bd5563cc366c3b5f6e2c2dfa2c..79a0ef4f3eb37970b0d9934ac97d53f1c558ace3 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.lispflowmapping.implementation.util.DSBEInputUtil;
 import org.opendaylight.lispflowmapping.implementation.util.RPCInputConvertorUtil;
 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInput;
@@ -48,7 +49,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev15090
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeysInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveMappingInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveMappingsInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeyInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeysInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingInput;
index 7554e63b17eba6252ebf489bfa8d026268cee6be..6764152ea8c8aa7baf526faa1118188b9810e161 100644 (file)
@@ -30,6 +30,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.Ipv6;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath;
 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.opendaylight.lfm.lisp.proto.rev151105.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
@@ -37,7 +38,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.ma
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
index 2fcc0634ac17e1dbe411a3eb8e4b791632f4f3ec..200cd691a24814fad1f4456b0899b66feb10e587 100644 (file)
@@ -38,6 +38,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
 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.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder;
@@ -53,7 +54,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev15090
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingChanged;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.OdlMappingserviceListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index bf03d3a14ced4fa0a2129c9b7111cab42b2bb85e..4304809d39b332d70488f39b7fc95a0f9b885c34 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.lispflowmapping.implementation.mapcache;
 
 import java.util.AbstractMap.SimpleImmutableEntry;
-import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashSet;
@@ -26,6 +25,7 @@ import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMapCache;
 import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
@@ -84,13 +84,9 @@ public class SimpleMapCache implements IMapCache {
         return table;
     }
 
-    public static Object deserializeBytes(byte[] data) {
-        return ByteBuffer.wrap(data);
-    }
-
-    private void removeExpiredXtrIdTableEntries(ILispDAO xtrIdDao, List<byte[]> expiredMappings) {
-        for (byte[] xtrId : expiredMappings) {
-            xtrIdDao.removeSpecific(deserializeBytes(xtrId), SubKeys.RECORD);
+    private void removeExpiredXtrIdTableEntries(ILispDAO xtrIdDao, List<XtrId> expiredMappings) {
+        for (XtrId xtrId : expiredMappings) {
+            xtrIdDao.removeSpecific(xtrId, SubKeys.RECORD);
         }
     }
 
@@ -118,11 +114,11 @@ public class SimpleMapCache implements IMapCache {
         ILispDAO xtrIdDao = null;
         if (!shouldOverwrite) {
             xtrIdDao = getOrInstantiateXtrIdTable(eid, table);
-            xtrIdDao.put(deserializeBytes(record.getXtrId()), new MappingEntry<>(SubKeys.RECORD, value));
+            xtrIdDao.put(record.getXtrId(), new MappingEntry<>(SubKeys.RECORD, value));
         }
 
         if (ConfigIni.getInstance().mappingMergeIsSet()) {
-            List<byte[]> expiredMappings = new ArrayList<byte[]>();
+            List<XtrId> expiredMappings = new ArrayList<XtrId>();
             Set<IpAddress> sourceRlocs = new HashSet<IpAddress>();
             MappingRecord mergedEntry = MappingMergeUtil.mergeXtrIdMappings(getXtrIdMappingList(xtrIdDao),
                     expiredMappings, sourceRlocs);
index 38cfdb1245caa0c7f45aa923b81c44ba7cb16bf4..12835d6364bc1579f7bb4e3e3d5ad6ff826a1869 100644 (file)
@@ -12,11 +12,11 @@ import java.util.Arrays;
 import java.util.List;
 
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.EidUri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKeyBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping;
index 82f85a937f3f8b662c3a0de15080dfe5d0dad48b..b090b1262e65d421a944aebc6d197b1a280a8c8f 100644 (file)
@@ -8,14 +8,17 @@
 package org.opendaylight.lispflowmapping.implementation.util;
 
 import com.google.common.base.Splitter;
+
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+
 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegister;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
@@ -23,7 +26,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.tr
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.EidUri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.MappingBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder;
index c815ea87c9b5984ac019c69b86ecc5db40c70727..642d7adfad116779522d08e566228e1a5ce17f64 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.addres
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
 import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
 import org.opendaylight.lispflowmapping.lisp.util.SourceDestKeyHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
@@ -142,7 +143,7 @@ public final class MappingMergeUtil {
     }
 
     public static MappingRecord mergeMappings(MappingRecord currentMergedMapping, MappingRecord newMapping,
-            byte[] xtrId, Date regdate) {
+            XtrId xtrId, Date regdate) {
         if (currentMergedMapping == null) {
             return newMapping;
         }
@@ -159,10 +160,10 @@ public final class MappingMergeUtil {
         return mrb.build();
     }
 
-    public static MappingRecord mergeXtrIdMappings(List<Object> records, List<byte[]> expiredMappings,
+    public static MappingRecord mergeXtrIdMappings(List<Object> records, List<XtrId> expiredMappings,
             Set<IpAddress> sourceRlocs) {
         MappingRecordBuilder mrb = null;
-        byte[] xtrId = {};
+        XtrId xtrId = null;
         Long timestamp = Long.MAX_VALUE;
 
         for (int i = 0; i < records.size(); i++) {
index ef64528a45e5967345a7c56f05bccc2b3e977c14..2d4c2de294d9eaebe5e370fb12b637d827a7f3b8 100644 (file)
@@ -17,6 +17,8 @@ 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.MapNotify;
 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.SiteId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
@@ -75,8 +77,8 @@ public final class MapNotifySerializer {
         }
 
         if (mapNotify.isXtrSiteIdPresent() != null && mapNotify.isXtrSiteIdPresent()) {
-            replyBuffer.put(mapNotify.getXtrId());
-            replyBuffer.put(mapNotify.getSiteId());
+            replyBuffer.put(mapNotify.getXtrId().getValue());
+            replyBuffer.put(mapNotify.getSiteId().getValue());
         }
         replyBuffer.clear();
         return replyBuffer;
@@ -107,10 +109,12 @@ public final class MapNotifySerializer {
                 for (int i = 0; i < recordCount; i++) {
                     mrbs.add(MappingRecordSerializer.getInstance().deserializeToBuilder(notifyBuffer));
                 }
-                byte[] xtrId  = new byte[MapRegisterSerializer.Length.XTRID_SIZE];
-                notifyBuffer.get(xtrId);
-                byte[] siteId = new byte[MapRegisterSerializer.Length.SITEID_SIZE];
-                notifyBuffer.get(siteId);
+                byte[] xtrIdBuf  = new byte[MapRegisterSerializer.Length.XTRID_SIZE];
+                notifyBuffer.get(xtrIdBuf);
+                XtrId xtrId = new XtrId(xtrIdBuf);
+                byte[] siteIdBuf = new byte[MapRegisterSerializer.Length.SITEID_SIZE];
+                notifyBuffer.get(siteIdBuf);
+                SiteId siteId = new SiteId(siteIdBuf);
                 builder.setXtrId(xtrId);
                 builder.setSiteId(siteId);
                 for (MappingRecordBuilder mrb : mrbs) {
index bfe398d75a2ce99119c15a6ee3b27b62360b88ac..a16a501b430b5a55f0972a0d61b57b1002bb19bd 100644 (file)
@@ -22,6 +22,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
 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.SiteId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
@@ -77,8 +79,8 @@ public final class MapRegisterSerializer {
         }
 
         if (mapRegister.isXtrSiteIdPresent() != null && mapRegister.isXtrSiteIdPresent()) {
-            registerBuffer.put(mapRegister.getXtrId());
-            registerBuffer.put(mapRegister.getSiteId());
+            registerBuffer.put(mapRegister.getXtrId().getValue());
+            registerBuffer.put(mapRegister.getSiteId().getValue());
         }
         registerBuffer.clear();
         return registerBuffer;
@@ -111,10 +113,12 @@ public final class MapRegisterSerializer {
                 for (int i = 0; i < recordCount; i++) {
                     mrbs.add(MappingRecordSerializer.getInstance().deserializeToBuilder(registerBuffer));
                 }
-                byte[] xtrId  = new byte[Length.XTRID_SIZE];
-                registerBuffer.get(xtrId);
-                byte[] siteId = new byte[Length.SITEID_SIZE];
-                registerBuffer.get(siteId);
+                byte[] xtrIdBuf  = new byte[Length.XTRID_SIZE];
+                registerBuffer.get(xtrIdBuf);
+                XtrId xtrId = new XtrId(xtrIdBuf);
+                byte[] siteIdBuf = new byte[Length.SITEID_SIZE];
+                registerBuffer.get(siteIdBuf);
+                SiteId siteId = new SiteId(siteIdBuf);
                 builder.setXtrId(xtrId);
                 builder.setSiteId(siteId);
                 for (MappingRecordBuilder mrb : mrbs) {
index 58bf372611c9937ec6c9a373966a3c8275f548a4..4fd885e030766c2da21a5fd0c2192bd42feffead 100644 (file)
@@ -30,6 +30,22 @@ module odl-lisp-proto {
              in network byte order.";
     }
 
+    typedef xtr-id {
+        type binary {
+            length "16";
+        }
+        description
+            "128 bit xTR identifier.";
+    }
+
+    typedef site-id {
+        type binary {
+            length "8";
+        }
+        description
+            "64 bit site identifier.";
+    }
+
     typedef ipv6-address-binary {
         type binary {
             length "16";
@@ -119,16 +135,12 @@ module odl-lisp-proto {
 
     grouping mapping-record-metadata {
         leaf xtr-id {
-            type binary {
-                length "16";
-            }
+            type xtr-id;
             description
                 "128 bit xTR identifier.";
         }
         leaf site-id {
-            type binary {
-                length "8";
-            }
+            type site-id;
             description
                 "64 bit site identifier.";
         }
@@ -194,14 +206,10 @@ module odl-lisp-proto {
 
     grouping xtrSiteId {
         leaf xtrId {
-            type binary {
-                length "16";
-            }
+            type xtr-id;
         }
         leaf siteId {
-            type binary {
-                length "8";
-            }
+            type site-id;
         }
     }
 
index 4bc12eb61736f5485b115f6fd4b695eba92fc46e..dc446a8e732580cba50744c28bc58019ef6e046a 100644 (file)
@@ -24,6 +24,8 @@ import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializat
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
 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.SiteId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
@@ -53,14 +55,16 @@ public class MapRegisterSerializationTest extends BaseTestCase {
         mrBuilder.setWantMapNotify(true);
         mrBuilder.setProxyMapReply(true);
         mrBuilder.setXtrSiteIdPresent(true);
-        byte[] authenticationData = new byte[] { (byte) 0x16, (byte) 0x98, (byte) 0x96, (byte) 0xeb, (byte) 0x88, (byte) 0x2d, (byte) 0x4d,
-                (byte) 0x22, (byte) 0xe5, (byte) 0x8f, (byte) 0xe6, (byte) 0x89, (byte) 0x64, (byte) 0xb9, (byte) 0x17, (byte) 0xa4, (byte) 0xba,
-                (byte) 0x4e, (byte) 0x8c, (byte) 0x41 };
+        byte[] authenticationData = new byte[] { (byte) 0x16, (byte) 0x98, (byte) 0x96, (byte) 0xeb, (byte) 0x88,
+                (byte) 0x2d, (byte) 0x4d, (byte) 0x22, (byte) 0xe5, (byte) 0x8f, (byte) 0xe6, (byte) 0x89, (byte) 0x64,
+                (byte) 0xb9, (byte) 0x17, (byte) 0xa4, (byte) 0xba, (byte) 0x4e, (byte) 0x8c, (byte) 0x41 };
         mrBuilder.setAuthenticationData(authenticationData);
-        byte[] xtrId  = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
-                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 };
+        XtrId xtrId  = new XtrId(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                (byte) 0x00, (byte) 0x00, (byte) 0x01 });
         mrBuilder.setXtrId(xtrId);
-        byte[] siteId = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 };
+        SiteId siteId = new SiteId(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                (byte) 0x00, (byte) 0x00, (byte) 0x01 });
         mrBuilder.setSiteId(siteId);
 
         ByteBuffer bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
@@ -83,11 +87,11 @@ public class MapRegisterSerializationTest extends BaseTestCase {
 
         byte[] actualXtrId  = new byte[Length.XTRID_SIZE];
         bb.get(actualXtrId);
-        ArrayAssert.assertEquals(xtrId, actualXtrId);
+        ArrayAssert.assertEquals(xtrId.getValue(), actualXtrId);
 
         byte[] actualSiteId = new byte[Length.SITEID_SIZE];
         bb.get(actualSiteId);
-        ArrayAssert.assertEquals(siteId, actualSiteId);
+        ArrayAssert.assertEquals(siteId.getValue(), actualSiteId);
 
         assertEquals(bb.position(), bb.capacity());
     }
@@ -114,17 +118,17 @@ public class MapRegisterSerializationTest extends BaseTestCase {
         mrBuilder.setKeyId((short) 0x0001);
         mrBuilder.setWantMapNotify(true);
         mrBuilder.setProxyMapReply(true);
-        byte[] authenticationData = new byte[] { (byte) 0x16, (byte) 0x98, (byte) 0x96, (byte) 0xeb, (byte) 0x88, (byte) 0x2d, (byte) 0x4d,
-                (byte) 0x22, (byte) 0xe5, (byte) 0x8f, (byte) 0xe6, (byte) 0x89, (byte) 0x64, (byte) 0xb9, (byte) 0x17, (byte) 0xa4, (byte) 0xba,
-                (byte) 0x4e, (byte) 0x8c, (byte) 0x41 };
+        byte[] authenticationData = new byte[] { (byte) 0x16, (byte) 0x98, (byte) 0x96, (byte) 0xeb, (byte) 0x88,
+                (byte) 0x2d, (byte) 0x4d, (byte) 0x22, (byte) 0xe5, (byte) 0x8f, (byte) 0xe6, (byte) 0x89, (byte) 0x64,
+                (byte) 0xb9, (byte) 0x17, (byte) 0xa4, (byte) 0xba, (byte) 0x4e, (byte) 0x8c, (byte) 0x41 };
         mrBuilder.setAuthenticationData(authenticationData);
 
         MapRegister mapRegister = mrBuilder.build();
         ArrayAssert.assertEquals(
                 MapRegisterSerializer.getInstance().serialize(mapRegister).array(),
                 MapRegisterSerializer.getInstance()
-                        .serialize(MapRegisterSerializer.getInstance().deserialize(MapRegisterSerializer.getInstance().serialize(mapRegister), null))
-                        .array());
+                        .serialize(MapRegisterSerializer.getInstance().deserialize(MapRegisterSerializer.getInstance()
+                                .serialize(mapRegister), null)).array());
     }
 
     @Test
@@ -440,9 +444,9 @@ public class MapRegisterSerializationTest extends BaseTestCase {
         assertEquals(1, mr.getMappingRecordItem().size());
         assertEquals(0xFFBB000000000000L, mr.getNonce().longValue());
         assertEquals(0x0001, mr.getKeyId().shortValue());
-        byte[] expectedAuthenticationData = { (byte) 0x2c, (byte) 0x61, (byte) 0xb9, (byte) 0xc9, (byte) 0x9a, (byte) 0x20, (byte) 0xba, (byte) 0xd8, //
-                (byte) 0xf5, (byte) 0x40, (byte) 0xd3, (byte) 0x55, (byte) 0x6f, (byte) 0x5f, (byte) 0x6e, (byte) 0x5a, //
-                (byte) 0xb2, (byte) 0x0a, (byte) 0xbf, (byte) 0xb5 };
+        byte[] expectedAuthenticationData = { (byte) 0x2c, (byte) 0x61, (byte) 0xb9, (byte) 0xc9, (byte) 0x9a,
+                (byte) 0x20, (byte) 0xba, (byte) 0xd8, (byte) 0xf5, (byte) 0x40, (byte) 0xd3, (byte) 0x55, (byte) 0x6f,
+                (byte) 0x5f, (byte) 0x6e, (byte) 0x5a, (byte) 0xb2, (byte) 0x0a, (byte) 0xbf, (byte) 0xb5 };
         ArrayAssert.assertEquals(expectedAuthenticationData, mr.getAuthenticationData());
     }
 
@@ -474,10 +478,11 @@ public class MapRegisterSerializationTest extends BaseTestCase {
         assertEquals(1, mr.getMappingRecordItem().size());
         assertEquals(0xFFBB000000000000L, mr.getNonce().longValue());
         assertEquals(0x0002, mr.getKeyId().shortValue());
-        byte[] expectedAuthenticationData = { (byte) 0x70, (byte) 0x30, (byte) 0xd4, (byte) 0xc6, (byte) 0x10, (byte) 0x44, (byte) 0x0d, (byte) 0x83,
-                (byte) 0xbe, (byte) 0x4d, (byte) 0xbf, (byte) 0xfd, (byte) 0xa9, (byte) 0x8c, (byte) 0x57, (byte) 0x6d, (byte) 0x68, (byte) 0xa5,
-                (byte) 0xbf, (byte) 0x32, (byte) 0x11, (byte) 0xc9, (byte) 0x7b, (byte) 0x58, (byte) 0xc4, (byte) 0xb9, (byte) 0x9f, (byte) 0x06,
-                (byte) 0x11, (byte) 0x23, (byte) 0xb9, (byte) 0x38 };
+        byte[] expectedAuthenticationData = { (byte) 0x70, (byte) 0x30, (byte) 0xd4, (byte) 0xc6, (byte) 0x10,
+                (byte) 0x44, (byte) 0x0d, (byte) 0x83, (byte) 0xbe, (byte) 0x4d, (byte) 0xbf, (byte) 0xfd, (byte) 0xa9,
+                (byte) 0x8c, (byte) 0x57, (byte) 0x6d, (byte) 0x68, (byte) 0xa5, (byte) 0xbf, (byte) 0x32, (byte) 0x11,
+                (byte) 0xc9, (byte) 0x7b, (byte) 0x58, (byte) 0xc4, (byte) 0xb9, (byte) 0x9f, (byte) 0x06, (byte) 0x11,
+                (byte) 0x23, (byte) 0xb9, (byte) 0x38 };
         ArrayAssert.assertEquals(expectedAuthenticationData, mr.getAuthenticationData());
     }
 }