support lcaf traffic engineering TELSDN-178: #close 87/1487/5
authorDavid Goldberg <david.goldberg@contextream.com>
Wed, 11 Sep 2013 12:08:47 +0000 (15:08 +0300)
committerDavid Goldberg <david.goldberg@contextream.com>
Sat, 14 Sep 2013 15:06:00 +0000 (18:06 +0300)
Signed-off-by: David Goldberg <david.goldberg@contextream.com>
Change-Id: If4e16f9e19681773431a50e203d215c04766e719
Signed-off-by: David Goldberg <david.goldberg@contextream.com>
25 files changed:
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/type/LispCanonicalAddressFormatEnum.java
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/type/lisp/address/LispTrafficEngineeringLCAFAddress.java [new file with mode: 0644]
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/type/lisp/address/ReencapHop.java [new file with mode: 0644]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/EidToLocatorRecordSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/LocatorRecordSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispAddressSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispApplicationDataLCAFAddressSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispIPAddressSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispIpv4AddressSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispIpv6AddressSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispLCAFAddressSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispListLCAFAddressSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispMACAddressSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispNoAddressSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispSegmentLCAFAddressSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispSourceDestLCAFAddressSerializer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispTrafficEngineeringLCAFAddressSerializer.java [new file with mode: 0644]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/factory/LispAFIAddressSerializerFactory.java [moved from mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispAddressSerializerFactory.java with 53% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/factory/LispLCAFAddressSerializerFactory.java [new file with mode: 0644]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispApplicationDataLCAFAddressTest.java
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispIpv6AddressTest.java
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispListLCAFAddressTest.java
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispSegmentLCAFAddressTest.java
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispSourceDestLCAFAddressTest.java
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispTrafficEngineeringLCAFAddressTest.java [new file with mode: 0644]

index aec35da248ef794c86b347a643e25dd716c96c8a..6bb689d14f2a61c5ba12c22bc45a89059ff4f39f 100644 (file)
@@ -13,12 +13,14 @@ import org.opendaylight.lispflowmapping.type.lisp.address.LispLCAFAddress;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispListLCAFAddress;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispSourceDestLCAFAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispTrafficEngineeringLCAFAddress;
 
 public enum LispCanonicalAddressFormatEnum {
     LIST(1, LispListLCAFAddress.class), //
     SEGMENT(2, LispSegmentLCAFAddress.class), //
     APPLICATION_DATA(4, LispApplicationDataLCAFAddress.class), //
     SOURCE_DEST(12, LispSourceDestLCAFAddress.class), //
+    TRAFFIC_ENGINEERING(10, LispTrafficEngineeringLCAFAddress.class), //
     UNKNOWN(-1, null);
 
     private byte lispCode;
diff --git a/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/type/lisp/address/LispTrafficEngineeringLCAFAddress.java b/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/type/lisp/address/LispTrafficEngineeringLCAFAddress.java
new file mode 100644 (file)
index 0000000..c1c40c7
--- /dev/null
@@ -0,0 +1,29 @@
+package org.opendaylight.lispflowmapping.type.lisp.address;
+
+import java.util.List;
+
+import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
+
+public class LispTrafficEngineeringLCAFAddress extends LispLCAFAddress {
+
+    private List<ReencapHop> hops;
+    
+    public LispTrafficEngineeringLCAFAddress(byte res2, List<ReencapHop> hops) {
+        super(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, res2);
+        this.hops = hops;
+    }
+    
+    @Override
+    public String toString() {
+        return "LispTrafficEngineeringLCAFAddress#[hops=" + hops + "]" + super.toString();
+    }
+
+    public List<ReencapHop> getHops() {
+        return hops;
+    }
+
+    public void setHops(List<ReencapHop> hops) {
+        this.hops = hops;
+    }
+    
+}
diff --git a/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/type/lisp/address/ReencapHop.java b/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/type/lisp/address/ReencapHop.java
new file mode 100644 (file)
index 0000000..a11f34c
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2013 Contextream, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.lispflowmapping.type.lisp.address;
+
+
+
+public class ReencapHop extends LispAddress{
+
+    private LispAddress hop;
+    private short resv3;
+    private boolean lookup;
+    private boolean RLOCProbe;
+    private boolean strict;
+    
+    public ReencapHop(LispAddress hop, short resv3, boolean lookup, boolean RLOCProbe, boolean strict) {
+        super(hop.getAfi());
+        this.hop = hop;
+        this.resv3 = resv3;
+        this.lookup = lookup;
+        this.RLOCProbe = RLOCProbe;
+        this.strict = strict;
+    }
+
+    public LispAddress getHop() {
+        return hop;
+    }
+
+    public void setHop(LispAddress hop) {
+        this.hop = hop;
+    }
+
+    public short getResv3() {
+        return resv3;
+    }
+
+    public void setResv3(short resv3) {
+        this.resv3 = resv3;
+    }
+
+    public boolean isLookup() {
+        return lookup;
+    }
+
+    public void setLookup(boolean lookup) {
+        this.lookup = lookup;
+    }
+
+    public boolean isRLOCProbe() {
+        return RLOCProbe;
+    }
+
+    public void setRLOCProbe(boolean rLOCProbe) {
+        RLOCProbe = rLOCProbe;
+    }
+
+    public boolean isStrict() {
+        return strict;
+    }
+
+    public void setStrict(boolean strict) {
+        this.strict = strict;
+    }
+    
+    @Override
+    public String toString() {
+        return "ReencapHop#[hop=" + hop + "]" + super.toString();
+    }
+
+    
+    
+
+}
index 8034b3cadacf6bde8466b594e4ac650cfb6425ff..9d80e39c9bce485203b2737add0e4bdbdd88ebe5 100644 (file)
@@ -3,7 +3,6 @@ package org.opendaylight.lispflowmapping.implementation.serializer;
 import java.nio.ByteBuffer;
 
 import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializerFactory;
 import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
 import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
 import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
@@ -48,7 +47,7 @@ public class EidToLocatorRecordSerializer {
                 ByteUtil.boolToBit(record.isAuthoritative(), Flags.AUTHORITATIVE)));
         replyBuffer.position(replyBuffer.position() + Length.RESERVED);
         replyBuffer.putShort(record.getMapVersion());
-        LispAddressSerializerFactory.getSerializer(record.getPrefix().getAfi()).serialize(replyBuffer, record.getPrefix());
+        LispAddressSerializer.getInstance().serialize(replyBuffer, record.getPrefix());
 
         for (LocatorRecord locatorRecord : record.getLocators()) {
             LocatorRecordSerializer.getInstance().serialize(replyBuffer, locatorRecord);
@@ -56,7 +55,7 @@ public class EidToLocatorRecordSerializer {
     }
 
     public int getSerializationSize(EidToLocatorRecord record) {
-        int size = Length.HEADER_SIZE + LispAddressSerializerFactory.getSerializer(record.getPrefix().getAfi()).getAddressSize(record.getPrefix());
+        int size = Length.HEADER_SIZE + LispAddressSerializer.getInstance().getAddressSize(record.getPrefix());
         for (LocatorRecord locatorRecord : record.getLocators()) {
             size += LocatorRecordSerializer.getInstance().getSerializationSize(locatorRecord);
         }
index 3d9af8dea454e56abd72069197b985a059e7d56f..90aa1be3c235cbc30be8170dae55b9fcea042069 100644 (file)
@@ -3,7 +3,6 @@ package org.opendaylight.lispflowmapping.implementation.serializer;
 import java.nio.ByteBuffer;
 
 import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializerFactory;
 import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
 import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
 
@@ -42,13 +41,11 @@ public class LocatorRecordSerializer {
         replyBuffer.put((byte) (ByteUtil.boolToBit(record.isLocalLocator(), Flags.LOCAL_LOCATOR) | //
                 ByteUtil.boolToBit(record.isRlocProbed(), Flags.RLOC_PROBED) | //
                 ByteUtil.boolToBit(record.isRouted(), Flags.ROUTED)));
-        LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(record.getLocator().getAfi());
-        serializer.serialize(replyBuffer, record.getLocator());
+        LispAddressSerializer.getInstance().serialize(replyBuffer, record.getLocator());
     }
 
     public int getSerializationSize(LocatorRecord record) {
-       LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(record.getLocator().getAfi());
-        return Length.HEADER_SIZE + serializer.getAddressSize(record.getLocator());
+        return Length.HEADER_SIZE + LispAddressSerializer.getInstance().getAddressSize(record.getLocator());
     }
     
     private interface Flags {
index 0fe9e095c946c77d19546a57f8738fc9a81fc227..dd2d6b0ff01d1a9e8d408e79a6ee7c0be02938b4 100644 (file)
@@ -1,8 +1,16 @@
+/*
+ * Copyright (c) 2013 Contextream, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.lispflowmapping.implementation.serializer.address;
 
 import java.nio.ByteBuffer;
 
 import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.factory.LispAFIAddressSerializerFactory;
 import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
 
@@ -17,34 +25,53 @@ public class LispAddressSerializer {
     public static LispAddressSerializer getInstance() {
         return INSTANCE;
     }
+    
+    protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+        throw new RuntimeException("UnImplemented");
+    }
+    
+    protected LispAddress deserializeData(ByteBuffer buffer) {
+        throw new RuntimeException("UnImplemented");
+    }
 
     public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
-        throw new RuntimeException("Not implemented");
+        LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(lispAddress.getAfi());
+        if (serializer == null) {
+            throw new LispSerializationException("Unknown AFI type=" + lispAddress.getAfi());
+        }
+        serializeAFIAddressHeader(buffer, lispAddress);
+        serializer.serializeData(buffer, lispAddress);
     }
 
-    protected void internalSerialize(ByteBuffer buffer, LispAddress lispAddress) {
+    protected static void serializeAFIAddressHeader(ByteBuffer buffer, LispAddress lispAddress) {
         buffer.putShort(lispAddress.getAfi().getIanaCode());
     }
 
     public int getAddressSize(LispAddress lispAddress) {
-        return Length.AFI;
+        AddressFamilyNumberEnum afiType = lispAddress.getAfi();
+        LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(afiType);
+        if (serializer == null) {
+            throw new LispSerializationException("Unknown AFI type=" + afiType);
+        }
+        return  Length.AFI + serializer.getAddressSize(lispAddress);
     }
 
     public LispAddress deserialize(ByteBuffer buffer) {
         short afi = buffer.getShort();
         AddressFamilyNumberEnum afiType = AddressFamilyNumberEnum.valueOf(afi);
-        LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(afiType);
+        LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(afiType);
         if (serializer == null) {
             throw new LispSerializationException("Unknown AFI type=" + afiType);
         }
         try {
-            return serializer.deserialize(buffer);
+            return serializer.deserializeData(buffer);
         } catch (Exception e) {
             throw new LispSerializationException(e.getMessage());
         }
     }
-
+    
     private interface Length {
         int AFI = 2;
     }
+
 }
index 332b3126e95d3257e9dc0036ac97aa6c1b05d800..f685ef94c4a9ca821b3e98268d01d9f1bc14fd26 100644 (file)
@@ -2,11 +2,9 @@ package org.opendaylight.lispflowmapping.implementation.serializer.address;
 
 import java.nio.ByteBuffer;
 
-import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
 import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispApplicationDataLCAFAddress;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
 
 public class LispApplicationDataLCAFAddressSerializer extends LispLCAFAddressSerializer {
 
@@ -21,29 +19,22 @@ public class LispApplicationDataLCAFAddressSerializer extends LispLCAFAddressSer
     }
 
     @Override
-    public short getLcafLength(LispAddress lispAddress) {
-        LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(((LispApplicationDataLCAFAddress) lispAddress).getAddress()
-                .getAfi());
-        return (short) (Length.ALL_FIELDS + serializer.getAddressSize(lispAddress));
+    protected short getLcafLength(LispAddress lispAddress) {
+        return (short) (Length.ALL_FIELDS + LispAddressSerializer.getInstance().getAddressSize(((LispApplicationDataLCAFAddress)lispAddress).getAddress()));
     }
 
     @Override
-    public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
-        super.internalSerialize(buffer, lispAddress);
+    protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
         LispApplicationDataLCAFAddress applicationDataAddress = ((LispApplicationDataLCAFAddress) lispAddress);
         buffer.put(ByteUtil.partialIntToByteArray(applicationDataAddress.getIPTos(), Length.TOC));
         buffer.put(applicationDataAddress.getProtocol());
         buffer.putShort(applicationDataAddress.getLocalPort());
         buffer.putShort(applicationDataAddress.getRemotePort());
-        LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(applicationDataAddress.getAddress().getAfi());
-        if (serializer == null) {
-            throw new LispSerializationException("Unknown AFI type=" + ((LispSegmentLCAFAddress) lispAddress).getAddress().getAfi());
-        }
-        serializer.serialize(buffer, ((LispApplicationDataLCAFAddress) lispAddress).getAddress());
+        LispAddressSerializer.getInstance().serialize(buffer, ((LispApplicationDataLCAFAddress) lispAddress).getAddress());
     }
 
     @Override
-    public LispApplicationDataLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
+    protected LispApplicationDataLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
 
         LispApplicationDataLCAFAddress applicationDataAddress = new LispApplicationDataLCAFAddress(res2);
         byte[] rawIPTos = new byte[3];
index dbf7f106882e87f7b23822416824446c78b7d642..dc947f9093f20a29281fbac6ad8cacf2d0521ac4 100644 (file)
@@ -9,9 +9,8 @@ public abstract class LispIPAddressSerializer extends LispAddressSerializer{
 
 
     @Override
-    public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+    protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
        LispIPAddress lispIpvAddress = (LispIPAddress)lispAddress;
-        super.internalSerialize(buffer, lispAddress);
         buffer.put(lispIpvAddress.getAddress().getAddress());
     }
 }
index 4e6723fec158c95db5adc1f16ed3de7085859030..2727d46e1b92692293659902e13941cab93bd2d5 100644 (file)
@@ -23,11 +23,11 @@ public class LispIpv4AddressSerializer extends LispIPAddressSerializer{
        
        @Override
     public int getAddressSize(LispAddress lispAddress) {
-        return super.getAddressSize(lispAddress) + 4;
+        return Length.IPV4;
     }
        
        @Override
-       public LispIpv4Address deserialize(ByteBuffer buffer) {
+       protected LispIpv4Address deserializeData(ByteBuffer buffer) {
         byte[] ipBuffer = new byte[4];
         InetAddress address = null;
         buffer.get(ipBuffer);
@@ -39,6 +39,10 @@ public class LispIpv4AddressSerializer extends LispIPAddressSerializer{
         }
         return new LispIpv4Address(address);
     }
+       
+       private interface Length {
+               int IPV4 = 4;
+           }
 
 
 
index af08355569e151733d9c47f4190270b3d36a8ea5..d3b377670054775a6cd56e0c4bca2f0f53670d73 100644 (file)
@@ -23,11 +23,11 @@ public class LispIpv6AddressSerializer extends LispIPAddressSerializer{
        
        @Override
     public int getAddressSize(LispAddress lispAddress) {
-        return super.getAddressSize(lispAddress) + 16;
+        return Length.IPV6;
     }
        
        @Override
-       public LispIpv6Address deserialize(ByteBuffer buffer) {
+       protected LispIpv6Address deserializeData(ByteBuffer buffer) {
         byte[] ipBuffer = new byte[16];
         InetAddress address = null;
         buffer.get(ipBuffer);
@@ -39,5 +39,9 @@ public class LispIpv6AddressSerializer extends LispIPAddressSerializer{
         }
         return new LispIpv6Address(address);
     }
+       
+       private interface Length {
+            int IPV6 = 16;
+        }
 
 }
index 46cc6160becf7ea305764abeb92878c0943c3e23..bd90d4c31a5a4d4a05aa8b31e942e06eb7646c82 100644 (file)
@@ -1,67 +1,78 @@
+/*
+ * Copyright (c) 2013 Contextream, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.lispflowmapping.implementation.serializer.address;
 
 import java.nio.ByteBuffer;
 
 import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.factory.LispLCAFAddressSerializerFactory;
 import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispLCAFAddress;
 
-public class LispLCAFAddressSerializer extends LispAddressSerializer{
-       
-       private static final LispLCAFAddressSerializer INSTANCE = new LispLCAFAddressSerializer();
+public class LispLCAFAddressSerializer extends LispAddressSerializer {
 
-       // Private constructor prevents instantiation from other classes
-       protected LispLCAFAddressSerializer() {
-       }
+    private static final LispLCAFAddressSerializer INSTANCE = new LispLCAFAddressSerializer();
 
-       public static LispLCAFAddressSerializer getInstance() {
-               return INSTANCE;
-       }
+    // Private constructor prevents instantiation from other classes
+    protected LispLCAFAddressSerializer() {
+    }
+
+    public static LispLCAFAddressSerializer getInstance() {
+        return INSTANCE;
+    }
 
-       @Override
-       public LispLCAFAddress deserialize(ByteBuffer buffer) {
+    @Override
+    protected LispLCAFAddress deserializeData(ByteBuffer buffer) {
         buffer.position(buffer.position() + Length.RES + Length.FLAGS);
         byte lispCode = buffer.get();
         LispCanonicalAddressFormatEnum lcafType = LispCanonicalAddressFormatEnum.valueOf(lispCode);
         byte res2 = buffer.get();
         short length = buffer.getShort();
 
-        LispLCAFAddressSerializer serializer = LispAddressSerializerFactory.getLCAFSerializer(lcafType);
+        LispLCAFAddressSerializer serializer = LispLCAFAddressSerializerFactory.getLCAFSerializer(lcafType);
         if (serializer == null) {
             throw new LispSerializationException("Unknown LispLCAFAddress type=" + lispCode);
         }
-        return serializer.innerDeserialize(buffer, res2, length);
+        return serializer.deserializeData(buffer, res2, length);
+    }
+
+    protected LispLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
+        throw new RuntimeException("Not implemented");
     }
-       
-       public LispLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
-               throw new RuntimeException("Not implemented");
-       }
 
     @Override
     public int getAddressSize(LispAddress lispAddress) {
-        return super.getAddressSize(lispAddress) + Length.LCAF_HEADER + LispAddressSerializerFactory.getLCAFSerializer(((LispLCAFAddress)lispAddress).getType()).getLcafLength(lispAddress);
+        return Length.LCAF_HEADER
+                + LispLCAFAddressSerializerFactory.getLCAFSerializer(((LispLCAFAddress) lispAddress).getType()).getLcafLength(lispAddress);
     }
-    
-    public short getLcafLength(LispAddress lispAddress) {
-       throw new RuntimeException("Not implemented");
+
+    protected short getLcafLength(LispAddress lispAddress) {
+        throw new RuntimeException("Not implemented");
     }
-    
+
     @Override
-    public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
-       LispLCAFAddressSerializer lcafSerializer = LispAddressSerializerFactory.getLCAFSerializer(((LispLCAFAddress)lispAddress).getType());
-        lcafSerializer.serialize(buffer, lispAddress);
+    protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+        serializeLCAFAddressHeader(buffer, lispAddress);
+        
+        LispLCAFAddressSerializer lcafSerializer = LispLCAFAddressSerializerFactory.getLCAFSerializer(((LispLCAFAddress) lispAddress).getType());
+        lcafSerializer.serializeData(buffer, lispAddress);
     }
 
-    @Override
-    protected void internalSerialize(ByteBuffer buffer, LispAddress lispAddress) {
-        super.internalSerialize(buffer, lispAddress);
-        LispLCAFAddress lispLCAFAddress = (LispLCAFAddress)lispAddress;
+    private void serializeLCAFAddressHeader(ByteBuffer buffer, LispAddress lispAddress) {
+        LispLCAFAddress lispLCAFAddress = (LispLCAFAddress) lispAddress;
         buffer.putShort((short) 0); // RES + Flags.
         buffer.put(lispLCAFAddress.getType().getLispCode());
         buffer.put(lispLCAFAddress.getRes2());
-        buffer.putShort(getLcafLength(lispAddress));
+        LispLCAFAddressSerializer lcafSerializer = LispLCAFAddressSerializerFactory.getLCAFSerializer(lispLCAFAddress.getType());
+        buffer.putShort(lcafSerializer.getLcafLength(lispAddress));
     }
+
     private interface Length {
         int RES = 1;
         int FLAGS = 1;
index ad5bfb33091797c0dbed94d67cd7a28232f9727f..df917ca6a3d4974e98f9633a2f8bd775580be555 100644 (file)
@@ -21,28 +21,27 @@ public class LispListLCAFAddressSerializer extends LispLCAFAddressSerializer{
 
 
        @Override
-    public short getLcafLength(LispAddress lispAddress) {
+       protected short getLcafLength(LispAddress lispAddress) {
         short totalSize = 0;
         for (LispAddress address : ((LispListLCAFAddress)lispAddress).getAddresses()) {
-            totalSize += LispAddressSerializerFactory.getSerializer(address.getAfi()).getAddressSize(lispAddress);
+            totalSize += LispAddressSerializer.getInstance().getAddressSize(address);
         }
         return totalSize;
     }
 
        @Override
-    public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
-        super.internalSerialize(buffer, lispAddress);
+       protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
         for (LispAddress address : ((LispListLCAFAddress)lispAddress).getAddresses()) {
-               LispAddressSerializerFactory.getSerializer(address.getAfi()).serialize(buffer, address);
+            LispAddressSerializer.getInstance().serialize(buffer, address);
         }
     }
        
        @Override
-       public LispListLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
+       public LispListLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
         List<LispAddress> addresses = new ArrayList<LispAddress>();
         while (length > 0) {
             LispAddress address = LispAddressSerializer.getInstance().deserialize(buffer);
-            length -= LispAddressSerializerFactory.getSerializer(address.getAfi()).getAddressSize(address);
+            length -= LispAddressSerializer.getInstance().getAddressSize(address);
             addresses.add(address);
         }
         return new LispListLCAFAddress(res2, addresses);
index 05992ddf4eb12697a391783d1e0747e28009deb1..9e86398a5a6533f6e27a306d63abb0ed9a90fe92 100644 (file)
@@ -20,22 +20,25 @@ public class LispMACAddressSerializer extends LispAddressSerializer{
 
        @Override
     public int getAddressSize(LispAddress lispAddress) {
-               return super.getAddressSize(lispAddress) + 6;
+               return super.getAddressSize(lispAddress) + Length.MAC;
 
     }
        
        @Override
-       public LispMACAddress deserialize(ByteBuffer buffer) {
+       protected LispMACAddress deserializeData(ByteBuffer buffer) {
                byte[] macBuffer = new byte[6];
                buffer.get(macBuffer);
         return new LispMACAddress(macBuffer);
     }
 
     @Override
-    public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+    protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
        LispMACAddress lispMACAddress = (LispMACAddress)lispAddress;
-        super.internalSerialize(buffer, lispMACAddress);
         buffer.put(lispMACAddress.getMAC());
     }
+    
+    private interface Length {
+        int MAC = 6;
+    }
 
 }
index d30439eb71a2d2b66b0949c0c2505fb3ac1a9ca2..6642158e744d7c86b2d1fdc26dd75725877c594d 100644 (file)
@@ -18,17 +18,17 @@ public class LispNoAddressSerializer extends LispAddressSerializer{
        }
        
        @Override
-       public LispNoAddress deserialize(ByteBuffer buffer) {
+       protected LispNoAddress deserializeData(ByteBuffer buffer) {
         return new LispNoAddress();
     }
 
     @Override
     public int getAddressSize(LispAddress lispAddress) {
-        return super.getAddressSize(lispAddress);
+        return 0;
     }
 
     @Override
-    public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+    protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
     }
 
 }
index 579f5d6131e9809d4bff81d40bcbe519b3447a16..1349435c606b5cb9ac1d2397d07574b367c21833 100644 (file)
@@ -2,7 +2,6 @@ package org.opendaylight.lispflowmapping.implementation.serializer.address;
 
 import java.nio.ByteBuffer;
 
-import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
 
@@ -20,24 +19,18 @@ public class LispSegmentLCAFAddressSerializer extends LispLCAFAddressSerializer{
 
 
        @Override
-    public short getLcafLength(LispAddress lispAddress) {
-               LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
-        return (short) (Length.INSTANCE + serializer.getAddressSize(((LispSegmentLCAFAddress)lispAddress).getAddress()));
+       protected short getLcafLength(LispAddress lispAddress) {
+        return (short) (Length.INSTANCE + LispAddressSerializer.getInstance().getAddressSize(((LispSegmentLCAFAddress)lispAddress).getAddress()));
     }
 
        @Override
-    public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
-        super.internalSerialize(buffer, lispAddress);
+       protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
         buffer.putInt(((LispSegmentLCAFAddress)lispAddress).getInstanceId());
-        LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
-        if (serializer == null) {
-            throw new LispSerializationException("Unknown AFI type=" + ((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
-        }
-        serializer.serialize(buffer, ((LispSegmentLCAFAddress)lispAddress).getAddress());
+        LispAddressSerializer.getInstance().serialize(buffer, ((LispSegmentLCAFAddress)lispAddress).getAddress());
     }
        
        @Override
-       public LispSegmentLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
+       protected LispSegmentLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
         int instanceId = buffer.getInt();
         LispAddress address = LispAddressSerializer.getInstance().deserialize(buffer);
 
index 439d0c9744a3836321b411269783d074ca5c1d50..2fed0fdd2991962b86d4d5cb3eb0ab5f410e0609 100644 (file)
@@ -2,7 +2,6 @@ package org.opendaylight.lispflowmapping.implementation.serializer.address;
 
 import java.nio.ByteBuffer;
 
-import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispSourceDestLCAFAddress;
 
@@ -19,36 +18,23 @@ public class LispSourceDestLCAFAddressSerializer extends LispLCAFAddressSerializ
     }
 
     @Override
-    public short getLcafLength(LispAddress lispAddress) {
-        LispAddressSerializer srcSerializer = LispAddressSerializerFactory.getSerializer(((LispSourceDestLCAFAddress) lispAddress).getSrcAddress()
-                .getAfi());
-        LispAddressSerializer dstSerializer = LispAddressSerializerFactory.getSerializer(((LispSourceDestLCAFAddress) lispAddress).getDstAddress()
-                .getAfi());
-        return (short) (Length.ALL_FIELDS + srcSerializer.getAddressSize(((LispSourceDestLCAFAddress) lispAddress).getSrcAddress()) + dstSerializer
+    protected short getLcafLength(LispAddress lispAddress) {
+        return (short) (Length.ALL_FIELDS + LispAddressSerializer.getInstance().getAddressSize(((LispSourceDestLCAFAddress) lispAddress).getSrcAddress()) + LispAddressSerializer.getInstance()
                 .getAddressSize(((LispSourceDestLCAFAddress) lispAddress).getDstAddress()));
     }
 
     @Override
-    public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
-        super.internalSerialize(buffer, lispAddress);
+    protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
         LispSourceDestLCAFAddress lispSourceDestLCAFAddress = ((LispSourceDestLCAFAddress) lispAddress);
         buffer.putShort(lispSourceDestLCAFAddress.getReserved());
         buffer.put(lispSourceDestLCAFAddress.getSrcMaskLength());
         buffer.put(lispSourceDestLCAFAddress.getDstMaskLength());
-        LispAddressSerializer srcSerializer = LispAddressSerializerFactory.getSerializer(lispSourceDestLCAFAddress.getSrcAddress().getAfi());
-        if (srcSerializer == null) {
-            throw new LispSerializationException("Unknown AFI type=" + lispSourceDestLCAFAddress.getSrcAddress().getAfi());
-        }
-        srcSerializer.serialize(buffer, lispSourceDestLCAFAddress.getSrcAddress());
-        LispAddressSerializer dstSerializer = LispAddressSerializerFactory.getSerializer(lispSourceDestLCAFAddress.getDstAddress().getAfi());
-        if (dstSerializer == null) {
-            throw new LispSerializationException("Unknown AFI type=" + lispSourceDestLCAFAddress.getDstAddress().getAfi());
-        }
-        dstSerializer.serialize(buffer, lispSourceDestLCAFAddress.getDstAddress());
+        LispAddressSerializer.getInstance().serialize(buffer, lispSourceDestLCAFAddress.getSrcAddress());
+        LispAddressSerializer.getInstance().serialize(buffer, lispSourceDestLCAFAddress.getDstAddress());
     }
 
     @Override
-    public LispSourceDestLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
+    protected LispSourceDestLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
         short res = buffer.getShort();
         byte srcMaskLength = buffer.get();
         byte dstMaskLength = buffer.get();
diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispTrafficEngineeringLCAFAddressSerializer.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispTrafficEngineeringLCAFAddressSerializer.java
new file mode 100644 (file)
index 0000000..9132591
--- /dev/null
@@ -0,0 +1,72 @@
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.lispflowmapping.implementation.serializer.address.factory.LispAFIAddressSerializerFactory;
+import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
+import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispTrafficEngineeringLCAFAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.ReencapHop;
+
+public class LispTrafficEngineeringLCAFAddressSerializer extends LispLCAFAddressSerializer {
+
+    private static final LispTrafficEngineeringLCAFAddressSerializer INSTANCE = new LispTrafficEngineeringLCAFAddressSerializer();
+
+    // Private constructor prevents instantiation from other classes
+    private LispTrafficEngineeringLCAFAddressSerializer() {
+    }
+
+    public static LispTrafficEngineeringLCAFAddressSerializer getInstance() {
+        return INSTANCE;
+    }
+
+    @Override
+    protected short getLcafLength(LispAddress lispAddress) {
+        short totalSize = 0;
+        for (ReencapHop hop : ((LispTrafficEngineeringLCAFAddress) lispAddress).getHops()) {
+            totalSize += LispAddressSerializer.getInstance().getAddressSize(hop) + 2;
+        }
+        return totalSize;
+    }
+
+    @Override
+    protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+        for (ReencapHop hop : ((LispTrafficEngineeringLCAFAddress) lispAddress).getHops()) {
+            serializeAFIAddressHeader(buffer, hop);
+            buffer.put((byte) 0);
+            buffer.put((byte) (ByteUtil.boolToBit(hop.isLookup(), Flags.LOOKUP) | //
+                    ByteUtil.boolToBit(hop.isRLOCProbe(), Flags.RLOC_PROBE) | //
+            ByteUtil.boolToBit(hop.isStrict(), Flags.STRICT)));
+            LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(hop.getAfi());
+            serializer.serializeData(buffer, hop.getHop());
+        }
+    }
+
+    @Override
+    protected LispTrafficEngineeringLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
+        List<ReencapHop> hops = new ArrayList<ReencapHop>();
+        while (length > 0) {
+            short afi = buffer.getShort();
+            LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(AddressFamilyNumberEnum.valueOf(afi));
+            byte flags = (byte) buffer.getShort();
+            boolean lookup = ByteUtil.extractBit(flags, Flags.LOOKUP);
+            boolean RLOCProbe = ByteUtil.extractBit(flags, Flags.RLOC_PROBE);
+            boolean strict = ByteUtil.extractBit(flags, Flags.STRICT);
+            LispAddress address = serializer.deserializeData(buffer);
+            ReencapHop hop = new ReencapHop(address, (short) 0, lookup, RLOCProbe, strict);
+            length -= LispAddressSerializer.getInstance().getAddressSize(hop) + 2;
+            hops.add(hop);
+        }
+        return new LispTrafficEngineeringLCAFAddress(res2, hops);
+    }
+
+    private interface Flags {
+        int LOOKUP = 0x04;
+        int RLOC_PROBE = 0x02;
+        int STRICT = 0x01;
+    }
+
+}
@@ -1,15 +1,20 @@
-package org.opendaylight.lispflowmapping.implementation.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address.factory;
 
 import java.util.HashMap;
 import java.util.Map;
 
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispASAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispIpv4AddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispIpv6AddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispMACAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispNoAddressSerializer;
 import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
 
-public class LispAddressSerializerFactory {
+public class LispAFIAddressSerializerFactory {
        
        private static Map<AddressFamilyNumberEnum, LispAddressSerializer> afiToSearializerMap;
-       private static Map<LispCanonicalAddressFormatEnum, LispLCAFAddressSerializer> lcafToSearializerMap;
        
        private static void initializeMap() {
                afiToSearializerMap = new HashMap<AddressFamilyNumberEnum, LispAddressSerializer>();
@@ -20,11 +25,6 @@ public class LispAddressSerializerFactory {
                afiToSearializerMap.put(AddressFamilyNumberEnum.MAC, LispMACAddressSerializer.getInstance());
                afiToSearializerMap.put(AddressFamilyNumberEnum.RESERVED, LispNoAddressSerializer.getInstance());
                
-               lcafToSearializerMap = new HashMap<LispCanonicalAddressFormatEnum, LispLCAFAddressSerializer>();
-               lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.LIST, LispListLCAFAddressSerializer.getInstance());
-               lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.SEGMENT, LispSegmentLCAFAddressSerializer.getInstance());
-               lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.APPLICATION_DATA, LispApplicationDataLCAFAddressSerializer.getInstance());
-               lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.SOURCE_DEST, LispSourceDestLCAFAddressSerializer.getInstance());
        }
        
        public static LispAddressSerializer getSerializer(AddressFamilyNumberEnum afi) {
@@ -34,12 +34,5 @@ public class LispAddressSerializerFactory {
                return afiToSearializerMap.get(afi);
        }
        
-       public static LispLCAFAddressSerializer getLCAFSerializer(LispCanonicalAddressFormatEnum lcaf) {
-               if (lcafToSearializerMap == null) {
-                       initializeMap();
-               }
-               return lcafToSearializerMap.get(lcaf);
-       }
-       
 
 }
diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/factory/LispLCAFAddressSerializerFactory.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/factory/LispLCAFAddressSerializerFactory.java
new file mode 100644 (file)
index 0000000..b7fba7e
--- /dev/null
@@ -0,0 +1,36 @@
+package org.opendaylight.lispflowmapping.implementation.serializer.address.factory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispApplicationDataLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispListLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispSegmentLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispSourceDestLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispTrafficEngineeringLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
+
+public class LispLCAFAddressSerializerFactory {
+       
+       private static Map<LispCanonicalAddressFormatEnum, LispLCAFAddressSerializer> lcafToSearializerMap;
+       
+       private static void initializeMap() {
+               
+               lcafToSearializerMap = new HashMap<LispCanonicalAddressFormatEnum, LispLCAFAddressSerializer>();
+               lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.LIST, LispListLCAFAddressSerializer.getInstance());
+               lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.SEGMENT, LispSegmentLCAFAddressSerializer.getInstance());
+               lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.APPLICATION_DATA, LispApplicationDataLCAFAddressSerializer.getInstance());
+               lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, LispTrafficEngineeringLCAFAddressSerializer.getInstance());
+               lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.SOURCE_DEST, LispSourceDestLCAFAddressSerializer.getInstance());
+       }
+       
+       public static LispLCAFAddressSerializer getLCAFSerializer(LispCanonicalAddressFormatEnum lcaf) {
+               if (lcafToSearializerMap == null) {
+                       initializeMap();
+               }
+               return lcafToSearializerMap.get(lcaf);
+       }
+       
+
+}
index 0354a293d7384577e4a95f6d107514d2ebad4bf2..c2465c9e08706c0394839d47df12646da4bf3aa6 100644 (file)
@@ -86,8 +86,8 @@ public class LispApplicationDataLCAFAddressTest extends BaseTestCase {
         address.setLocalPort((short) 0xA6A1);
         address.setRemotePort((short) 0xFFDD);
         address.setAddress(new LispIpv4Address(0x11223344));
-        ByteBuffer buf = ByteBuffer.allocate(LispApplicationDataLCAFAddressSerializer.getInstance().getAddressSize(address));
-        LispApplicationDataLCAFAddressSerializer.getInstance().serialize(buf, address);
+        ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+        LispAddressSerializer.getInstance().serialize(buf, address);
         ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
                 "04 20 00 0E " + //
                 "AA BB CC DD " + // IPTOS & protocol
index c5868db04827f94c2ee29d2aff628b8a17436d32..c663b4938761892b792626c4260342ad0587ceae 100644 (file)
@@ -22,7 +22,7 @@ public class LispIpv6AddressTest extends BaseTestCase {
         LispIpv6Address lispIpv6Address = new LispIpv6Address("::0");
 
         assertEquals(AddressFamilyNumberEnum.IP6, lispIpv6Address.getAfi());
-        assertEquals(18, LispIpv6AddressSerializer.getInstance().getAddressSize(lispIpv6Address));
+        assertEquals(18, LispAddressSerializer.getInstance().getAddressSize(lispIpv6Address));
         assertEquals("0:0:0:0:0:0:0:0", lispIpv6Address.toString());
     }
 
@@ -31,7 +31,7 @@ public class LispIpv6AddressTest extends BaseTestCase {
         LispIpv6Address lispIpv6Address = new LispIpv6Address(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 });
 
         assertEquals(AddressFamilyNumberEnum.IP6, lispIpv6Address.getAfi());
-        assertEquals(18, LispIpv6AddressSerializer.getInstance().getAddressSize(lispIpv6Address));
+        assertEquals(18, LispAddressSerializer.getInstance().getAddressSize(lispIpv6Address));
         assertEquals("0:0:0:0:0:0:0:1", lispIpv6Address.toString());
     }
 }
index 07d3ced1c6cf13b2c77b93bcc23ac549cf9a22f9..34b889702eb6cf7774faa2fe3dc6c4bffec9d5ca 100644 (file)
@@ -83,8 +83,8 @@ public class LispListLCAFAddressTest extends BaseTestCase {
         addressList.add(new LispIpv6Address("1222:3344:1122:3344:1122:3344:1122:3344"));
         LispListLCAFAddress address = new LispListLCAFAddress((byte) 0, addressList);
 
-        ByteBuffer buf = ByteBuffer.allocate(LispListLCAFAddressSerializer.getInstance().getAddressSize(address));
-        LispListLCAFAddressSerializer.getInstance().serialize(buf,address);
+        ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+        LispAddressSerializer.getInstance().serialize(buf,address);
         ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
                 "01 00 00 18 " + //
                 "00 01 AA BB CC DD " + // IPv4
@@ -96,8 +96,8 @@ public class LispListLCAFAddressTest extends BaseTestCase {
     public void serialize__NoAddresses() throws Exception {
         LispListLCAFAddress address = new LispListLCAFAddress((byte) 0, new ArrayList<LispAddress>());
 
-        ByteBuffer buf = ByteBuffer.allocate(LispListLCAFAddressSerializer.getInstance().getAddressSize(address));
-        LispListLCAFAddressSerializer.getInstance().serialize(buf,address);
+        ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+        LispAddressSerializer.getInstance().serialize(buf,address);
         ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
                 "01 00 00 00");
         ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
index d47009e06b331c9ed9adb34d3b2e3868f4022b5d..70864442d207409a963d53cfc5ccbcfa68eb17c9 100644 (file)
@@ -74,8 +74,8 @@ public class LispSegmentLCAFAddressTest extends BaseTestCase {
     @Test
     public void serialize__Simple() throws Exception {
         LispSegmentLCAFAddress address = new LispSegmentLCAFAddress((byte) 0x06, 0x01020304, new LispIpv4Address(0x11223344));
-        ByteBuffer buf = ByteBuffer.allocate(LispSegmentLCAFAddressSerializer.getInstance().getAddressSize(address));
-        LispSegmentLCAFAddressSerializer.getInstance().serialize(buf,address);
+        ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+        LispAddressSerializer.getInstance().serialize(buf,address);
         ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
                 "02 06 00 0A " + //
                 "01 02 03 04 " + // instance ID
@@ -86,8 +86,8 @@ public class LispSegmentLCAFAddressTest extends BaseTestCase {
     @Test
     public void serialize__Recursive_Segment() throws Exception {
         LispSegmentLCAFAddress address = new LispSegmentLCAFAddress((byte) 0x06, 0x01020304, new LispSegmentLCAFAddress((byte) 0x06, 0x01020305, new LispIpv4Address(0x11223344)));
-        ByteBuffer buf = ByteBuffer.allocate(LispSegmentLCAFAddressSerializer.getInstance().getAddressSize(address));
-        LispSegmentLCAFAddressSerializer.getInstance().serialize(buf,address);
+        ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+        LispAddressSerializer.getInstance().serialize(buf,address);
         ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
                 "02 06 00 16 " + //
                 "01 02 03 04 " + // instance ID
index baf282caa99a2bd18454e070bd4141ccdac7f459..d5c9d758bf95db63c8727adda4bbb4972ee47245 100644 (file)
@@ -84,8 +84,8 @@ public class LispSourceDestLCAFAddressTest extends BaseTestCase {
     @Test
     public void serialize__Simple() throws Exception {
        LispSourceDestLCAFAddress address = new LispSourceDestLCAFAddress((byte) 0x20, (short)0x0000, (byte) 0xCC, (byte) 0xDD, new LispIpv4Address(0x11223344), new LispIpv4Address(0x22334455));
-        ByteBuffer buf = ByteBuffer.allocate(LispSourceDestLCAFAddressSerializer.getInstance().getAddressSize(address));
-        LispSourceDestLCAFAddressSerializer.getInstance().serialize(buf,address);
+        ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+        LispAddressSerializer.getInstance().serialize(buf,address);
         ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
                         "0C 20 00 10 " + //
                  "00 00 CC DD " + // reserved + masks
diff --git a/mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispTrafficEngineeringLCAFAddressTest.java b/mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispTrafficEngineeringLCAFAddressTest.java
new file mode 100644 (file)
index 0000000..cc0590c
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2013 Contextream, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import junitx.framework.ArrayAssert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
+import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispTrafficEngineeringLCAFAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.ReencapHop;
+
+public class LispTrafficEngineeringLCAFAddressTest extends BaseTestCase {
+
+    @Test
+    public void deserialize__Simple() throws Exception {
+        LispAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+                "0A 00 00 10 " + //
+                "00 01 00 00 AA BB CC DD " + // IPv4
+                "00 01 00 00 11 22 33 44")); // IPv4
+
+        assertEquals(AddressFamilyNumberEnum.LCAF, address.getAfi());
+        LispTrafficEngineeringLCAFAddress trafficEngineering = (LispTrafficEngineeringLCAFAddress) address;
+
+        assertEquals(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, trafficEngineering.getType());
+
+        List<ReencapHop> hops = trafficEngineering.getHops();
+        assertEquals(2, hops.size());
+
+        assertEquals(new LispIpv4Address(0xAABBCCDD), hops.get(0).getHop());
+        assertEquals(new LispIpv4Address(0x11223344), hops.get(1).getHop());
+    }
+    
+    @Test
+    public void deserialize__Bits() throws Exception {
+        LispAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+                "0A 00 00 10 " + //
+                "00 01 00 05 AA BB CC DD " + // IPv4
+                "00 01 00 02 11 22 33 44")); // IPv4
+
+        assertEquals(AddressFamilyNumberEnum.LCAF, address.getAfi());
+        LispTrafficEngineeringLCAFAddress trafficEngineering = (LispTrafficEngineeringLCAFAddress) address;
+
+        assertEquals(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, trafficEngineering.getType());
+
+        List<ReencapHop> hops = trafficEngineering.getHops();
+        assertEquals(2, hops.size());
+
+        assertEquals(new LispIpv4Address(0xAABBCCDD), hops.get(0).getHop());
+        assertEquals(true, hops.get(0).isLookup());
+        assertEquals(false, hops.get(0).isRLOCProbe());
+        assertEquals(true, hops.get(0).isStrict());
+        assertEquals(new LispIpv4Address(0x11223344), hops.get(1).getHop());
+        assertEquals(false, hops.get(1).isLookup());
+        assertEquals(true, hops.get(1).isRLOCProbe());
+        assertEquals(false, hops.get(1).isStrict());
+    }
+
+    @Test
+    public void deserialize__NoAddresses() throws Exception {
+        LispAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+                "0A 00 00 00 "));
+
+        assertEquals(AddressFamilyNumberEnum.LCAF, address.getAfi());
+        LispTrafficEngineeringLCAFAddress trafficEngineering = (LispTrafficEngineeringLCAFAddress) address;
+
+        assertEquals(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, trafficEngineering.getType());
+
+        List<ReencapHop> hops = trafficEngineering.getHops();
+        assertEquals(0, hops.size());
+    }
+
+    @Test(expected = LispSerializationException.class)
+    public void deserialize__ShorterBuffer() throws Exception {
+        LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+                "0A 00 00 18 " + //
+                "00 01 AA BB CC DD " + // IPv4
+                "00 02 11 22 33 44 11 22 33 44 11 22 33 44"));
+    }
+
+    @Test(expected = LispSerializationException.class)
+    public void deserialize__ShorterBuffer2() throws Exception {
+        LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+                "0A 00 00 18 "));
+    }
+
+    @Test
+    public void serialize__Simple() throws Exception {
+        List<ReencapHop> hops = new ArrayList<ReencapHop>();
+        hops.add(new ReencapHop(new LispIpv4Address(0xAABBCCDD), (short)0, false, false, false));
+        hops.add(new ReencapHop(new LispIpv4Address(0x11223344), (short)0, false, false, false));
+        LispTrafficEngineeringLCAFAddress address = new LispTrafficEngineeringLCAFAddress((byte) 0, hops);
+
+        ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+        LispAddressSerializer.getInstance().serialize(buf,address);
+        ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+                "0A 00 00 10 " + //
+                "00 01 00 00 AA BB CC DD " + // IPv4
+                "00 01 00 00 11 22 33 44"); // IPv4
+        ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+    }
+
+    @Test
+    public void serialize__NoAddresses() throws Exception {
+        LispTrafficEngineeringLCAFAddress address = new LispTrafficEngineeringLCAFAddress((byte) 0, new ArrayList<ReencapHop>());
+
+        ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+        LispAddressSerializer.getInstance().serialize(buf,address);
+        ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+                "0A 00 00 00");
+        ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+    }
+}