BUG 4181: Fix PCEP Parsers/Serializers 89/26589/11
authorClaudio D. Gasparini <cgaspari@cisco.com>
Mon, 7 Sep 2015 08:34:40 +0000 (10:34 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 24 Sep 2015 21:37:49 +0000 (21:37 +0000)
Objects with more than one Ctype are not serialized
correctly.
This required update pcep-types.yang model, and register correctly
parser/serializers for:
-Bandwidth Object
-PathKEy Object /subobject
-EndPoint Object

Change-Id: I898c0521914eb4cb7f1a4a1349fdaf853101e3cf
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
15 files changed:
pcep/api/src/main/yang/pcep-types.yang
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Activator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractBandwidthParser.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIpv4ObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIpv6ObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExistingBandwidthObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROPathKey128SubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROPathKey32SubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROPathKey128SubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROPathKey32SubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROPathKey128SubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROPathKey32SubobjectParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java

index 90bc43ebbaeda85a59338f1335b7616c33899009..91de6854b2f1ab0bc82e20acb7d99c99525ac33b 100644 (file)
@@ -405,16 +405,28 @@ module pcep-types {
         }
     }
 
+    grouping bandwidth {
+        // No possibility to carry TLVs
+        leaf bandwidth {
+            type netc:bandwidth;
+        }
+    }
+
     grouping bandwidth-object {
         description "BANDWIDTH Object";
         reference "https://tools.ietf.org/html/rfc5440#section-7.7";
         container bandwidth {
             uses object;
+            uses bandwidth;
+        }
+    }
 
-            // No possibility to carry TLVs
-            leaf bandwidth {
-                type netc:bandwidth;
-            }
+    grouping reoptimization-bandwidth-object {
+        description "BANDWIDTH Object";
+        reference "https://tools.ietf.org/html/rfc5440#section-7.7";
+        container bandwidth {
+            uses object;
+            uses bandwidth;
         }
     }
 
