BUG-50 : added test for ERO. 34/2334/1
authorDana Kutenicsova <dkutenic@cisco.com>
Sun, 3 Nov 2013 13:11:48 +0000 (14:11 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Sun, 3 Nov 2013 13:11:48 +0000 (14:11 +0100)
Change-Id: Iced49450056c8847a5944e5f3fbbb090fbb0b253
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Activator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractEROWithSubobjectsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExplicitRouteObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROUnnumberedInterfaceSubobjectParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java
pcep/impl/src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionProviderContext.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/OSGiPCEPExtensionProviderContext.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/PCEPExtensionProviderContextImpl.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectHandlerRegistry.java

index 8fffe1f53611f33bb50f7d9e39f37652e2b17781..decb257e1b9aeaeb5ef6fef4af1c0bd437a1b1c9 100644 (file)
@@ -125,12 +125,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.RsvpErrorSpec;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.Stateful;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.symbolic.path.name.tlv.SymbolicPathName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AsNumberSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.IpPrefixSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LabelSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.Label;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.Srlg;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.Unnumbered;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabel;
@@ -168,11 +168,13 @@ public final class Activator implements PCEPExtensionProviderActivator {
                context.registerEROSubobjectParser(EROPathKeySubobjectParser.TYPE, new EROPathKeySubobjectParser());
                context.registerEROSubobjectParser(EROPathKeySubobjectParser.TYPE128, new EROPathKeySubobjectParser());
 
-               context.registerEROSubobjectSerializer(IpPrefixSubobject.class, new EROIpPrefixSubobjectParser());
-               context.registerEROSubobjectSerializer(AsNumberSubobject.class, new EROAsNumberSubobjectParser());
-               context.registerEROSubobjectSerializer(LabelSubobject.class, new EROLabelSubobjectParser(labelReg));
-               context.registerEROSubobjectSerializer(UnnumberedSubobject.class, new EROUnnumberedInterfaceSubobjectParser());
-               context.registerEROSubobjectSerializer(PathKeySubobject.class, new EROPathKeySubobjectParser());
+               context.registerEROSubobjectSerializer(IpPrefix.class, new EROIpPrefixSubobjectParser());
+               context.registerEROSubobjectSerializer(AsNumber.class, new EROAsNumberSubobjectParser());
+               context.registerEROSubobjectSerializer(Label.class, new EROLabelSubobjectParser(labelReg));
+               context.registerEROSubobjectSerializer(Unnumbered.class, new EROUnnumberedInterfaceSubobjectParser());
+               context.registerEROSubobjectSerializer(
+                               org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey.class,
+                               new EROPathKeySubobjectParser());
 
                final RROSubobjectHandlerRegistry rroSubReg = context.getRROSubobjectHandlerRegistry();
                context.registerRROSubobjectParser(RROIpPrefixSubobjectParser.TYPE, new RROIpPrefixSubobjectParser());
index 8265e8e4de74167810d38761cb63c26a8d17d5f5..824a244f6be49543bdf0ed43a29f4ddd9cfe0342 100644 (file)
@@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
+import com.google.common.primitives.UnsignedBytes;
 
 public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, ObjectSerializer {
 
@@ -34,8 +35,6 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
        public static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH;
        public static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH;
 
-       protected static final int PADDED_TO = 4;
-
        private final EROSubobjectHandlerRegistry subobjReg;
 
        protected AbstractEROWithSubobjectsParser(final EROSubobjectHandlerRegistry subobjReg) {
@@ -49,7 +48,6 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
 
                boolean loose_flag = false;
                int type;
-
                byte[] soContentsBytes;
                int length;
                int offset = 0;
@@ -90,15 +88,14 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
 
                for (final Subobjects subobject : subobjects) {
 
-                       final EROSubobjectSerializer serializer = this.subobjReg.getSubobjectSerializer(subobject);
+                       final EROSubobjectSerializer serializer = this.subobjReg.getSubobjectSerializer(subobject.getSubobjectType());
 
                        final byte[] valueBytes = serializer.serializeSubobject(subobject);
 
                        final byte[] bytes = new byte[SUB_HEADER_LENGTH + valueBytes.length];
 
-                       final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (subobject.isLoose() ? 1 << 7
-                                       : 0));
-                       final byte lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - 1)[0];
+                       final byte typeBytes = (byte) (UnsignedBytes.checkedCast(serializer.getType()) | (subobject.isLoose() ? 1 << 7 : 0));
+                       final byte lengthBytes = UnsignedBytes.checkedCast(valueBytes.length + SUB_HEADER_LENGTH);
 
                        bytes[0] = typeBytes;
                        bytes[1] = lengthBytes;
index 2eb4fd3d05592c3e8f2d7c78da746f4687d64263..647a96b44e00e7151d47764afd2336311a09e1fb 100644 (file)
@@ -47,7 +47,6 @@ public class PCEPExplicitRouteObjectParser extends AbstractEROWithSubobjectsPars
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
                                        + ". Needed ExplicitRouteObject.");
                }
-
                final ExplicitRouteObject ero = ((ExplicitRouteObject) object);
 
                assert !(ero.getSubobjects().isEmpty()) : "Empty Explicit Route Object.";
index a0dd7c653c9a29e168f07bc5e1acfa236d60b7b7..06235d0ec313f1a4131c2f7118d5d5e9ce5eeb6c 100644 (file)
@@ -25,13 +25,13 @@ public class EROUnnumberedInterfaceSubobjectParser implements EROSubobjectParser
 
        public static final int TYPE = 4;
 
-       public static final int ROUTER_ID_NUMBER_LENGTH = 4;
-       public static final int INTERFACE_ID_NUMBER_LENGTH = 4;
+       private static final int ROUTER_ID_NUMBER_LENGTH = 4;
+       private static final int INTERFACE_ID_NUMBER_LENGTH = 4;
 
-       public static final int ROUTER_ID_NUMBER_OFFSET = 2; // added reserved field of size 2
-       public static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
+       private static final int ROUTER_ID_NUMBER_OFFSET = 2;
+       private static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
 
-       public static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
+       private static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
index 9d096d834c3d98db4f8b94f6db12c5e3687a56e5..2a8b63a7c90a8653f965b6d78f3f181ab15140bf 100644 (file)
@@ -14,6 +14,7 @@ import java.io.IOException;
 import java.math.BigInteger;
 import java.util.List;
 
+import org.apache.commons.codec.binary.Hex;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.concepts.Ipv4Util;
@@ -26,6 +27,7 @@ import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPExcludeRouteObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPExplicitRouteObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPLspObjectParser;
@@ -68,6 +70,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.open.message.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.definition.ExplicitRouteBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.TlvsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.EndpointsBuilder;
@@ -95,6 +98,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ExcludeRouteSubobjects.Attribute;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedBuilder;
 
 import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
@@ -187,45 +191,28 @@ public class PCEPObjectParserTest {
                assertArrayEquals(result, parser.serializeObject(builder.build()));
        }
 
-       //
-       // @Test
-       // public void testERObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
-       // final byte[] bytesFromFile =
-       // ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin");
-       //
-       // MockitoAnnotations.initMocks(this);
-       // PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(registry);
-       // doReturn(parser).when(registry).getObjectParser(PCEPExplicitRouteObjectParser.TYPE,
-       // PCEPExplicitRouteObjectParser.CLASS);
-       // doReturn(new EROAsNumberSubobjectParser()).when(registry).getSubobjectParser(EROAsNumberSubobjectParser.TYPE);
-       // ObjectHeader h = new ObjectHeader() {
-       //
-       // @Override
-       // public Class<? extends DataContainer> getImplementedInterface() {
-       // // TODO Auto-generated method stub
-       // return null;
-       // }
-       //
-       // @Override
-       // public Boolean isProcessingRule() {
-       // return false;
-       // }
-       //
-       // @Override
-       // public Boolean isIgnore() {
-       // return false;
-       // }
-       // };
-       //
-       // final ExplicitRouteSubobject specObj = (ExplicitRouteSubobject)
-       // registry.getObjectParser(PCEPExplicitRouteObjectParser.TYPE, PCEPExplicitRouteObjectParser.CLASS).parseObject(h,
-       // bytesFromFile);
-       //
-       // System.out.println(specObj.toString());
-       //
-       // //final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
-       // //assertArrayEquals(bytesFromFile, bytesActual);
-       // }
+       @Test
+       public void testEROObject() throws Exception {
+               final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(PCEPExtensionProviderContextImpl.create().getEROSubobjectHandlerRegistry());
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin");
+
+               final ExplicitRouteBuilder builder = new ExplicitRouteBuilder();
+               builder.setProcessingRule(false);
+               builder.setIgnore(false);
+               final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects> subs = Lists.newArrayList();
+               subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder().setLoose(
+                               true).setSubobjectType(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()).build());
+               subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder().setLoose(
+                               true).setSubobjectType(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build());
+               subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder().setLoose(
+                               true).setSubobjectType(new UnnumberedBuilder().setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).build()).build());
+               builder.setSubobjects(subs);
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
+               System.out.println(new String(Hex.encodeHex(parser.serializeObject(builder.build()))));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
        //
        // @Test
        // public void testIRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
