Bug 187 - PCEP: object parser - report correctly unknown objects 23/6723/2
authorMilos Fabian <milfabia@cisco.com>
Mon, 5 May 2014 14:59:28 +0000 (16:59 +0200)
committerMilos Fabian <milfabia@cisco.com>
Tue, 6 May 2014 08:29:59 +0000 (10:29 +0200)
-differs between unknown object-class and object-type, returns proper error

Change-Id: I04c5f274294793776c84c4de8875e22d71b9a650
Signed-off-by: Milos Fabian <milfabia@cisco.com>
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleObjectRegistry.java

index 945b68cc5fb3422bceba084c3e18df536ed8a458..9cfd4da7c18c0a18c7c0a62a4159e03dc8af0807 100644 (file)
@@ -9,6 +9,9 @@ package org.opendaylight.protocol.pcep.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
 import java.util.List;
@@ -41,7 +44,9 @@ import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectPars
 import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.PCEPErrors;
 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
+import org.opendaylight.protocol.pcep.spi.UnknownObject;
 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
@@ -617,4 +622,26 @@ public class PCEPObjectParserTest {
                assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), ByteArray.cutBytes(result, 4)));
                assertArrayEquals(result, parser.serializeObject(builder.build()));
        }
+
+       @Test
+       public void testIgnoreUknownObject() throws PCEPDeserializerException {
+           final Object object = ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(false, false), null);
+           assertNull(object);
+       }
+
+       @Test
+       public void testUnrecognizedObjectType() throws PCEPDeserializerException {
+           final Object object = ctx.getObjectHandlerRegistry().parseObject(2, 2, new ObjectHeaderImpl(true, true), null);
+           assertNotNull(object);
+           assertTrue(object instanceof UnknownObject);
+           assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_TYPE, ((UnknownObject) object).getError());
+       }
+
+       @Test
+       public void testUnrecognizedObjectClass() throws PCEPDeserializerException {
+           final Object object = ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(true, true), null);
+           assertNotNull(object);
+           assertTrue(object instanceof UnknownObject);
+           assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_CLASS, ((UnknownObject) object).getError());
+       }
 }
index d624f10e2f1be612d96a0cc731587328c40a2687..b5950f0be6a8888d14e4282c3c2431fe31ebe9de 100644 (file)
@@ -53,15 +53,13 @@ public final class SimpleObjectRegistry implements ObjectRegistry {
                        return null;
                    }
 
-                       final boolean foundClass = false;
-
-                       // FIXME: BUG-187: search the parsers, check classes
-
-                       if (!foundClass) {
-                               return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
-                       } else {
-                               return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
+                       for (int type = 1; type <= 15; type++) {
+                           final ObjectParser objParser = this.handlers.getParser(createKey(objectClass, type));
+                           if(objParser != null) {
+                               return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
+                           }
                        }
+                       return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
                }
                return parser.parseObject(header, buffer);
        }