@@ -969,7 +981,7 @@ module pcep-types {
                         container reported-route {
                             uses reported-route-object;
 
-                            uses bandwidth-object;
+                            uses reoptimization-bandwidth-object;
                         }
 
                         uses vendor-information-objects;
index a6de235da65e75f3d1333bb359c566393b9a79ec..7cde3b86332ac798971c6b06cff85947148ec68d 100644 (file)
@@ -211,16 +211,18 @@ public final class Activator extends AbstractPCEPExtensionProviderActivator {
         regs.add(context.registerObjectSerializer(NoPath.class, noPathParser));
 
         final PCEPEndPointsIpv4ObjectParser endpoints4Parser = new PCEPEndPointsIpv4ObjectParser();
+        final PCEPEndPointsIpv6ObjectParser endpoints6Parser = new PCEPEndPointsIpv6ObjectParser();
         regs.add(context.registerObjectParser(PCEPEndPointsIpv4ObjectParser.CLASS, PCEPEndPointsIpv4ObjectParser.TYPE, endpoints4Parser));
-        regs.add(context.registerObjectParser(PCEPEndPointsIpv6ObjectParser.CLASS, PCEPEndPointsIpv6ObjectParser.TYPE,
-            new PCEPEndPointsIpv4ObjectParser()));
+        regs.add(context.registerObjectParser(PCEPEndPointsIpv6ObjectParser.CLASS, PCEPEndPointsIpv6ObjectParser.TYPE, endpoints6Parser));
         regs.add(context.registerObjectSerializer(EndpointsObj.class, endpoints4Parser));
 
         final PCEPBandwidthObjectParser bwParser = new PCEPBandwidthObjectParser();
+        final PCEPExistingBandwidthObjectParser bwExistingParser = new PCEPExistingBandwidthObjectParser();
         regs.add(context.registerObjectParser(PCEPBandwidthObjectParser.CLASS, PCEPBandwidthObjectParser.TYPE, bwParser));
-        regs.add(context.registerObjectParser(PCEPExistingBandwidthObjectParser.CLASS, PCEPExistingBandwidthObjectParser.TYPE,
-            new PCEPExistingBandwidthObjectParser()));
+        regs.add(context.registerObjectParser(PCEPExistingBandwidthObjectParser.CLASS, PCEPExistingBandwidthObjectParser.TYPE, bwExistingParser));
         regs.add(context.registerObjectSerializer(Bandwidth.class, bwParser));
+        regs.add(context.registerObjectSerializer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
+            .pcep.types.rev131005.reoptimization.bandwidth.object.Bandwidth.class, bwExistingParser));
 
         final PCEPMetricObjectParser metricParser = new PCEPMetricObjectParser();
         regs.add(context.registerObjectParser(PCEPMetricObjectParser.CLASS, PCEPMetricObjectParser.TYPE, metricParser));
index ddb69b6ea34739fb8f207af8f8277ef37edca031..8c25628fb92f2665cf417a6ecf0fca3754ce779e 100644 (file)
@@ -281,8 +281,8 @@ public class PCEPRequestMessageParser extends AbstractMessageParser {
                 rrBuilder.setRro((Rro) obj);
                 objects.remove(0);
                 final Object nextObj = objects.get(0);
-                if (nextObj instanceof Bandwidth) {
-                    rrBuilder.setBandwidth((Bandwidth) nextObj);
+                if (nextObj instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.Bandwidth) {
+                    rrBuilder.setBandwidth((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.Bandwidth) nextObj);
                 }
                 return State.REPORTED_IN;
             }
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractBandwidthParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractBandwidthParser.java
deleted file mode 100644 (file)
index e19c3be..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, 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.protocol.pcep.impl.object;
-
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-
-import com.google.common.base.Preconditions;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import org.opendaylight.protocol.pcep.spi.ObjectParser;
-import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
-import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.util.ByteArray;
-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.bandwidth.object.Bandwidth;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
-
-abstract class AbstractBandwidthParser implements ObjectParser, ObjectSerializer {
-
-    private static final int BANDWIDTH_F_LENGTH = 4;
-
-    @Override
-    public Bandwidth parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
-        Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
-        if (bytes.readableBytes() != BANDWIDTH_F_LENGTH) {
-            throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: "
-                    + BANDWIDTH_F_LENGTH + ".");
-        }
-        final BandwidthBuilder builder = new BandwidthBuilder();
-        builder.setIgnore(header.isIgnore());
-        builder.setProcessingRule(header.isProcessingRule());
-        builder.setBandwidth(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(ByteArray.getAllBytes(bytes)));
-        return builder.build();
-    }
-
-    @Override
-    public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof Bandwidth, "Wrong instance of PCEPObject. Passed %s. Needed BandwidthObject.", object.getClass());
-        final ByteBuf body = Unpooled.buffer();
-        writeFloat32(((Bandwidth) object).getBandwidth(), body);
-        formatBandwidth(object.isProcessingRule(), object.isIgnore(), body, buffer);
-    }
-
-    protected abstract void formatBandwidth(final Boolean processed, final Boolean ignored, final ByteBuf body, final ByteBuf buffer);
-}
index 83cc7f22e9c9a711d034cff54d92d710ce0dbd13..722f8a78d48456c539469048442205a27ce78857 100644 (file)
@@ -7,20 +7,50 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
+
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteArray;
+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.bandwidth.object.Bandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
 
 /**
  * Parser for Bandwidth
  */
-public class PCEPBandwidthObjectParser extends AbstractBandwidthParser {
+public class PCEPBandwidthObjectParser implements ObjectParser, ObjectSerializer {
 
     public static final int CLASS = 5;
 
     public static final int TYPE = 1;
 
+    public static final int BANDWIDTH_F_LENGTH = 4;
+
+    @Override
+    public Bandwidth parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
+        Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+        if (bytes.readableBytes() != BANDWIDTH_F_LENGTH) {
+            throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: "
+                + BANDWIDTH_F_LENGTH + ".");
+        }
+        final BandwidthBuilder builder = new BandwidthBuilder();
+        builder.setIgnore(header.isIgnore());
+        builder.setProcessingRule(header.isProcessingRule());
+        builder.setBandwidth(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(ByteArray.getAllBytes(bytes)));
+        return builder.build();
+    }
+
     @Override
