From 5f1a81016740452e817b2ef6efab5f6175212151 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 16 Oct 2013 11:02:35 +0200 Subject: [PATCH] BUG-113: allow for per-object subobject registries Change-Id: I19c0576e57cfc7b9a9f8aa4359bf9d23a9105770 Signed-off-by: Robert Varga --- .../protocol/pcep/impl/PCEPImplActivator.java | 96 +++++++++---------- .../impl/SingletonPCEPProviderContext.java | 18 +++- .../object/PCEPBandwidthObjectParser.java | 9 +- .../object/PCEPClassTypeObjectParser.java | 9 +- .../impl/object/PCEPCloseObjectParser.java | 9 +- .../object/PCEPEndPointsObjectParser.java | 9 +- .../impl/object/PCEPErrorObjectParser.java | 9 +- .../object/PCEPExplicitRouteObjectParser.java | 15 +-- .../PCEPGlobalConstraintsObjectParser.java | 9 +- .../object/PCEPIncludeRouteObjectParser.java | 15 +-- .../object/PCEPLoadBalancingObjectParser.java | 9 +- .../pcep/impl/object/PCEPLspObjectParser.java | 9 +- .../impl/object/PCEPLspaObjectParser.java | 9 +- .../impl/object/PCEPMetricObjectParser.java | 9 +- .../impl/object/PCEPNoPathObjectParser.java | 9 +- .../object/PCEPNotificationObjectParser.java | 9 +- .../PCEPObjectiveFunctionObjectParser.java | 9 +- .../impl/object/PCEPOpenObjectParser.java | 9 +- .../impl/object/PCEPPathKeyObjectParser.java | 9 +- .../object/PCEPReportedRouteObjectParser.java | 15 +-- .../PCEPRequestParameterObjectParser.java | 9 +- .../pcep/impl/object/PCEPSrpObjectParser.java | 9 +- .../impl/object/PCEPSvecObjectParser.java | 9 +- ...> AbstractObjectWithSubobjectsParser.java} | 69 +------------ .../spi/AbstractObjectWithTlvsParser.java | 90 +++++++++++++++++ .../pcep/spi/PCEPProviderContext.java | 4 +- 26 files changed, 243 insertions(+), 241 deletions(-) rename pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/{AbstractObjectParser.java => AbstractObjectWithSubobjectsParser.java} (59%) create mode 100644 pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPImplActivator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPImplActivator.java index 08bed1071c..3e78d31919 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPImplActivator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPImplActivator.java @@ -99,9 +99,9 @@ public final class PCEPImplActivator implements PCEPProviderActivator { Preconditions.checkState(registrations == null); final List regs = new ArrayList<>(); - final SubobjectHandlerRegistry subReg = context.getSubobjectHandlerRegistry(); - subReg.registerSubobjectParser(EROAsNumberSubobjectParser.TYPE, new EROAsNumberSubobjectParser()); - subReg.registerSubobjectSerializer(AsNumberSubobject.class, new EROAsNumberSubobjectParser()); + final SubobjectHandlerRegistry eroSubReg = context.getEROSubobjectHandlerRegistry(); + eroSubReg.registerSubobjectParser(EROAsNumberSubobjectParser.TYPE, new EROAsNumberSubobjectParser()); + eroSubReg.registerSubobjectSerializer(AsNumberSubobject.class, new EROAsNumberSubobjectParser()); final TlvHandlerRegistry tlvReg = context.getTlvHandlerRegistry(); tlvReg.registerTlvParser(NoPathVectorTlvParser.TYPE, new NoPathVectorTlvParser()); @@ -132,61 +132,61 @@ public final class PCEPImplActivator implements PCEPProviderActivator { tlvReg.registerTlvSerializer(PredundancyGroupIdTlv.class, new PredundancyGroupTlvParser()); final ObjectHandlerRegistry objReg = context.getObjectHandlerRegistry(); - objReg.registerObjectParser(PCEPOpenObjectParser.CLASS, PCEPOpenObjectParser.TYPE, new PCEPOpenObjectParser(subReg, tlvReg)); + objReg.registerObjectParser(PCEPOpenObjectParser.CLASS, PCEPOpenObjectParser.TYPE, new PCEPOpenObjectParser(tlvReg)); objReg.registerObjectParser(PCEPRequestParameterObjectParser.CLASS, PCEPRequestParameterObjectParser.TYPE, - new PCEPRequestParameterObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPNoPathObjectParser.CLASS, PCEPNoPathObjectParser.TYPE, new PCEPNoPathObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPEndPointsObjectParser.CLASS, PCEPEndPointsObjectParser.TYPE, new PCEPEndPointsObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPEndPointsObjectParser.CLASS_6, PCEPEndPointsObjectParser.TYPE_6, new PCEPEndPointsObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPBandwidthObjectParser.CLASS, PCEPBandwidthObjectParser.TYPE, new PCEPBandwidthObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPBandwidthObjectParser.E_CLASS, PCEPBandwidthObjectParser.E_TYPE, new PCEPBandwidthObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPMetricObjectParser.CLASS, PCEPMetricObjectParser.TYPE, new PCEPMetricObjectParser(subReg, tlvReg)); + new PCEPRequestParameterObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPNoPathObjectParser.CLASS, PCEPNoPathObjectParser.TYPE, new PCEPNoPathObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPEndPointsObjectParser.CLASS, PCEPEndPointsObjectParser.TYPE, new PCEPEndPointsObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPEndPointsObjectParser.CLASS_6, PCEPEndPointsObjectParser.TYPE_6, new PCEPEndPointsObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPBandwidthObjectParser.CLASS, PCEPBandwidthObjectParser.TYPE, new PCEPBandwidthObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPBandwidthObjectParser.E_CLASS, PCEPBandwidthObjectParser.E_TYPE, new PCEPBandwidthObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPMetricObjectParser.CLASS, PCEPMetricObjectParser.TYPE, new PCEPMetricObjectParser(tlvReg)); objReg.registerObjectParser(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE, - new PCEPExplicitRouteObjectParser(subReg, tlvReg)); + new PCEPExplicitRouteObjectParser(context.getEROSubobjectHandlerRegistry())); objReg.registerObjectParser(PCEPReportedRouteObjectParser.CLASS, PCEPReportedRouteObjectParser.TYPE, - new PCEPReportedRouteObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPLspaObjectParser.CLASS, PCEPLspaObjectParser.TYPE, new PCEPLspaObjectParser(subReg, tlvReg)); + new PCEPReportedRouteObjectParser(context.getRROSubobjectHandlerRegistry())); + objReg.registerObjectParser(PCEPLspaObjectParser.CLASS, PCEPLspaObjectParser.TYPE, new PCEPLspaObjectParser( tlvReg)); objReg.registerObjectParser(PCEPIncludeRouteObjectParser.CLASS, PCEPIncludeRouteObjectParser.TYPE, - new PCEPIncludeRouteObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPSvecObjectParser.CLASS, PCEPSvecObjectParser.TYPE, new PCEPSvecObjectParser(subReg, tlvReg)); + new PCEPIncludeRouteObjectParser(context.getEROSubobjectHandlerRegistry())); + objReg.registerObjectParser(PCEPSvecObjectParser.CLASS, PCEPSvecObjectParser.TYPE, new PCEPSvecObjectParser(tlvReg)); objReg.registerObjectParser(PCEPNotificationObjectParser.CLASS, PCEPNotificationObjectParser.TYPE, - new PCEPNotificationObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPErrorObjectParser.CLASS, PCEPErrorObjectParser.TYPE, new PCEPErrorObjectParser(subReg, tlvReg)); + new PCEPNotificationObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPErrorObjectParser.CLASS, PCEPErrorObjectParser.TYPE, new PCEPErrorObjectParser(tlvReg)); objReg.registerObjectParser(PCEPLoadBalancingObjectParser.CLASS, PCEPLoadBalancingObjectParser.TYPE, - new PCEPLoadBalancingObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPCloseObjectParser.CLASS, PCEPCloseObjectParser.TYPE, new PCEPCloseObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPPathKeyObjectParser.CLASS, PCEPPathKeyObjectParser.TYPE, new PCEPPathKeyObjectParser(subReg, tlvReg)); + new PCEPLoadBalancingObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPCloseObjectParser.CLASS, PCEPCloseObjectParser.TYPE, new PCEPCloseObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPPathKeyObjectParser.CLASS, PCEPPathKeyObjectParser.TYPE, new PCEPPathKeyObjectParser(tlvReg)); objReg.registerObjectParser(PCEPObjectiveFunctionObjectParser.CLASS, PCEPObjectiveFunctionObjectParser.TYPE, - new PCEPObjectiveFunctionObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPClassTypeObjectParser.CLASS, PCEPClassTypeObjectParser.TYPE, new PCEPClassTypeObjectParser(subReg, tlvReg)); + new PCEPObjectiveFunctionObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPClassTypeObjectParser.CLASS, PCEPClassTypeObjectParser.TYPE, new PCEPClassTypeObjectParser(tlvReg)); objReg.registerObjectParser(PCEPGlobalConstraintsObjectParser.CLASS, PCEPGlobalConstraintsObjectParser.TYPE, - new PCEPGlobalConstraintsObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPLspObjectParser.CLASS, PCEPLspObjectParser.TYPE, new PCEPLspObjectParser(subReg, tlvReg)); - objReg.registerObjectParser(PCEPSrpObjectParser.CLASS, PCEPSrpObjectParser.TYPE, new PCEPSrpObjectParser(subReg, tlvReg)); + new PCEPGlobalConstraintsObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPLspObjectParser.CLASS, PCEPLspObjectParser.TYPE, new PCEPLspObjectParser(tlvReg)); + objReg.registerObjectParser(PCEPSrpObjectParser.CLASS, PCEPSrpObjectParser.TYPE, new PCEPSrpObjectParser(tlvReg)); // objReg.registerObjectParser(PCEPExcludeRouteObjectParser.CLASS, PCEPExcludeRouteObjectParser.TYPE, new - // PCEPExcludeRouteObjectParser(reg)); + // PCEPExcludeRouteObjectParser(context.getXROSubobjectHandlerRegistry())); - objReg.registerObjectSerializer(OpenObject.class, new PCEPOpenObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(RpObject.class, new PCEPRequestParameterObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(NoPathObject.class, new PCEPNoPathObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(EndpointsObject.class, new PCEPEndPointsObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(BandwidthObject.class, new PCEPBandwidthObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(MetricObject.class, new PCEPMetricObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(ExplicitRouteObject.class, new PCEPExplicitRouteObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(ReportedRouteObject.class, new PCEPReportedRouteObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(LspaObject.class, new PCEPLspaObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(IncludeRouteObject.class, new PCEPIncludeRouteObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(SvecObject.class, new PCEPSvecObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(NotificationObject.class, new PCEPNotificationObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(PcepErrorObject.class, new PCEPErrorObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(LoadBalancingObject.class, new PCEPLoadBalancingObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(CloseObject.class, new PCEPCloseObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(OfObject.class, new PCEPObjectiveFunctionObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(ClasstypeObject.class, new PCEPClassTypeObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(GcObject.class, new PCEPGlobalConstraintsObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(LspObject.class, new PCEPLspObjectParser(subReg, tlvReg)); - objReg.registerObjectSerializer(SrpObject.class, new PCEPSrpObjectParser(subReg, tlvReg)); + objReg.registerObjectSerializer(OpenObject.class, new PCEPOpenObjectParser(tlvReg)); + objReg.registerObjectSerializer(RpObject.class, new PCEPRequestParameterObjectParser(tlvReg)); + objReg.registerObjectSerializer(NoPathObject.class, new PCEPNoPathObjectParser(tlvReg)); + objReg.registerObjectSerializer(EndpointsObject.class, new PCEPEndPointsObjectParser(tlvReg)); + objReg.registerObjectSerializer(BandwidthObject.class, new PCEPBandwidthObjectParser(tlvReg)); + objReg.registerObjectSerializer(MetricObject.class, new PCEPMetricObjectParser(tlvReg)); + objReg.registerObjectSerializer(ExplicitRouteObject.class, new PCEPExplicitRouteObjectParser(context.getEROSubobjectHandlerRegistry())); + objReg.registerObjectSerializer(ReportedRouteObject.class, new PCEPReportedRouteObjectParser(context.getRROSubobjectHandlerRegistry())); + objReg.registerObjectSerializer(LspaObject.class, new PCEPLspaObjectParser(tlvReg)); + objReg.registerObjectSerializer(IncludeRouteObject.class, new PCEPIncludeRouteObjectParser(context.getEROSubobjectHandlerRegistry())); + objReg.registerObjectSerializer(SvecObject.class, new PCEPSvecObjectParser(tlvReg)); + objReg.registerObjectSerializer(NotificationObject.class, new PCEPNotificationObjectParser(tlvReg)); + objReg.registerObjectSerializer(PcepErrorObject.class, new PCEPErrorObjectParser(tlvReg)); + objReg.registerObjectSerializer(LoadBalancingObject.class, new PCEPLoadBalancingObjectParser(tlvReg)); + objReg.registerObjectSerializer(CloseObject.class, new PCEPCloseObjectParser(tlvReg)); + objReg.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(tlvReg)); + objReg.registerObjectSerializer(OfObject.class, new PCEPObjectiveFunctionObjectParser(tlvReg)); + objReg.registerObjectSerializer(ClasstypeObject.class, new PCEPClassTypeObjectParser(tlvReg)); + objReg.registerObjectSerializer(GcObject.class, new PCEPGlobalConstraintsObjectParser(tlvReg)); + objReg.registerObjectSerializer(LspObject.class, new PCEPLspObjectParser(tlvReg)); + objReg.registerObjectSerializer(SrpObject.class, new PCEPSrpObjectParser(tlvReg)); // reg.registerObjectSerializer(ExcludeRouteObject.class, new PCEPExcludeRouteObjectParser(reg)); final MessageHandlerRegistry msgReg = context.getMessageHandlerRegistry(); diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SingletonPCEPProviderContext.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SingletonPCEPProviderContext.java index 3f99f4961c..fcded2e917 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SingletonPCEPProviderContext.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SingletonPCEPProviderContext.java @@ -34,7 +34,9 @@ public final class SingletonPCEPProviderContext implements PCEPProviderContext { 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 SubobjectHandlerRegistry eroSubReg = new SimpleSubobjectHandlerFactory(); + private final SubobjectHandlerRegistry rroSubReg = new SimpleSubobjectHandlerFactory(); + private final SubobjectHandlerRegistry xroSubReg = new SimpleSubobjectHandlerFactory(); private final TlvHandlerRegistry tlvReg = new SimpleTlvHandlerRegistry(); private SingletonPCEPProviderContext() { @@ -61,8 +63,18 @@ public final class SingletonPCEPProviderContext implements PCEPProviderContext { } @Override - public SubobjectHandlerRegistry getSubobjectHandlerRegistry() { - return subobjReg; + public SubobjectHandlerRegistry getEROSubobjectHandlerRegistry() { + return eroSubReg; + } + + @Override + public SubobjectHandlerRegistry getRROSubobjectHandlerRegistry() { + return rroSubReg; + } + + @Override + public SubobjectHandlerRegistry getXROSubobjectHandlerRegistry() { + return xroSubReg; } @Override diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java index aad6c6409a..5d0eda91b4 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java @@ -9,8 +9,7 @@ package org.opendaylight.protocol.pcep.impl.object; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry; +import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser; import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject; @@ -22,7 +21,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ /** * Parser for {@link BandwidthObject} */ -public class PCEPBandwidthObjectParser extends AbstractObjectParser { +public class PCEPBandwidthObjectParser extends AbstractObjectWithTlvsParser { public static final int E_CLASS = 5; @@ -34,8 +33,8 @@ public class PCEPBandwidthObjectParser extends AbstractObjectParser { +public class PCEPClassTypeObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 22; @@ -44,8 +43,8 @@ public class PCEPClassTypeObjectParser extends AbstractObjectParser { +public class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 15; @@ -48,8 +47,8 @@ public class PCEPCloseObjectParser extends AbstractObjectParser { */ public static final int TLVS_OFFSET = REASON_F_OFFSET + REASON_F_LENGTH; - public PCEPCloseObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPCloseObjectParser(final TlvHandlerRegistry tlvReg) { + super(tlvReg); } @Override diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsObjectParser.java index 3f0b78f4f5..59ecbd4802 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsObjectParser.java @@ -12,8 +12,7 @@ import org.opendaylight.protocol.concepts.Ipv6Util; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; import org.opendaylight.protocol.pcep.PCEPErrors; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry; +import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser; import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject; @@ -30,7 +29,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ /** * Parser for IPv4 {@link EndpointsObject} */ -public class PCEPEndPointsObjectParser extends AbstractObjectParser { +public class PCEPEndPointsObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 4; @@ -55,8 +54,8 @@ public class PCEPEndPointsObjectParser extends AbstractObjectParser { +public class PCEPErrorObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 13; @@ -43,8 +42,8 @@ public class PCEPErrorObjectParser extends AbstractObjectParser { public static final int EV_F_OFFSET = ET_F_OFFSET + ET_F_LENGTH; public static final int TLVS_OFFSET = EV_F_OFFSET + EV_F_LENGTH; - public PCEPErrorObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPErrorObjectParser(final TlvHandlerRegistry tlvReg) { + super(tlvReg); } @Override diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExplicitRouteObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExplicitRouteObjectParser.java index 1f3c87b3ab..dc8e3362c2 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExplicitRouteObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExplicitRouteObjectParser.java @@ -11,13 +11,11 @@ import java.util.Map; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; +import org.opendaylight.protocol.pcep.spi.AbstractObjectWithSubobjectsParser; import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry; -import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject; 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; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.definition.ExplicitRouteBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject; @@ -27,14 +25,14 @@ import com.google.common.collect.Maps; /** * Parser for {@link ExplicitRouteObject} */ -public class PCEPExplicitRouteObjectParser extends AbstractObjectParser { +public class PCEPExplicitRouteObjectParser extends AbstractObjectWithSubobjectsParser { public static final int CLASS = 7; public static final int TYPE = 1; - public PCEPExplicitRouteObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPExplicitRouteObjectParser(final SubobjectHandlerRegistry subobjReg) { + super(subobjReg); } @Override @@ -53,11 +51,6 @@ public class PCEPExplicitRouteObjectParser extends AbstractObjectParser { +public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 24; @@ -40,8 +39,8 @@ public class PCEPGlobalConstraintsObjectParser extends AbstractObjectParser { +public class PCEPIncludeRouteObjectParser extends AbstractObjectWithSubobjectsParser { public static final int CLASS = 10; public static final int TYPE = 1; - public PCEPIncludeRouteObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPIncludeRouteObjectParser(final SubobjectHandlerRegistry subobjReg) { + super(subobjReg); } @Override @@ -46,11 +44,6 @@ public class PCEPIncludeRouteObjectParser extends AbstractObjectParser { +public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 14; @@ -39,8 +38,8 @@ public class PCEPLoadBalancingObjectParser extends AbstractObjectParser { +public class PCEPLspObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 32; @@ -44,8 +43,8 @@ public class PCEPLspObjectParser extends AbstractObjectParser { private static final int SYNC_FLAG_OFFSET = 14; private static final int REMOVE_FLAG_OFFSET = 12; - public PCEPLspObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPLspObjectParser(final TlvHandlerRegistry tlvReg) { + super(tlvReg); } @Override diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java index dd4064caee..1a0edc3171 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java @@ -11,8 +11,7 @@ import java.util.BitSet; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry; +import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser; import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspaObject; @@ -25,7 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev /** * Parser for {@link LspaObject} */ -public class PCEPLspaObjectParser extends AbstractObjectParser { +public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 9; @@ -58,8 +57,8 @@ public class PCEPLspaObjectParser extends AbstractObjectParser { public static final int FLAGS_F_OFFSET = HOLD_PRIO_F_OFFSET + HOLD_PRIO_F_LENGTH; public static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1; // added reserved field of length 1B - public PCEPLspaObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPLspaObjectParser(final TlvHandlerRegistry tlvReg) { + super(tlvReg); } @Override diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java index f1a5f40675..21d5348771 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java @@ -11,8 +11,7 @@ import java.util.BitSet; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry; +import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser; import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32; @@ -26,7 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ /** * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPMetricObject PCEPMetricObject} */ -public class PCEPMetricObjectParser extends AbstractObjectParser { +public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 6; @@ -54,8 +53,8 @@ public class PCEPMetricObjectParser extends AbstractObjectParser public static final int SIZE = METRIC_VALUE_F_OFFSET + METRIC_VALUE_F_LENGTH; - public PCEPMetricObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPMetricObjectParser(final TlvHandlerRegistry tlvReg) { + super(tlvReg); } @Override diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java index bbf06a8adc..a565b63520 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java @@ -12,8 +12,7 @@ import java.util.BitSet; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; import org.opendaylight.protocol.pcep.impl.Util; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry; +import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser; import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.pcrep.pcrep.message.replies.result.failure.NoPath; @@ -27,7 +26,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ /** * Parser for {@link NoPathObject} */ -public class PCEPNoPathObjectParser extends AbstractObjectParser { +public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 3; @@ -55,8 +54,8 @@ public class PCEPNoPathObjectParser extends AbstractObjectParser public static final int C_FLAG_OFFSET = 0; - public PCEPNoPathObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPNoPathObjectParser(final TlvHandlerRegistry tlvReg) { + super(tlvReg); } @Override diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java index da652bf855..cfe395b28b 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java @@ -10,8 +10,7 @@ package org.opendaylight.protocol.pcep.impl.object; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; import org.opendaylight.protocol.pcep.impl.Util; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry; +import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser; import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NotificationObject; @@ -27,7 +26,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ /** * Parser for {@link NotificationObject} */ -public class PCEPNotificationObjectParser extends AbstractObjectParser { +public class PCEPNotificationObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 12; @@ -48,8 +47,8 @@ public class PCEPNotificationObjectParser extends AbstractObjectParser { +public class PCEPObjectiveFunctionObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 21; @@ -39,8 +38,8 @@ public class PCEPObjectiveFunctionObjectParser extends AbstractObjectParser { +public class PCEPOpenObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 1; @@ -78,8 +77,8 @@ public class PCEPOpenObjectParser extends AbstractObjectParser { private static final int PCEP_VERSION = 1; - public PCEPOpenObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPOpenObjectParser(final TlvHandlerRegistry tlvReg) { + super(tlvReg); } @Override diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java index a865e9f578..d47b78bb53 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java @@ -9,8 +9,7 @@ package org.opendaylight.protocol.pcep.impl.object; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry; +import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser; import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; 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; @@ -21,14 +20,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ /** * Parser for {@link PathKeyObject} */ -public class PCEPPathKeyObjectParser extends AbstractObjectParser { +public class PCEPPathKeyObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 16; public static final int TYPE = 1; - public PCEPPathKeyObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPPathKeyObjectParser(final TlvHandlerRegistry tlvReg) { + super(tlvReg); } @Override diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPReportedRouteObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPReportedRouteObjectParser.java index 4b0408dd4d..a9bcb769d9 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPReportedRouteObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPReportedRouteObjectParser.java @@ -9,26 +9,24 @@ package org.opendaylight.protocol.pcep.impl.object; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; +import org.opendaylight.protocol.pcep.spi.AbstractObjectWithSubobjectsParser; import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry; -import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; 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; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReportedRouteObject; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.ReportedRouteBuilder; /** * Parser for {@link ReportedRouteObject} */ -public class PCEPReportedRouteObjectParser extends AbstractObjectParser { +public class PCEPReportedRouteObjectParser extends AbstractObjectWithSubobjectsParser { public static final int CLASS = 8; public static final int TYPE = 1; - public PCEPReportedRouteObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPReportedRouteObjectParser(final SubobjectHandlerRegistry subobjReg) { + super(subobjReg); } @Override @@ -46,11 +44,6 @@ public class PCEPReportedRouteObjectParser extends AbstractObjectParser { +public class PCEPRequestParameterObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 2; @@ -95,8 +94,8 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectParser { +public final class PCEPSrpObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 33; public static final int TYPE = 1; - public PCEPSrpObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPSrpObjectParser(final TlvHandlerRegistry tlvReg) { + super(tlvReg); } @Override diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java index b5079bd854..2dfd0dd8ab 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java @@ -12,8 +12,7 @@ import java.util.List; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry; +import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser; import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object; @@ -28,7 +27,7 @@ import com.google.common.collect.Lists; /** * Parser for {@link SvecObject} */ -public class PCEPSvecObjectParser extends AbstractObjectParser { +public class PCEPSvecObjectParser extends AbstractObjectWithTlvsParser { public static final int CLASS = 11; @@ -58,8 +57,8 @@ public class PCEPSvecObjectParser extends AbstractObjectParser { */ public static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET; - public PCEPSvecObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { - super(subobjReg, tlvReg); + public PCEPSvecObjectParser(final TlvHandlerRegistry tlvReg) { + super(tlvReg); } @Override diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithSubobjectsParser.java similarity index 59% rename from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectParser.java rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithSubobjectsParser.java index ca2fe202da..7daaf988dd 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithSubobjectsParser.java @@ -13,7 +13,6 @@ import java.util.Map.Entry; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.util.ByteArray; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,13 +21,9 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -public abstract class AbstractObjectParser implements ObjectParser, ObjectSerializer { +public abstract class AbstractObjectWithSubobjectsParser implements ObjectParser, ObjectSerializer { - private static final Logger logger = LoggerFactory.getLogger(AbstractObjectParser.class); - - private static final int TLV_TYPE_F_LENGTH = 2; - private static final int TLV_LENGTH_F_LENGTH = 2; - private static final int TLV_HEADER_LENGTH = TLV_LENGTH_F_LENGTH + TLV_TYPE_F_LENGTH; + private static final Logger logger = LoggerFactory.getLogger(AbstractObjectWithSubobjectsParser.class); private static final int SUB_TYPE_FLAG_F_LENGTH = 1; private static final int SUB_LENGTH_F_LENGTH = 1; @@ -41,62 +36,9 @@ public abstract class AbstractObjectParser implements ObjectParser, Obj protected static final int PADDED_TO = 4; private final SubobjectHandlerRegistry subobjReg; - private final TlvHandlerRegistry tlvReg; - protected AbstractObjectParser(final SubobjectHandlerRegistry subobjReg, final TlvHandlerRegistry tlvReg) { + protected AbstractObjectWithSubobjectsParser(final SubobjectHandlerRegistry subobjReg) { this.subobjReg = Preconditions.checkNotNull(subobjReg); - this.tlvReg = Preconditions.checkNotNull(tlvReg); - } - - protected final void parseTlvs(final BUILDER builder, final byte[] bytes) throws PCEPDeserializerException { - if (bytes == null) { - throw new IllegalArgumentException("Byte array is mandatory."); - } - - int length; - int byteOffset = 0; - int type = 0; - - while (byteOffset < bytes.length) { - type = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TLV_TYPE_F_LENGTH)); - byteOffset += TLV_TYPE_F_LENGTH; - length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TLV_LENGTH_F_LENGTH)); - byteOffset += TLV_LENGTH_F_LENGTH; - - if (TLV_HEADER_LENGTH + length > bytes.length - byteOffset) { - throw new PCEPDeserializerException("Wrong length specified. Passed: " + (TLV_HEADER_LENGTH + length) + "; Expected: <= " - + (bytes.length - byteOffset) + "."); - } - - final byte[] tlvBytes = ByteArray.subByte(bytes, byteOffset, length); - - logger.trace("Attempt to parse tlv from bytes: {}", ByteArray.bytesToHexString(tlvBytes)); - final Tlv tlv = this.tlvReg.getTlvParser(type).parseTlv(tlvBytes); - logger.trace("Tlv was parsed. {}", tlv); - - addTlv(builder, tlv); - - byteOffset += length + getPadding(TLV_HEADER_LENGTH + length, PADDED_TO); - } - } - - protected final byte[] serializeTlv(final Tlv tlv) { - - final TlvSerializer serializer = this.tlvReg.getTlvSerializer(tlv); - - final byte[] typeBytes = (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - TLV_TYPE_F_LENGTH)); - - final byte[] valueBytes = serializer.serializeTlv(tlv); - - final byte[] lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - TLV_LENGTH_F_LENGTH); - - final byte[] bytes = new byte[TLV_HEADER_LENGTH + valueBytes.length + getPadding(TLV_HEADER_LENGTH + valueBytes.length, PADDED_TO)]; - - int byteOffset = 0; - System.arraycopy(typeBytes, 0, bytes, byteOffset, TLV_TYPE_F_LENGTH); - System.arraycopy(lengthBytes, 0, bytes, byteOffset += TLV_TYPE_F_LENGTH, TLV_LENGTH_F_LENGTH); - System.arraycopy(valueBytes, 0, bytes, byteOffset += TLV_LENGTH_F_LENGTH, valueBytes.length); - return bytes; } protected final void parseSubobjects(final BUILDER builder, final byte[] bytes) throws PCEPDeserializerException { @@ -178,9 +120,4 @@ public abstract class AbstractObjectParser implements ObjectParser, Obj // public abstract void addSubobject(final BUILDER builder, final Map subobjects); - public abstract void addTlv(final BUILDER builder, final Tlv tlv); - - private static int getPadding(final int length, final int padding) { - return (padding - (length % padding)) % padding; - } } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java new file mode 100644 index 0000000000..b4ec3f75b6 --- /dev/null +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectWithTlvsParser.java @@ -0,0 +1,90 @@ +/* + * 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.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Preconditions; + +public abstract class AbstractObjectWithTlvsParser implements ObjectParser, ObjectSerializer { + + private static final Logger logger = LoggerFactory.getLogger(AbstractObjectWithTlvsParser.class); + + private static final int TLV_TYPE_F_LENGTH = 2; + private static final int TLV_LENGTH_F_LENGTH = 2; + private static final int TLV_HEADER_LENGTH = TLV_LENGTH_F_LENGTH + TLV_TYPE_F_LENGTH; + + protected static final int PADDED_TO = 4; + + private final TlvHandlerRegistry tlvReg; + + protected AbstractObjectWithTlvsParser(final TlvHandlerRegistry tlvReg) { + this.tlvReg = Preconditions.checkNotNull(tlvReg); + } + + protected final void parseTlvs(final BUILDER builder, final byte[] bytes) throws PCEPDeserializerException { + if (bytes == null) { + throw new IllegalArgumentException("Byte array is mandatory."); + } + + int length; + int byteOffset = 0; + int type = 0; + + while (byteOffset < bytes.length) { + type = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TLV_TYPE_F_LENGTH)); + byteOffset += TLV_TYPE_F_LENGTH; + length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TLV_LENGTH_F_LENGTH)); + byteOffset += TLV_LENGTH_F_LENGTH; + + if (TLV_HEADER_LENGTH + length > bytes.length - byteOffset) { + throw new PCEPDeserializerException("Wrong length specified. Passed: " + (TLV_HEADER_LENGTH + length) + "; Expected: <= " + + (bytes.length - byteOffset) + "."); + } + + final byte[] tlvBytes = ByteArray.subByte(bytes, byteOffset, length); + + logger.trace("Attempt to parse tlv from bytes: {}", ByteArray.bytesToHexString(tlvBytes)); + final Tlv tlv = this.tlvReg.getTlvParser(type).parseTlv(tlvBytes); + logger.trace("Tlv was parsed. {}", tlv); + + addTlv(builder, tlv); + + byteOffset += length + getPadding(TLV_HEADER_LENGTH + length, PADDED_TO); + } + } + + protected final byte[] serializeTlv(final Tlv tlv) { + + final TlvSerializer serializer = this.tlvReg.getTlvSerializer(tlv); + + final byte[] typeBytes = (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - TLV_TYPE_F_LENGTH)); + + final byte[] valueBytes = serializer.serializeTlv(tlv); + + final byte[] lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - TLV_LENGTH_F_LENGTH); + + final byte[] bytes = new byte[TLV_HEADER_LENGTH + valueBytes.length + getPadding(TLV_HEADER_LENGTH + valueBytes.length, PADDED_TO)]; + + int byteOffset = 0; + System.arraycopy(typeBytes, 0, bytes, byteOffset, TLV_TYPE_F_LENGTH); + System.arraycopy(lengthBytes, 0, bytes, byteOffset += TLV_TYPE_F_LENGTH, TLV_LENGTH_F_LENGTH); + System.arraycopy(valueBytes, 0, bytes, byteOffset += TLV_LENGTH_F_LENGTH, valueBytes.length); + return bytes; + } + + public abstract void addTlv(final BUILDER builder, final Tlv tlv); + + private static int getPadding(final int length, final int padding) { + return (padding - (length % padding)) % padding; + } +} diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPProviderContext.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPProviderContext.java index 58ae54f41a..a15204760f 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPProviderContext.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPProviderContext.java @@ -14,6 +14,8 @@ public interface PCEPProviderContext { public LabelHandlerRegistry getHandlerRegistry(); public MessageHandlerRegistry getMessageHandlerRegistry(); public ObjectHandlerRegistry getObjectHandlerRegistry(); - public SubobjectHandlerRegistry getSubobjectHandlerRegistry(); + public SubobjectHandlerRegistry getEROSubobjectHandlerRegistry(); + public SubobjectHandlerRegistry getRROSubobjectHandlerRegistry(); + public SubobjectHandlerRegistry getXROSubobjectHandlerRegistry(); public TlvHandlerRegistry getTlvHandlerRegistry(); } -- 2.36.6