<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>
--- /dev/null
+/*
+ * 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);
+ }
+ };
+ }
+}
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;
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()));
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
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;
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;
* 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));
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);
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;
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;
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());
}
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));
<modules>
<module>api</module>
<module>impl</module>
+ <module>spi</module>
<module>testtool</module>
</modules>
</project>
--- /dev/null
+<?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>
--- /dev/null
+<?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>
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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);
+}
* 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) {
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) {
}
}
- 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
* 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;
}
--- /dev/null
+/*
+ * 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);
+}