-    protected void formatBandwidth(final Boolean processed, final Boolean ignored, final ByteBuf body, final ByteBuf buffer) {
-        ObjectUtil.formatSubobject(TYPE, CLASS, processed, ignored, body, buffer);
+    public void serializeObject(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object object, final ByteBuf buffer) {
+        Preconditions.checkArgument(object instanceof Bandwidth, "Wrong instance of PCEPObject. Passed %s. Needed BandwidthObject.", object.getClass());
+        final ByteBuf body = Unpooled.buffer();
+        writeFloat32(((Bandwidth) object).getBandwidth(), body);
+        ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 }
index 04df6390aa3bf8462cb1e7c0f5e08f6f0a4ef4c4..2fb2b034c47452dd55277c12c2f593b7773b4dd3 100644 (file)
@@ -24,6 +24,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.endpoints.AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4Case;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6Case;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObj;
@@ -67,6 +68,9 @@ public class PCEPEndPointsIpv4ObjectParser implements ObjectParser, ObjectSerial
         Preconditions.checkArgument(object instanceof EndpointsObj, "Wrong instance of PCEPObject. Passed %s. Needed EndpointsObject.", object.getClass());
         final EndpointsObj ePObj = (EndpointsObj) object;
         final AddressFamily afi = ePObj.getAddressFamily();
+        if(afi instanceof Ipv6Case) {
+            PCEPEndPointsIpv6ObjectParser.serializeObject(object,buffer);
+        }
         Preconditions.checkArgument(afi instanceof Ipv4Case, "Wrong instance of NetworkAddress. Passed %s. Needed IPv4", afi.getClass());
         final Ipv4 ipv4 = ((Ipv4Case) afi).getIpv4();
         final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH + Ipv4Util.IP4_LENGTH);
index f5267ce742bdc853f5c5b45a0f8189a341da158a..3a3335844126329d945995251e9333b4002149a9 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.pcep.spi.ObjectParser;
-import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
@@ -34,7 +33,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Parser for IPv6 {@link EndpointsObj}
  */
