Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / PCEPSubobjectParserTest.java
index 0a89b438b99ef83e5888aeeb276065cf438296ac..280a7e6896db42d4b1d7ac90956c046786e5295c 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.protocol.pcep.impl;
 
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
@@ -22,16 +23,21 @@ import org.opendaylight.protocol.concepts.IPv6Address;
 import org.opendaylight.protocol.concepts.IPv6Prefix;
 import org.opendaylight.protocol.concepts.SharedRiskLinkGroup;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier;
 import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROIPv4PrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROIPv6PrefixSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROExplicitExclusionRouteSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROGeneralizedLabelSubobject;
+import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROPathKeyWith128PCEIDSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROPathKeyWith32PCEIDSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROProtectionType1Subobject;
 import org.opendaylight.protocol.pcep.subobject.EROProtectionType2Subobject;
 import org.opendaylight.protocol.pcep.subobject.EROType1LabelSubobject;
+import org.opendaylight.protocol.pcep.subobject.EROUnnumberedInterfaceSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROWavebandSwitchingLabelSubobject;
 import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject;
 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
@@ -49,10 +55,9 @@ import org.opendaylight.protocol.pcep.subobject.XROAsNumberSubobject;
 import org.opendaylight.protocol.pcep.subobject.XROIPPrefixSubobject;
 import org.opendaylight.protocol.pcep.subobject.XROSRLGSubobject;
 import org.opendaylight.protocol.pcep.subobject.XROSubobjectAttribute;
