BUG-50 : added test for PathKey Object. 42/2342/1
authorDana Kutenicsova <dkutenic@cisco.com>
Sun, 3 Nov 2013 21:46:09 +0000 (22:46 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Sun, 3 Nov 2013 21:46:09 +0000 (22:46 +0100)
Change-Id: Ia8cbbc0c22e319ac8f88765a7682397f8a7bdf0a
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/PCEPPathKeyObjectParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java
pcep/impl/src/test/resources/PCEPPathKeyObject.bin [new file with mode: 0755]

index 9032c94e7c5eef8146ee923e9c9afee927a7e76f..458d6758e1c266da5496a7d89a5be9322b900c27 100644 (file)
@@ -263,7 +263,7 @@ public final class Activator implements PCEPExtensionProviderActivator {
                context.registerObjectParser(PCEPLoadBalancingObjectParser.CLASS, PCEPLoadBalancingObjectParser.TYPE,
                                new PCEPLoadBalancingObjectParser(tlvReg));
                context.registerObjectParser(PCEPCloseObjectParser.CLASS, PCEPCloseObjectParser.TYPE, new PCEPCloseObjectParser(tlvReg));
-               context.registerObjectParser(PCEPPathKeyObjectParser.CLASS, PCEPPathKeyObjectParser.TYPE, new PCEPPathKeyObjectParser(tlvReg));
+               context.registerObjectParser(PCEPPathKeyObjectParser.CLASS, PCEPPathKeyObjectParser.TYPE, new PCEPPathKeyObjectParser(eroSubReg));
                context.registerObjectParser(PCEPObjectiveFunctionObjectParser.CLASS, PCEPObjectiveFunctionObjectParser.TYPE,
                                new PCEPObjectiveFunctionObjectParser(tlvReg));
                context.registerObjectParser(PCEPClassTypeObjectParser.CLASS, PCEPClassTypeObjectParser.TYPE, new PCEPClassTypeObjectParser(tlvReg));
@@ -290,7 +290,7 @@ public final class Activator implements PCEPExtensionProviderActivator {
                context.registerObjectSerializer(PcepErrorObject.class, new PCEPErrorObjectParser(tlvReg));
                context.registerObjectSerializer(LoadBalancingObject.class, new PCEPLoadBalancingObjectParser(tlvReg));
                context.registerObjectSerializer(CloseObject.class, new PCEPCloseObjectParser(tlvReg));
-               context.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(tlvReg));
+               context.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(eroSubReg));
                context.registerObjectSerializer(OfObject.class, new PCEPObjectiveFunctionObjectParser(tlvReg));
                context.registerObjectSerializer(ClasstypeObject.class, new PCEPClassTypeObjectParser(tlvReg));
                context.registerObjectSerializer(GcObject.class, new PCEPGlobalConstraintsObjectParser(tlvReg));
index 824a244f6be49543bdf0ed43a29f4ddd9cfe0342..8f5ed1bdd8253ab389fba4bb72b9df727273d65d 100644 (file)
@@ -31,9 +31,9 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
        private static final int SUB_LENGTH_F_LENGTH = 1;
        private static final int SUB_HEADER_LENGTH = SUB_TYPE_FLAG_F_LENGTH + SUB_LENGTH_F_LENGTH;
 
-       public static final int TYPE_FLAG_F_OFFSET = 0;
-       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;
+       private static final int TYPE_FLAG_F_OFFSET = 0;
+       private static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH;
+       private static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH;
 
        private final EROSubobjectHandlerRegistry subobjReg;
 
index f535303104b85ce6d51d4b98a658000bf7aad321..60934c78b1dfc8f998692790962c262e72103a16 100644 (file)
@@ -7,59 +7,67 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import java.util.List;
+
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeyObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+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.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeys;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeysBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.path.key.expansion.PathKeyBuilder;
 
+import com.google.common.collect.Lists;
+
 /**
  * Parser for {@link PathKeyObject}
  */
-public class PCEPPathKeyObjectParser extends AbstractObjectWithTlvsParser<PathKeyBuilder> {
+public class PCEPPathKeyObjectParser extends AbstractEROWithSubobjectsParser {
 
        public static final int CLASS = 16;
 
        public static final int TYPE = 1;
 
-       public PCEPPathKeyObjectParser(final TlvHandlerRegistry tlvReg) {
-               super(tlvReg);
+       public PCEPPathKeyObjectParser(final EROSubobjectHandlerRegistry subReg) {
+               super(subReg);
        }
 
        @Override
        public PathKeyObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
-               // FIXME : finish
-
+                       PCEPDocumentedException {
                final PathKeyBuilder builder = new PathKeyBuilder();
-
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-
+               final List<PathKeys> pk = Lists.newArrayList();
+               final List<Subobjects> subs = parseSubobjects(bytes);
+               for (final Subobjects s : subs) {
+                       final PathKey k = (PathKey) s.getSubobjectType();
+                       pk.add(new PathKeysBuilder().setLoose(s.isLoose()).setPceId(k.getPathKey().getPceId()).setPathKey(k.getPathKey().getPathKey()).build());
+               }
+               builder.setPathKeys(pk);
                return builder.build();
        }
 
-       @Override
-       public void addTlv(final PathKeyBuilder builder, final Tlv tlv) {
-               // No tlvs defined
-       }
-
        @Override
        public byte[] serializeObject(final Object object) {
                if (!(object instanceof PathKeyObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed PathKeyObject.");
                }
-
                final PathKeyObject pkey = (PathKeyObject) object;
-
-               // FIXME, but no Tlvs defined
-               // final byte[] tlvs = PCEPTlvParser.put(lspaObj.getTlvs());
-               // final byte[] retBytes = new byte[TLVS_F_OFFSET + tlvs.length];
-               // ByteArray.copyWhole(tlvs, retBytes, TLVS_F_OFFSET);
-               return new byte[0];
+               final List<PathKeys> pk = pkey.getPathKeys();
+               final List<Subobjects> subs = Lists.newArrayList();
+               for (final PathKeys p : pk) {
+                       subs.add(new SubobjectsBuilder().setLoose(p.isLoose()).setSubobjectType(
+                                       new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder().setPathKey(
+                                                       new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder().setPathKey(
+                                                                       p.getPathKey()).setPceId(p.getPceId()).build()).build()).build());
+               }
+               return serializeSubobject(subs);
        }
 
        @Override
index 4c1b66750bce0cd43aac2a276281e7a8b1bc77e2..6a24ec4de8bc0b05a3475c85dbb36dc1f6bfbf30 100644 (file)
@@ -37,6 +37,7 @@ import org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
 import org.opendaylight.protocol.pcep.impl.object.PCEPSrpObjectParser;
@@ -52,9 +53,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OperationalStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PlspId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReportedRouteObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpIdNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
@@ -74,6 +76,8 @@ 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.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.path.key.object.PathKeys;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeysBuilder;
 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;
@@ -84,6 +88,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.pcrep.message.pcrep.message.replies.result.failure.no.path.tlvs.NoPathVectorBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.RpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.path.key.expansion.PathKeyBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.LoadBalancingBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.ReportedRouteBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.reported.route.BandwidthBuilder;
@@ -265,7 +270,6 @@ public class PCEPObjectParserTest {
                                                0x1245678L).setInterfaceId(0x9abcdef0L).build()).setProtectionAvailable(false).setProtectionInUse(false).build());
                builder.setSubobjects(subs);
 
-               final ReportedRouteObject t = parser.parseObject(new ObjectHeaderImpl(false, false), result);
                assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
                // FIXME: fix Ipv6Serializers (getType)
                // assertArrayEquals(result, parser.serializeObject(builder.build()));
@@ -591,6 +595,23 @@ public class PCEPObjectParserTest {
                assertArrayEquals(result, parser.serializeObject(builder.build()));
        }
 
+       @Test
+       public void testPathKeyObject() throws Exception {
+               final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(PCEPExtensionProviderContextImpl.create().getEROSubobjectHandlerRegistry());
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin");
+
+               final PathKeyBuilder builder = new PathKeyBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(false);
+               final List<PathKeys> list = Lists.newArrayList();
+               list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234)).setPceId(
+                               new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build());
+               builder.setPathKeys(list);
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
        @Test
        public void testSrpObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
                final PCEPSrpObjectParser parser = new PCEPSrpObjectParser(this.tlvRegistry);
@@ -635,5 +656,4 @@ public class PCEPObjectParserTest {
                assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
                assertArrayEquals(result, parser.serializeObject(builder.build()));
        }
-
 }
diff --git a/pcep/impl/src/test/resources/PCEPPathKeyObject.bin b/pcep/impl/src/test/resources/PCEPPathKeyObject.bin
new file mode 100755 (executable)
index 0000000..0b98826
Binary files /dev/null and b/pcep/impl/src/test/resources/PCEPPathKeyObject.bin differ