BUG-47: introduce SPI component 99/1699/1
authorRobert Varga <rovarga@cisco.com>
Sun, 6 Oct 2013 16:40:50 +0000 (18:40 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 6 Oct 2013 22:54:09 +0000 (00:54 +0200)
Change-Id: Iccf495f5ef390f0e67ee75e04f31a5904ab60fca
Signed-off-by: Robert Varga <rovarga@cisco.com>
15 files changed:
pcep/impl/pom.xml
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/HandlerRegistryImpl.java [new file with mode: 0644]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageValidator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/RawPCEPMessageFactory.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java
pcep/pom.xml
pcep/spi/.project [new file with mode: 0644]
pcep/spi/pom.xml [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/HandlerRegistry.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageHandler.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHandler.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPMessageType.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageType.java with 71% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RawMessage.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRawMessage.java with 66% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvHandler.java [new file with mode: 0644]

index e902bf3bedf5e4171dba2f1c7ee3192f09398f34..e7a5e6dbc4f11c9f995e89cab7aaf4c679317311 100644 (file)
                        <artifactId>pcep-api</artifactId>
                        <version>${project.version}</version>
                </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>pcep-spi</artifactId>
+                       <version>${project.version}</version>
+               </dependency>
                <dependency>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>framework</artifactId>
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/HandlerRegistryImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/HandlerRegistryImpl.java
new file mode 100644 (file)
index 0000000..8163664
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ * 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;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.opendaylight.protocol.concepts.AbstractRegistration;
+import org.opendaylight.protocol.pcep.spi.HandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.MessageHandler;
+import org.opendaylight.protocol.pcep.spi.ObjectHandler;
+import org.opendaylight.protocol.pcep.spi.TlvHandler;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+
+import com.google.common.base.Preconditions;
+
+public class HandlerRegistryImpl implements HandlerRegistry {
+       public static final HandlerRegistry INSTANCE;
+
+       static {
+               final HandlerRegistry reg = new HandlerRegistryImpl();
+
+               // FIXME: fill this in
+
+               //              reg.registerMessageHandler(PCEPOpenMessage.class, 1, new PCEPOpenMessageParser());
+               //              reg.registerMessageHandler(PCEPNotificationMessage.class, 5, new PCEPNotificationMessageParser());
+               //              reg.registerMessageHandler(PCEPKeepAliveMessage.class, 2, new PCEPKeepAliveMessageParser());
+               //              reg.registerMessageHandler(PCEPReplyMessage.class, 4, new PCEPReplyMessageParser());
+               //              reg.registerMessageHandler(PCEPRequestMessage.class, 3, new PCEPRequestMessageParser());
+               //              reg.registerMessageHandler(PCEPErrorMessage.class, 6, new PCEPErrorMessageParser());
+               //              reg.registerMessageHandler(PCEPCloseMessage.class, 7, new PCEPCloseMessageParser());
+               //              reg.registerMessageHandler(PCEPUpdateRequestMessage.class, 11, new PCEPUpdateRequestMessageParser());
+               //              reg.registerMessageHandler(PCEPReportMessage.class, 10, new PCEPReportMessageParser());
+               //              reg.registerMessageHandler(PCCreateMessage.class, 12, new PCCreateMessageParser());
+
+               INSTANCE = reg;
+       }
+
+       private final Map<Integer, MessageHandler> msgHandlerInts = new HashMap<>();
+       private final Map<Class<? extends Message>, MessageHandler> msgHandlerClasses = new HashMap<>();
+
+       private final Map<Integer, ObjectHandler> objHandlerInts = new HashMap<>();
+       private final Map<Class<? extends Object>, ObjectHandler> objHandlerClasses = new HashMap<>();
+
+       private final Map<Integer, TlvHandler> tlvHandlerInts = new HashMap<>();
+       private final Map<Class<? extends Tlv>, TlvHandler> tlvHandlerClasses = new HashMap<>();
+
+       private HandlerRegistryImpl() {
+
+       }
+
+       @Override
+       public synchronized MessageHandler getMessageHandler(final int messageType) {
+               Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
+               return msgHandlerInts.get(messageType);
+       }
+
+       @Override
+       public synchronized MessageHandler getMessageHandler(final Message message) {
+               return msgHandlerClasses.get(message.getClass());
+       }
+
+       @Override
+       public synchronized ObjectHandler getObjectHandler(final int objectClass, final int objectType) {
+               Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255);
+               Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
+
+               return objHandlerInts.get((objectClass << 4) + objectType);
+       }
+
+       @Override
+       public synchronized ObjectHandler getObjectHandler(final Object object) {
+               return objHandlerClasses.get(object.getClass());
+       }
+
+       @Override
+       public synchronized TlvHandler getTlvHandler(final int tlvType) {
+               Preconditions.checkArgument(tlvType >= 0 && tlvType <= 65535);
+               return tlvHandlerInts.get(tlvType);
+       }
+
+       @Override
+       public synchronized TlvHandler getTlvHandler(final Tlv tlv) {
+               return tlvHandlerClasses.get(tlv.getClass());
+       }
+
+       private synchronized void unregisterMessageHandler(final Integer msgType, final Class<? extends Message> msgClass) {
+               msgHandlerInts.remove(msgType);
+               msgHandlerClasses.remove(msgClass);
+       }
+
+       @Override
+       public synchronized AutoCloseable registerMessageHandler(
+                       final Class<? extends Message> msgClass, final int msgType,
+                       final MessageHandler handler) {
+               Preconditions.checkArgument(msgType >= 0 && msgType <= 255);
+
+               Preconditions.checkArgument(!msgHandlerInts.containsKey(msgType), "Message type %s already registered", msgType);
+               Preconditions.checkArgument(!msgHandlerClasses.containsKey(msgClass), "Message class %s already registered", msgClass);
+
+               msgHandlerInts.put(msgType, handler);
+               msgHandlerClasses.put(msgClass, handler);
+
+               return new AbstractRegistration() {
+                       @Override
+                       protected void removeRegistration() {
+                               unregisterMessageHandler(msgType, msgClass);
+                       }
+               };
+       }
+
+       private synchronized void unregisterObjectHandler(final Integer key, final Class<? extends Object> objClass) {
+               objHandlerInts.remove(key);
+               objHandlerClasses.remove(objClass);
+       }
+
+       @Override
+       public synchronized AutoCloseable registerObjectHandler(
+                       final Class<? extends Object> objClass, final int objectClass, final int objectType,
+                       final ObjectHandler handler) {
+               Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255);
+               Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
+
+               final Integer key = (objectClass << 4) + objectType;
+               Preconditions.checkArgument(!objHandlerInts.containsKey(key), "Object class %s type %s already registered",
+                               objectClass, objectType);
+               Preconditions.checkArgument(!objHandlerClasses.containsKey(objectClass), "TLV class %s already registered", objectClass);
+
+               objHandlerInts.put(key, handler);
+               objHandlerClasses.put(objClass, handler);
+
+               return new AbstractRegistration() {
+                       @Override
+                       protected void removeRegistration() {
+                               unregisterObjectHandler(key, objClass);
+                       }
+               };
+       }
+
+       private synchronized void unregisterTlvHandler(final int tlvType, final Class<? extends Tlv> tlvClass) {
+               tlvHandlerInts.remove(tlvType);
+               tlvHandlerClasses.remove(tlvClass);
+       }
+
+       @Override
+       public synchronized AutoCloseable registerTlvHandler(final Class<? extends Tlv> tlvClass,
+                       final int tlvType, final TlvHandler handler) {
+               Preconditions.checkArgument(tlvType >= 0 && tlvType <= 65535);
+
+               Preconditions.checkArgument(!tlvHandlerInts.containsKey(tlvType), "TLV type %s already registered", tlvType);
+               Preconditions.checkArgument(!tlvHandlerClasses.containsKey(tlvClass), "TLV class %s already registered", tlvClass);
+
+               tlvHandlerInts.put(tlvType, handler);
+               tlvHandlerClasses.put(tlvClass, handler);
+
+               return new AbstractRegistration() {
+                       @Override
+                       protected void removeRegistration() {
+                               unregisterTlvHandler(tlvType, tlvClass);
+                       }
+               };
+       }
+}
index d27516aece197c5ff2912645d9b9e0fe91e2f6d2..10bc6ecc9d6b4038096f4b93ac6ab9d4f7ef9ed9 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.protocol.framework.DocumentedException;
 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPMessage;