+import org.opendaylight.protocol.pcep.subobject.XROUnnumberedInterfaceSubobject;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.route.subobjects.subobject.type.AsNumberBuilder;
 
 /**
  * Tests for subobjects
@@ -66,42 +71,30 @@ public class PCEPSubobjectParserTest {
        final byte[] ipv4bytes1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
        final byte[] ipv4bytes2 = { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
 
-       final byte[] asnumber = { (byte) 0xA0, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64 };
-
        @Test
        public void testSerDeser() throws PCEPDeserializerException, IOException {
-               // final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfSubobjects.bin");
-               // final List<ExplicitRouteSubobject> objsToTest = PCEPEROSubobjectParser.parse(bytesFromFile);
-               //
-               // assertEquals(8, objsToTest.size());
-
-               final EROAsNumberSubobjectParser parser = new EROAsNumberSubobjectParser();
-               final CSubobject s = parser.parseSubobject(ByteArray.cutBytes(this.asnumber, 2));
-
-               assertEquals(s, new AsNumberBuilder().setAsNumber(new AsNumber((long) 0x64)).build());
-               // assertEquals(objsToTest.get(1), new AsNumberBuilder().setAsNumber(new AsNumber(0x0010L)).build());
-
-               // assertEquals(objsToTest.get(2), new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
-               // IPv4Address(this.ipv4bytes1), 0x20), true));
-               //
-               // assertEquals(objsToTest.get(3), new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
-               // IPv4Address(this.ipv4bytes2), 0x15), false));
-               // assertEquals(objsToTest.get(4), new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new
-               // IPv6Address(this.ipv6bytes1), 0x80), true));
-               //
-               // assertEquals(objsToTest.get(5), new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new
-               // IPv6Address(this.ipv6bytes2), 0x16), false));
-               // final byte[] addr1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
-               // assertEquals(objsToTest.get(6),
-               // new EROUnnumberedInterfaceSubobject(new IPv4Address(addr1), new UnnumberedInterfaceIdentifier(0xFFFFFFFFL),
-               // true));
-               //
-               // final byte[] addr2 = { (byte) 0x01, (byte) 0x24, (byte) 0x56, (byte) 0x78 };
-               // assertEquals(objsToTest.get(7),
-               // new EROUnnumberedInterfaceSubobject(new IPv4Address(addr2), new UnnumberedInterfaceIdentifier(0x9ABCDEF0L),
-               // false));
-               //
-               // assertArrayEquals(bytesFromFile, PCEPEROSubobjectParser.put(objsToTest));
+               final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfSubobjects.bin");
+               final List<ExplicitRouteSubobject> objsToTest = PCEPEROSubobjectParser.parse(bytesFromFile);
+
+               assertEquals(8, objsToTest.size());
+
+               assertEquals(objsToTest.get(0), new EROAsNumberSubobject(new AsNumber(0xFFFFL), true));
+               assertEquals(objsToTest.get(1), new EROAsNumberSubobject(new AsNumber(0x0010L), false));
+               assertEquals(objsToTest.get(2), new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(this.ipv4bytes1), 0x20), true));
+
+               assertEquals(objsToTest.get(3), new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(this.ipv4bytes2), 0x15), false));
+               assertEquals(objsToTest.get(4), new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(this.ipv6bytes1), 0x80), true));
+
+               assertEquals(objsToTest.get(5), new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(this.ipv6bytes2), 0x16), false));
+               final byte[] addr1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+               assertEquals(objsToTest.get(6),
+                               new EROUnnumberedInterfaceSubobject(new IPv4Address(addr1), new UnnumberedInterfaceIdentifier(0xFFFFFFFFL), true));
+
+               final byte[] addr2 = { (byte) 0x01, (byte) 0x24, (byte) 0x56, (byte) 0x78 };
+               assertEquals(objsToTest.get(7),
+                               new EROUnnumberedInterfaceSubobject(new IPv4Address(addr2), new UnnumberedInterfaceIdentifier(0x9ABCDEF0L), false));
+
+               assertArrayEquals(bytesFromFile, PCEPEROSubobjectParser.put(objsToTest));
 
        }
 
@@ -151,37 +144,41 @@ public class PCEPSubobjectParserTest {
                objsToTest.add(new XROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(this.ipv6bytes2), 0x16), true, XROSubobjectAttribute.INTERFACE));
                objsToTest.add(new XROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(this.ipv4bytes1), 0x16), false, XROSubobjectAttribute.INTERFACE));
                objsToTest.add(new XROAsNumberSubobject(new AsNumber((long) 0x1234), true));
-               // objsToTest.add(new XROUnnumberedInterfaceSubobject(new IPv4Address(this.ipv4bytes1), new
-               // UnnumberedInterfaceIdentifier(0xFFFFFFFFL), true, XROSubobjectAttribute.SRLG));
+               objsToTest.add(new XROUnnumberedInterfaceSubobject(new IPv4Address(this.ipv4bytes1), new UnnumberedInterfaceIdentifier(0xFFFFFFFFL), true, XROSubobjectAttribute.SRLG));
                objsToTest.add(new XROSRLGSubobject(new SharedRiskLinkGroup(0x12345678L), false));
 
                assertEquals(objsToTest, PCEPXROSubobjectParser.parse(PCEPXROSubobjectParser.put(objsToTest)));
        }
 
-       //
-       // @Test
-       // public void testDifferentLengthExceptions() {
-       // final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data
-       // // for parsing subobjects
-       //
-       // try {
-       // EROAsNumberSubobjectParser.parse(bytes, true);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // EROUnnumberedInterfaceSubobjectParser.parse(bytes, true);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // EROIpPrefixSubobjectParser.parse(bytes, true);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       // }
+       @Test
+       public void testDifferentLengthExceptions() {
+               final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data
+               // for parsing subobjects
+
+               try {
+                       EROAsNumberSubobjectParser.parse(bytes, true);
+                       fail("");
+               } catch (final PCEPDeserializerException e) {
+               }
+
+               try {
+                       EROUnnumberedInterfaceSubobjectParser.parse(bytes, true);
+                       fail("");
+               } catch (final PCEPDeserializerException e) {
+               }
+
+               try {
+                       EROIPv4PrefixSubobjectParser.parse(bytes, true);
+                       fail("");
+               } catch (final PCEPDeserializerException e) {
+               }
+
+               try {
+                       EROIPv6PrefixSubobjectParser.parse(bytes, true);
+                       fail("");
+               } catch (final PCEPDeserializerException e) {
+               }
+       }
 
        @Test
        public void testNullExceptions() throws PCEPDeserializerException {
@@ -189,7 +186,7 @@ public class PCEPSubobjectParserTest {
                // subobjects
 
                try {
-                       new EROAsNumberSubobjectParser().parseSubobject(bytes);
+                       EROAsNumberSubobjectParser.parse(bytes, true);
                        fail("");
                } catch (final IllegalArgumentException e) {
                }
@@ -201,7 +198,13 @@ public class PCEPSubobjectParserTest {
                }
 
                try {
-                       new EROIpPrefixSubobjectParser().parseSubobject(bytes);
+                       EROIPv4PrefixSubobjectParser.parse(bytes, true);
+                       fail("");
+               } catch (final IllegalArgumentException e) {
+               }
+
+               try {
+                       EROIPv6PrefixSubobjectParser.parse(bytes, true);
                        fail("");
                } catch (final IllegalArgumentException e) {
                }
@@ -213,11 +216,11 @@ public class PCEPSubobjectParserTest {
                final ExplicitRouteSubobject instance = new ExplicitRouteSubobject() {
                };
 
-               // try {
-               // new EROAsNumberSubobjectParser().serializeSubobject(instance);
-               // fail("");
-               // } catch (final IllegalArgumentException e) {
-               // }
+               try {
+                       EROAsNumberSubobjectParser.put(instance);
+                       fail("");
+               } catch (final IllegalArgumentException e) {
+               }
 
                try {
                        EROUnnumberedInterfaceSubobjectParser.put(instance);
@@ -225,36 +228,63 @@ public class PCEPSubobjectParserTest {
                } catch (final IllegalArgumentException e) {
                }
 
-               // try {
-               // EROIpPrefixSubobjectParser.put(instance);
-               // fail("");
-               // } catch (final IllegalArgumentException e) {
-               // }
-
-               // try {
-               // final byte[] ipv6addr = { (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) 0x00 };
-               // EROIpPrefixSubobjectParser.put(new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(ipv6addr),
-               // 1), false));
-               // fail("");
-               // } catch (final IllegalArgumentException e) {
-               // }
-               //
-               // try {
-               // EROIPv6PrefixSubobjectParser.put(instance);
-               // fail("");
-               // } catch (final IllegalArgumentException e) {
-               // }
-               //
-               // try {
-               // final byte[] ipv4addr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
-               // EROIPv6PrefixSubobjectParser.put(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
-               // IPv4Address(ipv4addr), 1), false));
-               // fail("");
-               // } catch (final IllegalArgumentException e) {
-               // }
+               try {
+                       EROIPv4PrefixSubobjectParser.put(instance);
+                       fail("");
+               } catch (final IllegalArgumentException e) {
+               }
+
+               try {
+                       final byte[] ipv6addr = { (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) 0x00 };
+                       EROIPv4PrefixSubobjectParser.put(new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(ipv6addr), 1), false));
+                       fail("");
+               } catch (final IllegalArgumentException e) {
+               }
+
+               try {
+                       EROIPv6PrefixSubobjectParser.put(instance);
+                       fail("");
+               } catch (final IllegalArgumentException e) {
+               }
+
+               try {
+                       final byte[] ipv4addr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
+                       EROIPv6PrefixSubobjectParser.put(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(ipv4addr), 1), false));
+                       fail("");
+               } catch (final IllegalArgumentException e) {
+               }
+
+       }
+
+       @Test
+       public void testEmptyExceptions() throws PCEPDeserializerException {
+               final byte[] bytes = {}; // not empty but not enought data for parsing
+               // subobjects
+
+               try {
+                       EROAsNumberSubobjectParser.parse(bytes, true);
+                       fail("");
+               } catch (final IllegalArgumentException e) {
+               }
+
+               try {
+                       EROUnnumberedInterfaceSubobjectParser.parse(bytes, true);
+                       fail("");
+               } catch (final IllegalArgumentException e) {
+               }
 
+               try {
+                       EROIPv4PrefixSubobjectParser.parse(bytes, true);
+                       fail("");
+               } catch (final IllegalArgumentException e) {
+               }
+
+               try {
+                       EROIPv6PrefixSubobjectParser.parse(bytes, true);
+                       fail("");
+               } catch (final IllegalArgumentException e) {
+               }
        }
+
 }