BUG-50 : added parser for Pcreq message.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPEndPointsObjectParser.java
index 170bff9f6f30f7343ff8fbad41e9be05e1b9d982..8754c2e6484caa93daa424db25ef52149461207f 100644 (file)
@@ -10,7 +10,9 @@ package org.opendaylight.protocol.pcep.impl.object;
 import org.opendaylight.protocol.concepts.Ipv4Util;
 import org.opendaylight.protocol.concepts.Ipv6Util;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.PCEPErrors;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.UnknownObject;
 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;
@@ -22,12 +24,16 @@ 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.address.family.Ipv6Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObj;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Parser for IPv4 {@link EndpointsObj}
  */
 public class PCEPEndPointsObjectParser extends AbstractObjectWithTlvsParser<EndpointsObjBuilder> {
 
+       private static final Logger LOG = LoggerFactory.getLogger(PCEPEndPointsObjectParser.class);
+
        public static final int CLASS = 4;
        public static final int TYPE = 1;
 
@@ -54,16 +60,10 @@ public class PCEPEndPointsObjectParser extends AbstractObjectWithTlvsParser<Endp
        }
 
        @Override
-       public EndpointsObj parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
+       public Object parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
                if (bytes == null) {
                        throw new IllegalArgumentException("Array of bytes is mandatory");
                }
-
-               if (!header.isProcessingRule()) {
-                       //LOG.debug("Processed bit not set on ENDPOINTS OBJECT, ignoring it");
-                       return null;
-               }
-
                final EndpointsObjBuilder builder = new EndpointsObjBuilder();
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
@@ -81,6 +81,10 @@ public class PCEPEndPointsObjectParser extends AbstractObjectWithTlvsParser<Endp
                } else {
                        throw new PCEPDeserializerException("Wrong length of array of bytes.");
                }
+               if (!builder.isProcessingRule()) {
+                       LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
+                       return new UnknownObject(PCEPErrors.P_FLAG_NOT_SET, builder.build());
+               }
                return builder.build();
        }