-import org.opendaylight.protocol.pcep.impl.message.PCEPRawMessage;
+import org.opendaylight.protocol.pcep.spi.RawMessage;
 
 import com.google.common.base.Preconditions;
 
@@ -31,8 +31,8 @@ public final class PCEPMessageFactory implements ProtocolMessageFactory<PCEPMess
                final List<PCEPMessage> validated = new ArrayList<>(parsed.size());
 
                for (PCEPMessage msg : parsed) {
-                       Preconditions.checkState(msg instanceof PCEPRawMessage);
-                       final PCEPRawMessage raw = (PCEPRawMessage) msg;
+                       Preconditions.checkState(msg instanceof RawMessage);
+                       final RawMessage raw = (RawMessage) msg;
 
                        try {
                                validated.addAll(PCEPMessageValidator.getValidator(raw.getMsgType()).validate(raw.getAllObjects()));
index bc95fa69fbb40e050a39b1f45a5551cede5c36a2..c940bf80e4a1c2bcbf9e2efa7c31a490af548eb7 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageValidator;
 import org.opendaylight.protocol.pcep.impl.message.PCEPReportMessageValidator;
 import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageValidator;
 import org.opendaylight.protocol.pcep.impl.message.PCEPUpdateRequestMessageValidator;
+import org.opendaylight.protocol.pcep.spi.PCEPMessageType;
 
 /**
  * Base class for message validators
index 3f36cdc050fb6165ae8881184975e19927b9c541..09aef389a717b0d6b0a067e8dac1ac85eae3e4b0 100644 (file)
@@ -23,7 +23,6 @@ import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageParser;
 import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
 import org.opendaylight.protocol.pcep.impl.message.PCEPNotificationMessageParser;
 import org.opendaylight.protocol.pcep.impl.message.PCEPOpenMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPRawMessage;
 import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
 import org.opendaylight.protocol.pcep.impl.message.PCEPReportMessageParser;
 import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser;
@@ -38,6 +37,8 @@ import org.opendaylight.protocol.pcep.message.PCEPReplyMessage;
 import org.opendaylight.protocol.pcep.message.PCEPReportMessage;
 import org.opendaylight.protocol.pcep.message.PCEPRequestMessage;
 import org.opendaylight.protocol.pcep.message.PCEPUpdateRequestMessage;
+import org.opendaylight.protocol.pcep.spi.PCEPMessageType;
+import org.opendaylight.protocol.pcep.spi.RawMessage;
 import org.opendaylight.protocol.util.ByteArray;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -116,13 +117,7 @@ class RawPCEPMessageFactory implements ProtocolMessageFactory<PCEPMessage> {
                 * if PCEPObjectIdentifier.getObjectClassFromInt() dont't throws
                 * exception and if returned null we know the error type
                 */
-               PCEPMessageType msgType;
-               try {
-                       msgType = PCEPMessageType.getFromInt(type);
-               } catch (final PCEPDeserializerException e) {
-                       logger.debug("Failed to get message type from {}", type);
-                       throw new DeserializerException(e.getMessage(), e);
-               }
+               PCEPMessageType msgType = PCEPMessageType.getFromInt(type);
                if (msgType == null) {
                        logger.debug("Unknown message type {}", type);
                        throw new DocumentedException("Unhandled message type " + type, new PCEPDocumentedException("Unhandled message type " + type, PCEPErrors.CAPABILITY_NOT_SUPPORTED));
@@ -130,7 +125,7 @@ class RawPCEPMessageFactory implements ProtocolMessageFactory<PCEPMessage> {
 
                PCEPMessage msg;
                try {
-                       msg = new PCEPRawMessage(PCEPObjectFactory.parseObjects(msgBody), msgType);
+                       msg = new RawMessage(PCEPObjectFactory.parseObjects(msgBody), msgType);
                } catch (final PCEPDeserializerException e) {
                        logger.debug("Unexpected deserializer problem", e);
                        throw new DeserializerException(e.getMessage(), e);
index 63c0ab560b853a8b56249ecb67b1d213cdae5fed..2623335a9c6814b9c731c209faee488c34291fa1 100644 (file)
@@ -30,7 +30,6 @@ import org.opendaylight.protocol.pcep.PCEPObject;
 import org.opendaylight.protocol.pcep.PCEPTlv;
 import org.opendaylight.protocol.pcep.concepts.LSPSymbolicName;
 import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier;
-import org.opendaylight.protocol.pcep.impl.message.PCEPRawMessage;
 import org.opendaylight.protocol.pcep.impl.object.UnknownObject;
 import org.opendaylight.protocol.pcep.message.PCCreateMessage;
 import org.opendaylight.protocol.pcep.message.PCEPCloseMessage;
@@ -75,6 +74,8 @@ import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject;
 import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject;
 import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject;
 import org.opendaylight.protocol.pcep.object.PCEPSvecObject;
+import org.opendaylight.protocol.pcep.spi.PCEPMessageType;
+import org.opendaylight.protocol.pcep.spi.RawMessage;
 import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROUnnumberedInterfaceSubobject;
 import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject;
@@ -123,7 +124,7 @@ public class PCEPValidatorTest {
        private static List<PCEPMessage> deserMsg(final String srcFile) throws IOException, DeserializerException, DocumentedException,
                        PCEPDeserializerException {
                final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile);
-               final PCEPRawMessage rawMessage = (PCEPRawMessage) msgFactory.parse(bytesFromFile).get(0);
+               final RawMessage rawMessage = (RawMessage) msgFactory.parse(bytesFromFile).get(0);
 
                return PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects());
        }
@@ -641,7 +642,7 @@ public class PCEPValidatorTest {
                final byte[] bytes = msgFactory.put(msg);
 
                // FIXME: need construct with invalid processed parameter
-               final PCEPRawMessage rawMessage = (PCEPRawMessage) msgFactory.parse(bytes).get(0);
+               final RawMessage rawMessage = (RawMessage) msgFactory.parse(bytes).get(0);
 
                assertEquals(PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects()),
                                asList((PCEPMessage) msg));
index 9e04fc65c01d669ba5afd718d05d7fe5b6e4864b..8fd3c665bac8cf899c81cb67b8f058c01970f90e 100644 (file)
@@ -19,6 +19,7 @@
        <modules>
                <module>api</module>
                <module>impl</module>
+               <module>spi</module>
         <module>testtool</module>
     </modules>
 </project>
diff --git a/pcep/spi/.project b/pcep/spi/.project
new file mode 100644 (file)
index 0000000..b097022
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>pcep-spi</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.m2e.core.maven2Builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>org.eclipse.m2e.core.maven2Nature</nature>
+       </natures>
+</projectDescription>
diff --git a/pcep/spi/pom.xml b/pcep/spi/pom.xml
new file mode 100644 (file)
index 0000000..3bac3da
--- /dev/null
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+       <parent>
+               <groupId>org.opendaylight.bgpcep</groupId>
+               <artifactId>pcep-parent</artifactId>
+               <version>0.3.0-SNAPSHOT</version>
+       </parent>
+
+       <modelVersion>4.0.0</modelVersion>
+       <artifactId>pcep-spi</artifactId>
+       <description>PCE Protocol SPI</description>
+       <packaging>bundle</packaging>
+       <name>${project.artifactId}</name>
+       <prerequisites>
+               <maven>3.0.4</maven>
+       </prerequisites>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>concepts</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>pcep-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+                       <version>${slf4j.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>mockito-configuration</artifactId>
+            <version>${project.version}</version>
+                       <scope>test</scope>
+        </dependency>
+       </dependencies>
+
+       <build>
+        <plugins>
+           <plugin>
+               <groupId>org.apache.felix</groupId>
+               <artifactId>maven-bundle-plugin</artifactId>
+               <version>${maven.bundle.version}</version>
+               <extensions>true</extensions>
+               <configuration>
+                   <instructions>
+                       <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                       <Export-Package>
+                           org.opendaylight.protocol.pcep.spi,
+                       </Export-Package>
+                       <Import-Package>
+                           org.opendaylight.protocol.concepts,
+                           org.opendaylight.protocol.framework,
+                           org.opendaylight.protocol.util,
+                           com.google.common.*,
+                           javax.management,
+                           org.slf4j.*
+                       </Import-Package>
+                   </instructions>
+               </configuration>
+           </plugin>
+               </plugins>
+       </build>
+
+       <distributionManagement>
+               <site>
+                       <id>${project.artifactId}</id>
+                       <name>PCEP-SPI Module site</name>
+                       <url>${basedir}/target/site/${project.artifactId}</url>
+               </site>
+       </distributionManagement>
+
+</project>
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/HandlerRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/HandlerRegistry.java
new file mode 100644 (file)
index 0000000..7e07eb3
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+
+public interface HandlerRegistry {
+       public AutoCloseable registerMessageHandler(Class<? extends Message> msgClass, int messageType, MessageHandler handler);
+       public MessageHandler getMessageHandler(int messageType);
+       public MessageHandler getMessageHandler(Message message);
+
+       public AutoCloseable registerObjectHandler(Class<? extends Object> objClass, int objectClass, int objectType, ObjectHandler handler);
+       public ObjectHandler getObjectHandler(int objectClass, int objectType);
+       public ObjectHandler getObjectHandler(Object object);
+
+       public AutoCloseable registerTlvHandler(Class<? extends Tlv> tlvClass, int tlvType, TlvHandler handler);
+       public TlvHandler getTlvHandler(int tlvType);
+       public TlvHandler getTlvHandler(Tlv tlv);
+}
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageHandler.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageHandler.java
new file mode 100644 (file)
index 0000000..236d634
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * 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.spi;
+
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+
+public interface MessageHandler {
+       public Message messageFromBytes(ByteBuf bytes);
+       public ByteBuf bytesFromMessage(Message message);
+}
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHandler.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHandler.java
new file mode 100644 (file)
index 0000000..a8f7068
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * 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.spi;
+
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+
+public interface ObjectHandler {
+       public Object objectFromBytes(ByteBuf bytes);
+       public ByteBuf bytesFromObject(Object object);
+}
similarity index 71%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageType.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPMessageType.java
index 14c9697aeb21cdb9f3e9ca65e1efb856462c3bad..a9397ef2083ac1672d1c4cd23bd778ed8ec7cd47 100644 (file)
@@ -5,18 +5,21 @@
  * 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;
+package org.opendaylight.protocol.pcep.spi;
 
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Type identifier for {@link org.opendaylight.protocol.pcep.PCEPMessage PCEPMessage}
  */
+@Deprecated()
 public enum PCEPMessageType {
        OPEN(1), NOTIFICATION(5), KEEPALIVE(2), RESPONSE(4), REQUEST(3), ERROR(6), CLOSE(7), UPDATE_REQUEST(11), STATUS_REPORT(10),
        // TODO: replace with actual values by IANA
        PCCREATE(12);
 
+       private static final Logger logger = LoggerFactory.getLogger(PCEPMessageType.class);
        private final int identifier;
 
        PCEPMessageType(final int identifier) {
@@ -27,7 +30,7 @@ public enum PCEPMessageType {
                return this.identifier;
        }
 
-       public static PCEPMessageType getFromInt(final int type) throws PCEPDeserializerException {
+       public static PCEPMessageType getFromInt(final int type) {
 
                for (final PCEPMessageType type_e : PCEPMessageType.values()) {
                        if (type_e.getIdentifier() == type) {
@@ -35,7 +38,7 @@ public enum PCEPMessageType {
                        }
                }
 
-               throw new PCEPDeserializerException("Unknown PCEPMessage Class identifier. Passed: " + type + "; Known: "
-                               + PCEPMessageType.values() + ".");
+               logger.trace("Unknown PCEPMessage Class identifier. Passed: {}; Known: {}", type, values());
+               return null;
        }
 }
\ No newline at end of file
similarity index 66%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRawMessage.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RawMessage.java
index af00b1fd39b2c32dddd60c3e145e799ce4c579b7..abaa51b96634fb885a7a965613539b87225b893b 100644 (file)
@@ -5,24 +5,20 @@
  * 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.message;
+package org.opendaylight.protocol.pcep.spi;
 
 import java.util.List;
 
 import org.opendaylight.protocol.pcep.PCEPMessage;
 import org.opendaylight.protocol.pcep.PCEPObject;
-import org.opendaylight.protocol.pcep.impl.PCEPMessageType;
 
 /**
  * Class representing raw message.
  */
-public class PCEPRawMessage extends PCEPMessage {
-
-       private static final long serialVersionUID = 1075879993862417873L;
-
+public class RawMessage extends PCEPMessage {
        private final PCEPMessageType msgType;
 
-       public PCEPRawMessage(final List<PCEPObject> objects, final PCEPMessageType msgType) {
+       public RawMessage(final List<PCEPObject> objects, final PCEPMessageType msgType) {
                super(objects);
                this.msgType = msgType;
        }
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvHandler.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvHandler.java
new file mode 100644 (file)
index 0000000..cde1cc4
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * 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.spi;
+
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+
+public interface TlvHandler {
+       public Tlv tlvFromBytes(ByteBuf bytes);
+       public ByteBuf bytesFromTlv(Tlv tlv);
+}