Bug-6242: PCRpt received with bandwidth reoptimization object leads to loop causing OOM 34/42434/2
authorAjay <ajayl.bro@gmail.com>
Mon, 25 Jul 2016 04:37:50 +0000 (04:37 +0000)
committerAjay L <ajayl.bro@gmail.com>
Tue, 26 Jul 2016 21:54:11 +0000 (21:54 +0000)
- added bandwidth reoptimization object to the list of possible objects in PCRpt message
- gracefully handle condition where unexpected object is present in received message
- updated unit-tests

Change-Id: Idfd2cf28b6b6385f67e6e81ea41a1904653c5ab5
Signed-off-by: Ajay <ajayl.bro@gmail.com>
pcep/api/src/main/yang/pcep-types.yang
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/BaseParserExtensionActivator.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/message/PCEPErrorMessageParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/message/PCEPReplyMessageParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/message/PCEPRequestMessageParser.java
pcep/base-parser/src/main/java/org/opendaylight/protocol/pcep/parser/object/PCEPExistingBandwidthObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07ErrorMessageParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07PCReportMessageParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07PCUpdateRequestMessageParser.java
pcep/ietf-stateful07/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPValidatorTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java

index e5c97f99a8c40dadb9375c0a6ef47c3f906f4bce..cc0bcddb1166e5aad8dc95ebd4fb5fe18b180eb1 100644 (file)
@@ -427,7 +427,7 @@ module pcep-types {
     grouping reoptimization-bandwidth-object {
         description "BANDWIDTH Object";
         reference "https://tools.ietf.org/html/rfc5440#section-7.7";
-        container bandwidth {
+        container reoptimization-bandwidth {
             uses object;
             uses bandwidth;
         }
@@ -946,6 +946,7 @@ module pcep-types {
         uses lspa-object;
 
         uses bandwidth-object;
+        uses reoptimization-bandwidth-object;
 
         list metrics {
             uses metric-object;
index 5f60154a598723727568c4ce07130e47b9ce55d6..81eb9da3557f5fe990c26a8eba5dc81b752bd783 100644 (file)
@@ -220,7 +220,7 @@ public final class BaseParserExtensionActivator extends AbstractPCEPExtensionPro
         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));
+            .pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth.class, bwExistingParser));
 
         final PCEPMetricObjectParser metricParser = new PCEPMetricObjectParser();
         regs.add(context.registerObjectParser(PCEPMetricObjectParser.CLASS, PCEPMetricObjectParser.TYPE, metricParser));
index 69e400a901e657bc8dfbecf3cf610e505463a269..64d000d216affa80ea5d85d762e692320b4209d2 100644 (file)
@@ -108,7 +108,7 @@ public class PCEPErrorMessageParser extends AbstractMessageParser {
             throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory.");
         }
         objects.remove(0);
-        while (!objects.isEmpty()) {
+        while (!objects.isEmpty() && !state.equals(State.END)) {
             obj = objects.get(0);
             if (obj instanceof UnknownObject) {
                 return new PcerrBuilder().setPcerrMessage(b.setErrors(((UnknownObject) obj).getErrors()).build()).build();
index 8e89fe8043acb10b3f1728057c42edabc8c9b370..f174296fbc91a7ab80f8cb872e41e730db38c791 100644 (file)
@@ -165,12 +165,12 @@ public class PCEPReplyMessageParser extends AbstractMessageParser {
     }
 
     protected Replies getValidReply(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
-        if (!(objects.get(0) instanceof Rp)) {
+        Object object = objects.remove(0);
+        if (!(object instanceof Rp)) {
             errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.<Rp>absent()));
             return null;
         }
-        final Rp rp = (Rp) objects.get(0);
-        objects.remove(0);
+        final Rp rp = (Rp) object;
         final RepliesBuilder repliesBuilder = new RepliesBuilder();
         if (!objects.isEmpty() && objects.get(0) instanceof Monitoring) {
             repliesBuilder.setMonitoring((Monitoring) objects.get(0));
index edb5f3b44d9f7a6597a4afc1d8b92c805368db4d..259829168dfc64a60a4042188068fbd1434e2f09 100644 (file)
@@ -124,7 +124,7 @@ public class PCEPRequestMessageParser extends AbstractMessageParser {
             final ReportedRoute rr = p2p.getReportedRoute();
             if (rr != null) {
                 serializeObject(rr.getRro(), buffer);
-                serializeObject(rr.getBandwidth(), buffer);
+                serializeObject(rr.getReoptimizationBandwidth(), buffer);
             }
         }
         serializeObject(p2p.getLoadBalancing(), buffer);
@@ -262,7 +262,7 @@ public class PCEPRequestMessageParser extends AbstractMessageParser {
 
         if (rp.isReoptimization()
                 && builder.getBandwidth() != null
-                && !builder.getReportedRoute().getBandwidth().getBandwidth().equals(
+                && !builder.getReportedRoute().getReoptimizationBandwidth().getBandwidth().equals(
                         new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 }))
                 && builder.getReportedRoute().getRro() == null) {
             errors.add(createErrorMsg(PCEPErrors.RRO_MISSING, Optional.of(rp)));
@@ -280,8 +280,8 @@ public class PCEPRequestMessageParser extends AbstractMessageParser {
                 rrBuilder.setRro((Rro) obj);
                 objects.remove(0);
                 final Object nextObj = objects.get(0);
-                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);
+                if (nextObj instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) {
+                    rrBuilder.setReoptimizationBandwidth((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) nextObj);
                 }
                 return State.REPORTED_IN;
             }
index 12daa6c496f861c0a10d961a4c64bd73a442bb7f..2f2b182993f811d006992a4fea32c1831b522938 100644 (file)
@@ -18,8 +18,8 @@ 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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder;
 
 /**
  * Parser for Bandwidth
@@ -31,13 +31,13 @@ public class PCEPExistingBandwidthObjectParser implements ObjectParser, ObjectSe
     public static final int TYPE = 2;
 
     @Override
-    public Bandwidth parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
+    public ReoptimizationBandwidth 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();
+        final ReoptimizationBandwidthBuilder builder = new ReoptimizationBandwidthBuilder();
         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)));
@@ -46,10 +46,10 @@ public class PCEPExistingBandwidthObjectParser implements ObjectParser, ObjectSe
 
     @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 " +
+        Preconditions.checkArgument(object instanceof ReoptimizationBandwidth, "Wrong instance of PCEPObject. Passed " +
             "%s. Needed ReoptimizationBandwidthObject.", object.getClass());
         final ByteBuf body = Unpooled.buffer();
-        writeFloat32(((Bandwidth) object).getBandwidth(), body);
+        writeFloat32(((ReoptimizationBandwidth) object).getBandwidth(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
 }
index 12a3d0c17d26bc209fdcdbd1a1a4c112e77edac0..48ae2a56759ff78683fd9de5cd91c5efd209e665 100644 (file)
@@ -98,7 +98,7 @@ public final class Stateful07ErrorMessageParser extends PCEPErrorMessageParser {
         if (!state.equals(State.INIT)) {
             objects.remove(0);
         }
-        while (!objects.isEmpty()) {
+        while (!objects.isEmpty() && !state.equals(State.END)) {
             obj = objects.get(0);
             if (obj instanceof UnknownObject) {
                 return new PcerrBuilder().setPcerrMessage(b.setErrors(((UnknownObject) obj).getErrors()).build()).build();
index 4d047c9bb0173fcb42bb50f70f0d5a8e1219b01b..60d3744e62d1a9d578e2c306f044b5a7ba4869a5 100644 (file)
@@ -74,6 +74,7 @@ public class Stateful07PCReportMessageParser extends AbstractMessageParser {
             serializeObject(p.getEro(), buffer);
             serializeObject(p.getLspa(), buffer);
             serializeObject(p.getBandwidth(), buffer);
+            serializeObject(p.getReoptimizationBandwidth(), buffer);
             if (p.getMetrics() != null) {
                 for (final Metrics m : p.getMetrics()) {
                     serializeObject(m.getMetric(), buffer);
@@ -114,17 +115,16 @@ public class Stateful07PCReportMessageParser extends AbstractMessageParser {
                 lspViaSR = PSTUtil.isDefaultPST(tlvs.getPathSetupType());
             }
             builder.setSrp(srp);
-            if(objects.isEmpty()) {
+            if (objects.isEmpty()) {
                 object = null;
             } else {
                 object = objects.remove(0);
             }
         }
 
-        if(validateLsp(object, lspViaSR, errors, builder)) {
-            if(!objects.isEmpty()) {
-                object = objects.remove(0);
-                if(!validateEmpty(object, objects, errors, builder)) {
+        if (validateLsp(object, lspViaSR, errors, builder)) {
+            if (!objects.isEmpty()) {
+                if (!validatePath(objects, errors, builder)) {
                     return null;
                 }
             }
@@ -134,24 +134,11 @@ public class Stateful07PCReportMessageParser extends AbstractMessageParser {
         return null;
     }
 
-    private boolean validateEmpty(final Object object, final List<Object> objects, final List<Message> errors, final ReportsBuilder builder) {
-        final PathBuilder pBuilder = new PathBuilder();
-        if (object instanceof Ero) {
-            pBuilder.setEro((Ero) object);
-        } else {
-            errors.add(createErrorMsg(PCEPErrors.ERO_MISSING, Optional.<Rp>absent()));
-            return false;
-        }
-        parsePath(objects, pBuilder);
-        builder.setPath(pBuilder.build());
-        return true;
-    }
-
     private boolean validateLsp(final Object object, final boolean lspViaSR, final List<Message> errors, final ReportsBuilder builder) {
         if (object instanceof Lsp) {
             final Lsp lsp = (Lsp) object;
             final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.Tlvs tlvs = lsp.getTlvs();
-            if(!lspViaSR && lsp.getPlspId().getValue() != 0 && (tlvs == null || tlvs.getLspIdentifiers() == null)) {
+            if (!lspViaSR && lsp.getPlspId().getValue() != 0 && (tlvs == null || tlvs.getLspIdentifiers() == null)) {
                 final Message errorMsg = createErrorMsg(PCEPErrors.LSP_IDENTIFIERS_TLV_MISSING, Optional.<Rp>absent());
                 errors.add(errorMsg);
                 return false;
@@ -165,6 +152,20 @@ public class Stateful07PCReportMessageParser extends AbstractMessageParser {
         return true;
     }
 
+    private boolean validatePath(final List<Object> objects, final List<Message> errors, final ReportsBuilder builder) {
+        final PathBuilder pBuilder = new PathBuilder();
+        Object object = objects.remove(0);
+        if (object instanceof Ero) {
+            pBuilder.setEro((Ero) object);
+        } else {
+            errors.add(createErrorMsg(PCEPErrors.ERO_MISSING, Optional.<Rp>absent()));
+            return false;
+        }
+        parsePath(objects, pBuilder);
+        builder.setPath(pBuilder.build());
+        return true;
+    }
+
     private void parsePath(final List<Object> objects, final PathBuilder builder) {
         final List<Metrics> pathMetrics = Lists.newArrayList();
         Object obj;
@@ -191,7 +192,11 @@ public class Stateful07PCReportMessageParser extends AbstractMessageParser {
         case LSPA_IN:
             if (obj instanceof Bandwidth) {
                 builder.setBandwidth((Bandwidth) obj);
-                return State.BANDWIDTH_IN;
+                return State.LSPA_IN;
+            }
+            if (obj instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) {
+                builder.setReoptimizationBandwidth((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) obj);
+                return State.LSPA_IN;
             }
         case BANDWIDTH_IN:
             if (obj instanceof Metric) {
index 57cc3e02d049326a247bf3eecb2e355606f69126..dcb250a5d62a3848fa307714d7365163129a1219 100644 (file)
@@ -69,6 +69,7 @@ public class Stateful07PCUpdateRequestMessageParser extends AbstractMessageParse
             serializeObject(p.getEro(), buffer);
             serializeObject(p.getLspa(), buffer);
             serializeObject(p.getBandwidth(), buffer);
+            serializeObject(p.getReoptimizationBandwidth(), buffer);
             if (p.getMetrics() != null) {
                 for (final Metrics m : p.getMetrics()) {
                     serializeObject(m.getMetric(), buffer);
@@ -89,7 +90,7 @@ public class Stateful07PCUpdateRequestMessageParser extends AbstractMessageParse
 
         while (!objects.isEmpty()) {
             final Updates upd = getValidUpdates(objects, errors);
-            if(upd != null) {
+            if (upd != null) {
                 updateRequests.add(upd);
             }
         }
@@ -100,40 +101,56 @@ public class Stateful07PCUpdateRequestMessageParser extends AbstractMessageParse
     }
 
     protected Updates getValidUpdates(final List<Object> objects, final List<Message> errors) {
-        boolean isValid = true;
         final UpdatesBuilder builder = new UpdatesBuilder();
-        if (objects.get(0) instanceof Srp) {
-            builder.setSrp((Srp) objects.get(0));
-            objects.remove(0);
+
+        Object object = objects.remove(0);
+        if (object instanceof Srp) {
+            builder.setSrp((Srp) object);
+            if (objects.isEmpty()) {
+                object = null;
+            } else {
+                object = objects.remove(0);
+            }
         } else {
             errors.add(createErrorMsg(PCEPErrors.SRP_MISSING, Optional.<Rp>absent()));
-            isValid = false;
         }
-        if (objects.get(0) instanceof Lsp) {
-            builder.setLsp((Lsp) objects.get(0));
-            objects.remove(0);
-        } else {
-            errors.add(createErrorMsg(PCEPErrors.LSP_MISSING, Optional.<Rp>absent()));
-            isValid = false;
-        }
-        if (!objects.isEmpty()) {
-            final PathBuilder pBuilder = new PathBuilder();
-            if (objects.get(0) instanceof Ero) {
-                pBuilder.setEro((Ero) objects.get(0));
-                objects.remove(0);
-            } else {
-                errors.add(createErrorMsg(PCEPErrors.ERO_MISSING, Optional.<Rp>absent()));
-                isValid = false;
+
+        if (validateLsp(object, errors, builder)) {
+            if (!objects.isEmpty()) {
+                if (!validatePath(objects, errors, builder)) {
+                    return null;
+                }
             }
-            parsePath(objects, pBuilder);
-            builder.setPath(pBuilder.build());
-        }
-        if(isValid) {
+
             return builder.build();
         }
         return null;
     }
 
+    private boolean validateLsp(final Object object, final List<Message> errors, final UpdatesBuilder builder) {
+        if (object instanceof Lsp) {
+            builder.setLsp((Lsp) object);
+        } else {
+            errors.add(createErrorMsg(PCEPErrors.LSP_MISSING, Optional.<Rp>absent()));
+            return false;
+        }
+        return true;
+    }
+
+    private boolean validatePath(final List<Object> objects, final List<Message> errors, final UpdatesBuilder builder) {
+        final PathBuilder pBuilder = new PathBuilder();
+        Object object = objects.remove(0);
+        if (object instanceof Ero) {
+            pBuilder.setEro((Ero) object);
+        } else {
+            errors.add(createErrorMsg(PCEPErrors.ERO_MISSING, Optional.<Rp>absent()));
+            return false;
+        }
+        parsePath(objects, pBuilder);
+        builder.setPath(pBuilder.build());
+        return true;
+    }
+
     private void parsePath(final List<Object> objects, final PathBuilder pBuilder) {
         final List<Metrics> pathMetrics = Lists.newArrayList();
         Object obj;
@@ -160,7 +177,11 @@ public class Stateful07PCUpdateRequestMessageParser extends AbstractMessageParse
         case LSPA_IN:
             if (obj instanceof Bandwidth) {
                 pBuilder.setBandwidth((Bandwidth) obj);
-                return State.BANDWIDTH_IN;
+                return State.LSPA_IN;
+            }
+            if (obj instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) {
+                pBuilder.setReoptimizationBandwidth((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) obj);
+                return State.LSPA_IN;
             }
         case BANDWIDTH_IN:
             if (obj instanceof Metric) {
index 7ee87f3c505ed131727b93b4ee917f06d7246bec..3ebc0130d5944b0bf95a5bd62d02896cb1b7a669 100644 (file)
@@ -10,11 +10,14 @@ package org.opendaylight.protocol.pcep.ietf;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+
 import com.google.common.collect.Lists;
+import com.google.common.primitives.Bytes;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import org.junit.Before;
@@ -33,6 +36,7 @@ import org.opendaylight.protocol.pcep.sync.optimizations.SyncOptimizationsActiva
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Lsp1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Lsp1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.PcinitiateBuilder;
@@ -120,6 +124,8 @@ public class PCEPValidatorTest {
     private Srp srp;
     private Lsp lsp;
     private Lsp lspSrp;
+    private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth bandwidth;
+    private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth reoptimizationBandwidth;
 
     private AsNumberCase eroASSubobject;
     private UnnumberedCase rroUnnumberedSub;
@@ -159,6 +165,31 @@ public class PCEPValidatorTest {
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
     };
 
+    private static final byte[] PCRT3 = {
+        (byte) 0x20, (byte) 0x0A, (byte) 0x00, (byte) 0x4C,
+
+        (byte) 0x20, (byte) 0x10, (byte) 0x00, (byte) 0x1C, //(byte) 0x39,
+        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, //Skip
+        (byte) 0x00, (byte) 0x12, (byte) 0x00, (byte) 0x10, //TLV Type + TLV Length
+        (byte) 0x7F, (byte) 0x00, (byte) 0x01, (byte) 0x01, //TLV 127.0.1.1
+        (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, //TLV LSP Id + Tunnel id
+        (byte) 0x7F, (byte) 0x00, (byte) 0x01, (byte) 0x02, //TLV Ipv4ExtendedTunnelId 127.0.1.2
+        (byte) 0x7F, (byte) 0x00, (byte) 0x01, (byte) 0x03, //TLV TunnelEndpointAddress 127.0.1.3
+
+        (byte) 0x07, (byte) 0x10, (byte) 0x00, (byte) 0x08,
+        (byte) 0x20, (byte) 0x04, (byte) 0xFF, (byte) 0xFF,
+        (byte) 0x09, (byte) 0x10, (byte) 0x00, (byte) 0x14,
+        (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,
+
+        (byte) 0x05, (byte) 0x10, (byte) 0x00, (byte) 0x08,
+        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+        (byte) 0x05, (byte) 0x20, (byte) 0x00, (byte) 0x08,
+        (byte) 0x47, (byte) 0x74, (byte) 0x24, (byte) 0x00
+    };
+
     @Before
     public void setUp() throws Exception {
         this.ctx = new SimplePCEPExtensionProviderContext();
@@ -253,6 +284,18 @@ public class PCEPValidatorTest {
         final Ipv4Builder afi = new Ipv4Builder();
         afi.setSourceIpv4Address(new Ipv4Address("255.255.255.255"));
         afi.setDestinationIpv4Address(new Ipv4Address("255.255.255.255"));
+
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder bandwidthBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder();
+        bandwidthBuilder.setIgnore(false);
+        bandwidthBuilder.setProcessingRule(false);
+        bandwidthBuilder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
+        this.bandwidth = bandwidthBuilder.build();
+
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder reoptimizationBandwidthBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder();
+        reoptimizationBandwidthBuilder.setIgnore(false);
+        reoptimizationBandwidthBuilder.setProcessingRule(false);
+        reoptimizationBandwidthBuilder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x47, (byte) 0x74, (byte) 0x24, (byte) 0x00 }));
+        this.reoptimizationBandwidth = reoptimizationBandwidthBuilder.build();
     }
 
     @Test
@@ -400,6 +443,20 @@ public class PCEPValidatorTest {
             buf = Unpooled.buffer(result.readableBytes());
             parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
             assertArrayEquals(result.array(), buf.array());
+
+            result = Unpooled.wrappedBuffer(PCRT3);
+
+            final List<Reports> reports4 = Lists.newArrayList();
+            reports4.add(new ReportsBuilder().setLsp(this.lsp).setPath(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.PathBuilder().setEro(
+                    this.ero).setLspa(this.lspa).setBandwidth(this.bandwidth).setReoptimizationBandwidth(this.reoptimizationBandwidth).build()).build());
+            builder.setReports(reports4);
+
+            final ByteBuf input2 = result.slice(4, result.readableBytes() - 4);
+            assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(input2, Collections.emptyList()));
+            buf = Unpooled.buffer(result.readableBytes());
+            parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
+            assertArrayEquals(result.array(), buf.array());
         }
     }
 
@@ -526,30 +583,84 @@ public class PCEPValidatorTest {
     @Test
     public void testMissingLspObjectErrorInPcRptMsg() throws PCEPDeserializerException {
         final byte[] statefulMsg= {
-            0x20,0x0B,0x00,0x1C,
+            (byte) 0x20, (byte) 0x0B, (byte) 0x00, (byte) 0x1C,
             /* srp-object */
-            0x21,0x10,0x00,0x0C,
-            0x00,0x00,0x00,0x001,
-            0x00,0x00,0x00,0x01,
+            (byte) 0x21, (byte) 0x10, (byte) 0x00, (byte) 0x0C,
+            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x001,
+            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
             /* lsp-object is missing*/
             /* sr-ero-object */
-            0x07,0x10,0x00,0x0C,
+            (byte) 0x07, (byte) 0x10, (byte) 0x00, (byte) 0x0C,
             /* ipv4 prefix subobject */
-            (byte) 0x81,0x08,(byte) 0xFF,(byte) 0xFF,
-            (byte) 0xFF,(byte) 0xFF,0x16,0x00};
-
-        final Stateful07PCReportMessageParser parser = new Stateful07PCReportMessageParser(this.ctx.getObjectHandlerRegistry());
-
-        final PcerrMessageBuilder errMsgBuilder = new PcerrMessageBuilder();
-        errMsgBuilder.setErrors(Lists.newArrayList(new ErrorsBuilder().setErrorObject(
-            new ErrorObjectBuilder().setType((short) 6).setValue((short) 8).build()).build()));
-        final PcerrBuilder builder = new PcerrBuilder();
-        builder.setPcerrMessage(errMsgBuilder.build());
-
-        final ByteBuf buf = Unpooled.wrappedBuffer(statefulMsg);
-        final List<Message> errors = Lists.newArrayList();
-        parser.parseMessage(buf.slice(4, buf.readableBytes() - 4), errors);
-        assertFalse(errors.isEmpty());
-        assertEquals(builder.build(), errors.get(0));
+            (byte) 0x81, (byte) 0x08, (byte) 0xFF, (byte) 0xFF,
+            (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00
+        };
+
+        try (CrabbeInitiatedActivator a = new CrabbeInitiatedActivator();
+                StatefulActivator b = new StatefulActivator()) {
+            a.start(this.ctx);
+            b.start(this.ctx);
+            final Stateful07PCReportMessageParser parser = new Stateful07PCReportMessageParser(
+                    this.ctx.getObjectHandlerRegistry());
+
+            final PcerrMessageBuilder errMsgBuilder = new PcerrMessageBuilder();
+            errMsgBuilder.setErrors(Lists.newArrayList(new ErrorsBuilder()
+                    .setErrorObject(new ErrorObjectBuilder().setType((short) 6).setValue((short) 8).build()).build()));
+            final PcerrBuilder builder = new PcerrBuilder();
+            builder.setPcerrMessage(errMsgBuilder.build());
+
+            final ByteBuf buf = Unpooled.wrappedBuffer(statefulMsg);
+            final List<Message> errors = Lists.newArrayList();
+            parser.parseMessage(buf.slice(4, buf.readableBytes() - 4), errors);
+            assertFalse(errors.isEmpty());
+            assertEquals(builder.build(), errors.get(0));
+        }
+    }
+
+    @Test
+    public void testUnexpectedRroObjectInPcUpdMsg() throws PCEPDeserializerException {
+        final byte[] badUpdateMsg = {
+            (byte) 0x20, (byte) 0x0b, (byte) 0x00, (byte) 0x50,
+            /* SRP, LSP and ERO objects */
+            (byte) 0x21, (byte) 0x12, (byte) 0x00, (byte) 0x0c,
+            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+            (byte) 0x20, (byte) 0x10, (byte) 0x00, (byte) 0x08,
+            (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x09,
+            (byte) 0x07, (byte) 0x10, (byte) 0x00, (byte) 0x14,
+            (byte) 0x01, (byte) 0x08, (byte) 0x05, (byte) 0x05,
+            (byte) 0x05, (byte) 0x03, (byte) 0x18, (byte) 0x00,
+            (byte) 0x01, (byte) 0x08, (byte) 0x08, (byte) 0x08,
+            (byte) 0x08, (byte) 0x04, (byte) 0x18, (byte) 0x00,
+            /* RRO object */
+            (byte) 0x08, (byte) 0x10, (byte) 0x00, (byte) 0x24,
+            (byte) 0x01, (byte) 0x08, (byte) 0x0a, (byte) 0x00,
+            (byte) 0x00, (byte) 0x83, (byte) 0x20, (byte) 0x20,
+            (byte) 0x03, (byte) 0x08, (byte) 0x01, (byte) 0x01,
+            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+            (byte) 0x01, (byte) 0x08, (byte) 0x0a, (byte) 0x00,
+            (byte) 0x09, (byte) 0xde, (byte) 0x20, (byte) 0x00,
+            (byte) 0x03, (byte) 0x08, (byte) 0x01, (byte) 0x01,
+            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
+        };
+
+        try (CrabbeInitiatedActivator a = new CrabbeInitiatedActivator()) {
+            a.start(this.ctx);
+
+            final Stateful07PCUpdateRequestMessageParser parser = new Stateful07PCUpdateRequestMessageParser(
+                    this.ctx.getObjectHandlerRegistry());
+
+            final PcerrMessageBuilder errMsgBuilder = new PcerrMessageBuilder();
+            errMsgBuilder.setErrors(Lists.newArrayList(new ErrorsBuilder()
+                    .setErrorObject(new ErrorObjectBuilder().setType((short) 6).setValue((short) 10).build()).build()));
+            final PcerrBuilder builder = new PcerrBuilder();
+            builder.setPcerrMessage(errMsgBuilder.build());
+
+            final ByteBuf buf = Unpooled.wrappedBuffer(badUpdateMsg);
+            final List<Message> errors = Lists.newArrayList();
+            parser.parseMessage(buf.slice(4, buf.readableBytes() - 4), errors);
+            assertFalse(errors.isEmpty());
+            assertEquals(builder.build(), errors.get(0));
+        }
     }
 }
index a5c94e5a9e97134bdc718117085f5db26897c2d7..43ff056218d998a312384313bcb535bde5de8c2a 100644 (file)
@@ -411,8 +411,8 @@ public class PCEPObjectParserTest {
         final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin"));
 
         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();
+            .bandwidth.object.ReoptimizationBandwidthBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
+            .ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder();
         builder.setProcessingRule(true);
         builder.setIgnore(true);
         builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));