index 7613b9b4542d643df3e9d3f995bb13cdeb1287a7..9b7cead89183d3b9472fb609b7cd324009b56332 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin and b/pcep/impl/src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin differ
index 83d7e24eb008e8ed12144a0ceac2ac4cf0fcb3b9..f7ebf51ac5fec7a6f987dceecaebb93061c3f8bc 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.protocol.pcep.spi;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.SubobjectType;
 
 public interface EROSubobjectHandlerRegistry {
        public EROSubobjectParser getSubobjectParser(int subobjectType);
-       public EROSubobjectSerializer getSubobjectSerializer(Subobjects subobject);
+
+       public EROSubobjectSerializer getSubobjectSerializer(SubobjectType subobject);
 }
index 84e219d3ad8b96d6bab1c1ca192874abe6c2b33a..0abe69011c1db73b0f39ec43971e31d435f545dc 100644 (file)
@@ -21,7 +21,7 @@ public interface PCEPExtensionProviderContext extends PCEPExtensionConsumerConte
 
        public AutoCloseable registerEROSubobjectParser(int subobjectType, EROSubobjectParser parser);
 
-       public AutoCloseable registerEROSubobjectSerializer(Class<? extends CSubobject> subobjectClass, EROSubobjectSerializer serializer);
+       public AutoCloseable registerEROSubobjectSerializer(Class<? extends SubobjectType> subobjectClass, EROSubobjectSerializer serializer);
 
        public AutoCloseable registerMessageParser(int messageType, MessageParser parser);
 
