import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Keepalive;
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.subobject.subobject.type.PathKeyCase.class,
new RROPathKey32SubobjectParser());
- final XROSubobjectHandlerRegistry xroSubReg = context.getXROSubobjectHandlerRegistry();
+ final XROSubobjectRegistry xroSubReg = context.getXROSubobjectHandlerRegistry();
context.registerXROSubobjectParser(XROIpv4PrefixSubobjectParser.TYPE, new XROIpv4PrefixSubobjectParser());
context.registerXROSubobjectParser(XROIpv6PrefixSubobjectParser.TYPE, new XROIpv6PrefixSubobjectParser());
context.registerXROSubobjectParser(XROAsNumberSubobjectParser.TYPE, new XROAsNumberSubobjectParser());
import org.opendaylight.protocol.pcep.spi.ObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
import org.slf4j.Logger;
private static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH;
private static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH;
- private final XROSubobjectHandlerRegistry subobjReg;
+ private final XROSubobjectRegistry subobjReg;
- protected AbstractXROWithSubobjectsParser(final XROSubobjectHandlerRegistry subobjReg) {
+ protected AbstractXROWithSubobjectsParser(final XROSubobjectRegistry subobjReg) {
this.subobjReg = Preconditions.checkNotNull(subobjReg);
}
soContentsBytes = ByteArray.subByte(bytes, offset, length - SO_CONTENTS_OFFSET);
LOG.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
- final Subobject sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, mandatory);
- LOG.debug("Subobject was parsed. {}", sub);
-
- subs.add(sub);
-
+ final Subobject sub = this.subobjReg.parseSubobject(type, soContentsBytes, mandatory);
+ if (sub == null) {
+ LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
+ } else {
+ LOG.debug("Subobject was parsed. {}", sub);
+ subs.add(sub);
+ }
offset += soContentsBytes.length;
}
return subs;
}
protected final byte[] serializeSubobject(final List<Subobject> subobjects) {
-
final List<byte[]> result = Lists.newArrayList();
-
int finalLength = 0;
-
for (final Subobject subobject : subobjects) {
-
- final XROSubobjectSerializer serializer = this.subobjReg.getSubobjectSerializer(subobject.getSubobjectType());
-
- final byte[] bytes = serializer.serializeSubobject(subobject);
- finalLength += bytes.length;
- result.add(bytes);
+ final byte[] bytes = this.subobjReg.serializeSubobject(subobject);
+ if (bytes == null) {
+ LOG.warn("Could not find serializer for subobject type: {}. Skipping subobject.", subobject.getSubobjectType());
+ } else {
+ finalLength += bytes.length;
+ result.add(bytes);
+ }
}
-
final byte[] resultBytes = new byte[finalLength];
int byteOffset = 0;
for (final byte[] b : result) {
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.util.ByteArray;
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;
private static final int FLAGS_OFFSET = 3;
- public PCEPExcludeRouteObjectParser(final XROSubobjectHandlerRegistry registry) {
+ public PCEPExcludeRouteObjectParser(final XROSubobjectRegistry registry) {
super(registry);
}
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
private static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH;
private static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH;
- private final XROSubobjectHandlerRegistry registry;
+ private final XROSubobjectRegistry registry;
- public EROExplicitExclusionRouteSubobjectParser(final XROSubobjectHandlerRegistry registry) {
+ public EROExplicitExclusionRouteSubobjectParser(final XROSubobjectRegistry registry) {
this.registry = registry;
}
soContentsBytes = new byte[length - SO_CONTENTS_OFFSET];
System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
- final XROSubobjectParser parser = this.registry.getSubobjectParser(type);
-
- subs.add(parser.parseSubobject(soContentsBytes, mandatory));
+ subs.add(this.registry.parseSubobject(type, soContentsBytes, mandatory));
offset += length;
}
for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject subobject : subobjects) {
- final XROSubobjectSerializer serializer = this.registry.getSubobjectSerializer(subobject.getSubobjectType());
-
- final byte[] bytes = serializer.serializeSubobject(subobject);
+ final byte[] bytes = this.registry.serializeSubobject(subobject);
finalLength += bytes.length;
result.add(bytes);
}
RROSubobjectHandlerRegistry getRROSubobjectHandlerRegistry();
- XROSubobjectHandlerRegistry getXROSubobjectHandlerRegistry();
+ XROSubobjectRegistry getXROSubobjectHandlerRegistry();
TlvHandlerRegistry getTlvHandlerRegistry();
}
+++ /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.rsvp.rev130820.basic.explicit.route.subobjects.SubobjectType;
-
-public interface XROSubobjectHandlerRegistry {
- XROSubobjectParser getSubobjectParser(int subobjectType);
- XROSubobjectSerializer getSubobjectSerializer(SubobjectType subobject);
-}
--- /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.exclude.route.object.xro.Subobject;
+
+public interface XROSubobjectRegistry {
+ /**
+ * Finds parser for given subobject type in the registry. Delegates parsing to found parser.
+ * @param type subobject type, key in parser registry
+ * @param buffer subobject raw binary value to be parsed
+ * @param mandatory XRO specific common field
+ * @return null if the parser for this subobject could not be found
+ * @throws PCEPDeserializerException if the parsing did not succeed
+ */
+ Subobject parseSubobject(final int type, final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException;
+
+ /**
+ * Find serializer for given subobject. Delegates parsing to found serializer.
+ * @param subobject to be parsed
+ * @return null if the serializer for this subobject could not be found
+ */
+ byte[] serializeSubobject(final Subobject subobject);
+}
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
private final SimpleObjectHandlerRegistry objReg = new SimpleObjectHandlerRegistry();
private final SimpleEROSubobjectHandlerRegistry eroSubReg = new SimpleEROSubobjectHandlerRegistry();
private final SimpleRROSubobjectHandlerRegistry rroSubReg = new SimpleRROSubobjectHandlerRegistry();
- private final SimpleXROSubobjectHandlerRegistry xroSubReg = new SimpleXROSubobjectHandlerRegistry();
+ private final SimpleXROSubobjectRegistry xroSubReg = new SimpleXROSubobjectRegistry();
private final SimpleTlvHandlerRegistry tlvReg = new SimpleTlvHandlerRegistry();
@Override
}
@Override
- public final XROSubobjectHandlerRegistry getXROSubobjectHandlerRegistry() {
+ public final XROSubobjectRegistry getXROSubobjectHandlerRegistry() {
return this.xroSubReg;
}
package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
import org.opendaylight.protocol.util.Values;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.SubobjectType;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import com.google.common.base.Preconditions;
-public final class SimpleXROSubobjectHandlerRegistry implements XROSubobjectHandlerRegistry {
+public final class SimpleXROSubobjectRegistry implements XROSubobjectRegistry {
private final HandlerRegistry<DataContainer, XROSubobjectParser, XROSubobjectSerializer> handlers = new HandlerRegistry<>();
public AutoCloseable registerSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
}
@Override
- public XROSubobjectParser getSubobjectParser(final int subobjectType) {
- Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Values.UNSIGNED_SHORT_MAX_VALUE);
- return this.handlers.getParser(subobjectType);
+ public Subobject parseSubobject(int type, byte[] buffer, boolean mandatory) throws PCEPDeserializerException {
+ Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE);
+ final XROSubobjectParser parser = this.handlers.getParser(type);
+ if (parser == null) {
+ return null;
+ }
+ return parser.parseSubobject(buffer, mandatory);
}
@Override
- public XROSubobjectSerializer getSubobjectSerializer(final SubobjectType subobject) {
- return this.handlers.getSerializer(subobject.getImplementedInterface());
+ public byte[] serializeSubobject(Subobject subobject) {
+ final XROSubobjectSerializer serializer = this.handlers.getSerializer(subobject.getSubobjectType().getImplementedInterface());
+ if (serializer == null) {
+ return null;
+ }
+ return serializer.serializeSubobject(subobject);
}
}