-public class PCEPEndPointsIpv6ObjectParser implements ObjectParser, ObjectSerializer {
+public class PCEPEndPointsIpv6ObjectParser implements ObjectParser {
 
     private static final Logger LOG = LoggerFactory.getLogger(PCEPEndPointsIpv6ObjectParser.class);
 
@@ -62,8 +61,7 @@ public class PCEPEndPointsIpv6ObjectParser implements ObjectParser, ObjectSerial
         return builder.build();
     }
 
-    @Override
-    public void serializeObject(final Object object, final ByteBuf buffer) {
+    public static void serializeObject(final Object object, final ByteBuf buffer) {
         Preconditions.checkArgument(object instanceof EndpointsObj, "Wrong instance of PCEPObject. Passed %s. Needed EndpointsObject.", object.getClass());
         final EndpointsObj ePObj = (EndpointsObj) object;
         final AddressFamily afi = ePObj.getAddressFamily();
index 3d99eda891a57c2eed4878af5f3eae8048817106..6b6d320e1e20842d079eb2f1f09fcda16df91b0a 100644 (file)
@@ -7,20 +7,49 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
+
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteArray;
+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.reoptimization.bandwidth.object.Bandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.BandwidthBuilder;
 
 /**
  * Parser for Bandwidth
  */
-public class PCEPExistingBandwidthObjectParser extends AbstractBandwidthParser {
+public class PCEPExistingBandwidthObjectParser implements ObjectParser, ObjectSerializer {
 
     public static final int CLASS = 5;
 
     public static final int TYPE = 2;
 
     @Override
-    protected void formatBandwidth(final Boolean processed, final Boolean ignored, final ByteBuf body, final ByteBuf buffer) {
-        ObjectUtil.formatSubobject(TYPE, CLASS, processed, ignored, body, buffer);
+    public Bandwidth parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
+        Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+        if (bytes.readableBytes() != PCEPBandwidthObjectParser.BANDWIDTH_F_LENGTH) {
+            throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: "
+                + PCEPBandwidthObjectParser.BANDWIDTH_F_LENGTH + ".");
+        }
+        final BandwidthBuilder builder = new BandwidthBuilder();
+        builder.setIgnore(header.isIgnore());
+        builder.setProcessingRule(header.isProcessingRule());
+        builder.setBandwidth(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(ByteArray.getAllBytes(bytes)));
+        return builder.build();
+    }
+
+    @Override
+    public void serializeObject(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object object, final ByteBuf buffer) {
+        Preconditions.checkArgument(object instanceof Bandwidth, "Wrong instance of PCEPObject. Passed " +
+            "%s. Needed ReoptimizationBandwidthObject.", object.getClass());
+        final ByteBuf body = Unpooled.buffer();
+        writeFloat32(((Bandwidth) object).getBandwidth(), body);
+        ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 }
index 3bce6644085322e8a418a181281d5625f7135721..910e7e5a6eb434fafa12b9112a1b1c06bf2c96f7 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.util.ByteArray;
@@ -28,7 +27,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 /**
  * Parser for {@link PathKey}
  */
-public class EROPathKey128SubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
+public class EROPathKey128SubobjectParser implements EROSubobjectParser {
 
     public static final int TYPE = 65;
 
@@ -54,8 +53,7 @@ public class EROPathKey128SubobjectParser implements EROSubobjectParser, EROSubo
         return builder.build();
     }
 
-    @Override
-    public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
+    public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
         Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
             .subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
index 92eab4898f6240fdc7ba593a64711b9fa675f00e..837bda93312829d607e80ec85d93d23573de0eb2 100644 (file)
@@ -61,9 +61,13 @@ public class EROPathKey32SubobjectParser implements EROSubobjectParser, EROSubob
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
             .subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
         final ByteBuf body = Unpooled.buffer();
+        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+        if(pk.getPceId().getBinary().length == 16) {
+            EROPathKey128SubobjectParser.serializeSubobject(subobject,buffer);
+        }
         Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
         writeUnsignedShort(pk.getPathKey().getValue(), body);
-        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+        Preconditions.checkArgument(pk.getPceId().getBinary().length == 4, "PceId 32 Bit required.");
         body.writeBytes(pk.getPceId().getBinary());
         EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
index 86a379f25953860ae2a9190462f270853079a1c5..05987614f178bb7335255d7cd5626bf0ecc3255e 100644 (file)
@@ -14,7 +14,6 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject;
@@ -25,7 +24,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.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
 
-public class RROPathKey128SubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
+public class RROPathKey128SubobjectParser implements RROSubobjectParser {
 
     public static final int TYPE = 65;
 
@@ -55,8 +54,7 @@ public class RROPathKey128SubobjectParser implements RROSubobjectParser, RROSubo
         return builder.build();
     }
 
-    @Override
-    public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
+    public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
         final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType();
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects
             .subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
index dc3c86782d1cd57358e538e3e8a5190d3efcbc5e..2ae9a2ba8dcd09c8815d22e009c4b7c2dbbb5bce 100644 (file)
@@ -61,9 +61,13 @@ public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubob
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects
             .subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
         final ByteBuf body = Unpooled.buffer();
+        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+        if(pk.getPceId().getBinary().length == 16) {
+            RROPathKey128SubobjectParser.serializeSubobject(subobject,buffer);
+        }
         Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
         writeUnsignedShort(pk.getPathKey().getValue(), body);
-        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+        Preconditions.checkArgument(pk.getPceId().getBinary().length == 4, "PceId 32 Bit required.");
         body.writeBytes(pk.getPceId().getBinary());
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
index 26d7bf39f23fed2b63d84e627e2554b28ab367f8..02d4b464bb90c13f05154e42902ae4a3ecbe719b 100644 (file)
@@ -14,7 +14,6 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
@@ -28,7 +27,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 /**
  * Parser for {@link PathKey}
  */
-public class XROPathKey128SubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
+public class XROPathKey128SubobjectParser implements XROSubobjectParser {
 
     public static final int TYPE = 65;
 
@@ -54,8 +53,7 @@ public class XROPathKey128SubobjectParser implements XROSubobjectParser, XROSubo
         return builder.build();
     }
 
-    @Override
-    public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
+    public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
         Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
             .subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
index 21f826dcb37228d1797c47e0efb4166265ca66d1..2f607f721b1a85aec60338a08b053c3e6a18a00f 100644 (file)
@@ -60,9 +60,13 @@ public class XROPathKey32SubobjectParser implements XROSubobjectParser, XROSubob
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
             .subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
         final ByteBuf body = Unpooled.buffer();
+        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+        if(pk.getPceId().getBinary().length == 16) {
+            XROPathKey128SubobjectParser.serializeSubobject(subobject,buffer);
+        }
         Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
         writeUnsignedShort(pk.getPathKey().getValue(), body);
-        Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+        Preconditions.checkArgument(pk.getPceId().getBinary().length == 4, "PceId 32 Bit required.");
         body.writeBytes(pk.getPceId().getBinary());
         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
     }
index 67ff60878b8bb263206af378d88c2eeaa95b3f63..89803d825fa3e533a5d22dbafd7f8fa5e38ca4fb 100644 (file)
@@ -409,7 +409,9 @@ public class PCEPObjectParserTest {
         final PCEPExistingBandwidthObjectParser parser = new PCEPExistingBandwidthObjectParser();
         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin"));
 
-        final BandwidthBuilder builder = new BandwidthBuilder();
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization
+            .bandwidth.object.BandwidthBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
+            .ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.BandwidthBuilder();
         builder.setProcessingRule(true);
         builder.setIgnore(true);
         builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));