BUG-47: introduce Label handlers 07/1907/2
authorRobert Varga <rovarga@cisco.com>
Tue, 15 Oct 2013 14:42:24 +0000 (16:42 +0200)
committerRobert Varga <rovarga@cisco.com>
Tue, 15 Oct 2013 14:43:09 +0000 (16:43 +0200)
Change-Id: I61ba0a34d3f7c28f2487639f93f466c6c8f7a80c
Signed-off-by: Robert Varga <rovarga@cisco.com>
pcep/api/src/main/yang/rsvp.yang
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleLabelHandlerRegistry.java [new file with mode: 0644]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleMessageHandlerRegistry.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleMessageHandlerFactory.java with 95% similarity]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SingletonPCEPProviderContext.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelHandlerRegistry.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelParser.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelSerializer.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPProviderContext.java

index 989ef60faca00743fe6a0c5fc3b836f091bac736..672fdf54b896aa50173d1472719e605b631fabb6 100644 (file)
@@ -130,9 +130,14 @@ module rsvp {
                }
        }
 
+       // Marker
+       grouping c-label;
+
        grouping type1-label {
                reference "https://tools.ietf.org/html/rfc3209#section-4.1";
 
+               uses c-label;
+
                leaf type1-label {
                        type uint32;
                        mandatory true;
@@ -142,6 +147,8 @@ module rsvp {
        grouping generalized-label {
                reference "https://tools.ietf.org/html/rfc3473#section-2.3";
 
+               uses c-label;
+
                leaf generalized-label {
                        type binary;
                        mandatory true;
@@ -151,6 +158,8 @@ module rsvp {
        grouping waveband-switching-label {
                reference "https://tools.ietf.org/html/rfc3473#section-2.4";
 
+               uses c-label;
+
                leaf end-label {
                        type uint32;
                        mandatory true;
@@ -197,6 +206,8 @@ module rsvp {
        grouping generalized-channel-set-label {
                reference "https://tools.ietf.org/html/rfc6002#section-3.2";
 
+               uses c-label;
+
                list subobjects {
                        uses label-set;
                }
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleLabelHandlerRegistry.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleLabelHandlerRegistry.java
new file mode 100644 (file)
index 0000000..1d34690
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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 org.opendaylight.protocol.concepts.HandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.LabelParser;
+import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+
+import com.google.common.base.Preconditions;
+
+public class SimpleLabelHandlerRegistry implements LabelHandlerRegistry {
+       private final HandlerRegistry<DataContainer, LabelParser, LabelSerializer> handlers = new HandlerRegistry<>();
+
+       @Override
+       public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
+               Preconditions.checkArgument(cType >= 0 && cType <= 255);
+               return handlers.registerParser(cType, parser);
+       }
+
+       @Override
+       public LabelParser getLabelParser(final int cType) {
+               Preconditions.checkArgument(cType >= 0 && cType <= 255);
+               return handlers.getParser(cType);
+       }
+
+       @Override
+       public AutoCloseable registerLabelSerializer(final Class<? extends CLabel> labelClass, final LabelSerializer serializer) {
+               return handlers.registerSerializer(labelClass, serializer);
+       }
+
+       @Override
+       public LabelSerializer getLabelSerializer(final CLabel label) {
+               return handlers.getSerializer(label.getImplementedInterface());
+       }
+}
similarity index 95%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleMessageHandlerFactory.java
rename to pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleMessageHandlerRegistry.java
index 234cfdd12ca15c46ca8c174b86fa0fd1196f7ec5..e73f3bc20065669de87c370a2832241af049a764 100644 (file)
@@ -19,7 +19,7 @@ import com.google.common.base.Preconditions;
 /**
  *
  */
-public final class SimpleMessageHandlerFactory implements MessageHandlerRegistry {
+public final class SimpleMessageHandlerRegistry implements MessageHandlerRegistry {
        private final HandlerRegistry<DataContainer, MessageParser, MessageSerializer> handlers = new HandlerRegistry<>();
 
        @Override
index f2e6bb2821eb7098dda494f552bc7ec3e4d47c6c..f9992c80ba482810ffcfa25bd00e35feb94b0e3d 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.impl;
 
 import javax.annotation.concurrent.ThreadSafe;
 
+import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.PCEPProviderContext;
@@ -24,7 +25,8 @@ public final class SingletonPCEPProviderContext implements PCEPProviderContext {
                private static final PCEPProviderContext INSTANCE = new SingletonPCEPProviderContext();
        }
 
-       private final MessageHandlerRegistry msgReg = new SimpleMessageHandlerFactory();
+       private final LabelHandlerRegistry labelReg = new SimpleLabelHandlerRegistry();
+       private final MessageHandlerRegistry msgReg = new SimpleMessageHandlerRegistry();
        private final ObjectHandlerRegistry objReg = new SimpleObjectHandlerRegistry();
        private final SubobjectHandlerRegistry subobjReg =  new SimpleSubobjectHandlerFactory();
        private final TlvHandlerRegistry tlvReg = new SimpleTlvHandlerRegistry();
@@ -37,6 +39,11 @@ public final class SingletonPCEPProviderContext implements PCEPProviderContext {
                return Holder.INSTANCE;
        }
 
+       @Override
+       public LabelHandlerRegistry getHandlerRegistry() {
+               return labelReg;
+       }
+
        @Override
        public MessageHandlerRegistry getMessageHandlerRegistry() {
                return msgReg;
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelHandlerRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelHandlerRegistry.java
new file mode 100644 (file)
index 0000000..3f0d4c6
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.rsvp.rev130820.CLabel;
+
+public interface LabelHandlerRegistry {
+       public AutoCloseable registerLabelParser(int cType, LabelParser parser);
+       public LabelParser getLabelParser(int cType);
+
+       public AutoCloseable registerLabelSerializer(Class<? extends CLabel> labelClass, LabelSerializer serializer);
+       public LabelSerializer getLabelSerializer(CLabel label);
+}
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelParser.java
new file mode 100644 (file)
index 0000000..8ecd171
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * 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.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
+
+public interface LabelParser {
+       public CLabel parseLabel(final byte[] buffer) throws PCEPDeserializerException;
+}
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelSerializer.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelSerializer.java
new file mode 100644 (file)
index 0000000..d17dce1
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.rsvp.rev130820.CLabel;
+
+public interface LabelSerializer {
+
+       @Deprecated
+       public int getType();
+
+       public byte[] serializeSubobject(CLabel subobject);
+}
index 83480bc8e4e5c6e0e36efca1b664cb551d655855..58ae54f41ac22c41dd7f6b4cd49abe2d8a2f3cfe 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.protocol.pcep.spi;
  *
  */
 public interface PCEPProviderContext {
+       public LabelHandlerRegistry getHandlerRegistry();
        public MessageHandlerRegistry getMessageHandlerRegistry();
        public ObjectHandlerRegistry getObjectHandlerRegistry();
        public SubobjectHandlerRegistry getSubobjectHandlerRegistry();