Use YANG java files instead of the old model TELSDN-474 #close
[lispflowmapping.git] / mappingservice / implementation / src / test / java / org / opendaylight / lispflowmapping / implementation / serializer / address / LispSegmentLCAFAddressTest.java
index 70864442d207409a963d53cfc5ccbcfa68eb17c9..340b7e6e633b806ed95d803a22a2b3a8526bf5e1 100644 (file)
@@ -15,30 +15,30 @@ import junitx.framework.ArrayAssert;
 
 import org.junit.Test;
 import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.implementation.serializer.LispAFIConvertor;
 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.LispIpv6Address;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LcafSegmentAddress;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LispAFIAddress;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lcafsegmentaddress.AddressBuilder;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.LcafSegmentBuilder;
 
 public class LispSegmentLCAFAddressTest extends BaseTestCase {
 
     @Test
     public void deserialize__Simple() throws Exception {
-        LispAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+        LispAFIAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
                 "02 20 00 0A " + //
                 "AA BB CC DD " + // instance ID
                 "00 01 11 22 33 44")); // AFI=1, IP=0x11223344
 
-        assertEquals(AddressFamilyNumberEnum.LCAF, address.getAfi());
-        LispSegmentLCAFAddress segAddress = (LispSegmentLCAFAddress) address;
+        assertEquals(AddressFamilyNumberEnum.LCAF.getIanaCode(), address.getAfi().shortValue());
+        LcafSegmentAddress segAddress = (LcafSegmentAddress) address;
 
-        assertEquals(new LispIpv4Address(0x11223344), segAddress.getAddress());
-        assertEquals(0xAABBCCDD, segAddress.getInstanceId());
-        assertEquals(0x20, segAddress.getIdMaskLen());
-        assertEquals(LispCanonicalAddressFormatEnum.SEGMENT, segAddress.getType());
+        assertEquals(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68"), segAddress.getAddress().getPrimitiveAddress());
+        assertEquals(0xAABBCCDD, segAddress.getInstanceId().intValue());
+        assertEquals(LispCanonicalAddressFormatEnum.SEGMENT.getLispCode(), segAddress.getLcafType().byteValue());
     }
 
     @Test(expected = LispSerializationException.class)
@@ -58,43 +58,30 @@ public class LispSegmentLCAFAddressTest extends BaseTestCase {
 
     @Test
     public void deserialize__Ipv6() throws Exception {
-        LispSegmentLCAFAddress segAddress = (LispSegmentLCAFAddress) LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+        LcafSegmentAddress segAddress = (LcafSegmentAddress) LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
                 "02 20 00 0A " + //
                 "AA BB CC DD " + // instance ID
                 "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD")); // AFI=2,
         // IPv6
 
-        assertEquals(new LispIpv6Address(new byte[] { 0x11, 0x22, 0x33, 0x44, //
-                0x55, 0x66, 0x77, (byte) 0x88, //
-                (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, //
-                (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD }), segAddress.getAddress());
+        assertEquals(LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiAddress("1122:3344:5566:7788:99aa:bbcc:aabb:ccdd")), segAddress
+                .getAddress().getPrimitiveAddress());
 
     }
 
     @Test
     public void serialize__Simple() throws Exception {
-        LispSegmentLCAFAddress address = new LispSegmentLCAFAddress((byte) 0x06, 0x01020304, new LispIpv4Address(0x11223344));
-        ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
-        LispAddressSerializer.getInstance().serialize(buf,address);
+        LcafSegmentBuilder addressBuilder = new LcafSegmentBuilder();
+        addressBuilder.setInstanceId((long) 0x01020304);
+        addressBuilder.setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()).setLcafType((short) LispCanonicalAddressFormatEnum.SEGMENT.getLispCode());
+        addressBuilder.setAddress(new AddressBuilder().setPrimitiveAddress(LispAFIConvertor.asPrimitiveIPAfiAddress("17.34.51.68")).build());
+        ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(addressBuilder.build()));
+        LispAddressSerializer.getInstance().serialize(buf, addressBuilder.build());
         ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
-                "02 06 00 0A " + //
+                "02 00 00 0A " + //
                 "01 02 03 04 " + // instance ID
                 "00 01 11 22 33 44");
         ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
     }
-    
-    @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(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
-                "40 03 00 00 " + //
-                "02 06 00 0A " + //
-                "01 02 03 05 " + // instance ID
-                "00 01 11 22 33 44");
-        ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
-    }
+
 }