index dff12f9a3fd789f4831ee04da920dd97963edc56..5d7a73faf2ad9d3aaefb6d7cdae126730e5b1ad2 100644 (file)
@@ -54,7 +54,7 @@ class OSGiPCEPExtensionProviderContext extends OSGiPCEPExtensionConsumerContext
        }
 
        @Override
-       public AutoCloseable registerEROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+       public AutoCloseable registerEROSubobjectSerializer(final Class<? extends SubobjectType> subobjectClass,
                        final EROSubobjectSerializer serializer) {
                // TODO Auto-generated method stub
                return null;
index b697116975e6ffacdb591b5b566662b07bbe0265..710865c9fca254010b7b3af43b443905b7692da2 100644 (file)
@@ -137,7 +137,7 @@ public final class PCEPExtensionProviderContextImpl implements PCEPExtensionProv
        }
 
        @Override
-       public AutoCloseable registerEROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+       public AutoCloseable registerEROSubobjectSerializer(final Class<? extends SubobjectType> subobjectClass,
                        final EROSubobjectSerializer serializer) {
                return this.eroSubReg.registerSubobjectSerializer(subobjectClass, serializer);
        }
index e083d2bebe92438d96169450bc6b15cb665544f6..5f81b0f3dd3e9b1519c1a451f5967abddfff182d 100644 (file)
@@ -12,8 +12,7 @@ import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.util.Util;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
-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.basic.explicit.route.subobjects.SubobjectType;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
 import com.google.common.base.Preconditions;
@@ -26,7 +25,7 @@ public final class SimpleEROSubobjectHandlerRegistry implements EROSubobjectHand
                return this.handlers.registerParser(subobjectType, parser);
        }
 
-       public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+       public AutoCloseable registerSubobjectSerializer(final Class<? extends SubobjectType> subobjectClass,
                        final EROSubobjectSerializer serializer) {
                return this.handlers.registerSerializer(subobjectClass, serializer);
        }
@@ -38,7 +37,7 @@ public final class SimpleEROSubobjectHandlerRegistry implements EROSubobjectHand
        }
 
        @Override
-       public EROSubobjectSerializer getSubobjectSerializer(final Subobjects subobject) {
+       public EROSubobjectSerializer getSubobjectSerializer(final SubobjectType subobject) {
                return this.handlers.getSerializer(subobject.getImplementedInterface());
        }
 }