import org.opendaylight.protocol.pcep.impl.tlv.OrderTlvParser;
import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
context.registerLabelSerializer(GeneralizedLabelCase.class, new GeneralizedLabelParser());
context.registerLabelSerializer(WavebandSwitchingLabelCase.class, new WavebandSwitchingLabelParser());
- final EROSubobjectHandlerRegistry eroSubReg = context.getEROSubobjectHandlerRegistry();
+ final EROSubobjectRegistry eroSubReg = context.getEROSubobjectHandlerRegistry();
context.registerEROSubobjectParser(EROIpv4PrefixSubobjectParser.TYPE, new EROIpv4PrefixSubobjectParser());
context.registerEROSubobjectParser(EROIpv6PrefixSubobjectParser.TYPE, new EROIpv6PrefixSubobjectParser());
context.registerEROSubobjectParser(EROAsNumberSubobjectParser.TYPE, new EROAsNumberSubobjectParser());
import java.util.List;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
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 EROSubobjectHandlerRegistry subobjReg;
+ private final EROSubobjectRegistry subobjReg;
- protected AbstractEROWithSubobjectsParser(final EROSubobjectHandlerRegistry subobjReg) {
+ protected AbstractEROWithSubobjectsParser(final EROSubobjectRegistry subobjReg) {
this.subobjReg = Preconditions.checkNotNull(subobjReg);
}
System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
LOG.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
- final Subobject sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, loose);
- LOG.debug("Subobject was parsed. {}", sub);
-
- subs.add(sub);
-
+ final Subobject sub = this.subobjReg.parseSubobject(type, soContentsBytes, loose);
+ if (sub == null) {
+ LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
+ } else {
+ LOG.debug("Subobject was parsed. {}", sub);
+ subs.add(sub);
+ }
offset += 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 EROSubobjectSerializer 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) {
*/
package org.opendaylight.protocol.pcep.impl.object;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
public static final int TYPE = 1;
- public PCEPExplicitRouteObjectParser(final EROSubobjectHandlerRegistry subobjReg) {
+ public PCEPExplicitRouteObjectParser(final EROSubobjectRegistry subobjReg) {
super(subobjReg);
}
import java.util.List;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
public static final int TYPE = 1;
- public PCEPIncludeRouteObjectParser(final EROSubobjectHandlerRegistry subobjReg) {
+ public PCEPIncludeRouteObjectParser(final EROSubobjectRegistry subobjReg) {
super(subobjReg);
}
import java.util.List;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
public static final int TYPE = 1;
- public PCEPPathKeyObjectParser(final EROSubobjectHandlerRegistry subReg) {
+ public PCEPPathKeyObjectParser(final EROSubobjectRegistry subReg) {
super(subReg);
}
+++ /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 EROSubobjectHandlerRegistry {
- EROSubobjectParser getSubobjectParser(int subobjectType);
- EROSubobjectSerializer 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.explicit.route.object.ero.Subobject;
+
+public interface EROSubobjectRegistry {
+ /**
+ * 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 loose ERO 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 subobjectType, final byte[] buffer, final boolean loose) 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);
+}
ObjectHandlerRegistry getObjectHandlerRegistry();
- EROSubobjectHandlerRegistry getEROSubobjectHandlerRegistry();
+ EROSubobjectRegistry getEROSubobjectHandlerRegistry();
RROSubobjectRegistry getRROSubobjectHandlerRegistry();
package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.Values;
+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.rsvp.rev130820.basic.explicit.route.subobjects.SubobjectType;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import com.google.common.base.Preconditions;
-public final class SimpleEROSubobjectHandlerRegistry implements EROSubobjectHandlerRegistry {
+public final class SimpleEROSubobjectRegistry implements EROSubobjectRegistry {
private final HandlerRegistry<DataContainer, EROSubobjectParser, EROSubobjectSerializer> handlers = new HandlerRegistry<>();
public AutoCloseable registerSubobjectParser(final int subobjectType, final EROSubobjectParser parser) {
}
@Override
- public EROSubobjectParser 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 loose) throws PCEPDeserializerException {
+ Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE);
+ final EROSubobjectParser parser = this.handlers.getParser(type);
+ if (parser == null) {
+ return null;
+ }
+ return parser.parseSubobject(buffer, loose);
}
@Override
- public EROSubobjectSerializer getSubobjectSerializer(final SubobjectType subobject) {
- return this.handlers.getSerializer(subobject.getImplementedInterface());
+ public byte[] serializeSubobject(Subobject subobject) {
+ final EROSubobjectSerializer serializer = this.handlers.getSerializer(subobject.getSubobjectType().getImplementedInterface());
+ if (serializer == null) {
+ return null;
+ }
+ return serializer.serializeSubobject(subobject);
}
}
import javax.annotation.concurrent.ThreadSafe;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
private final SimpleLabelHandlerRegistry labelReg = new SimpleLabelHandlerRegistry();
private final SimpleMessageHandlerRegistry msgReg = new SimpleMessageHandlerRegistry();
private final SimpleObjectHandlerRegistry objReg = new SimpleObjectHandlerRegistry();
- private final SimpleEROSubobjectHandlerRegistry eroSubReg = new SimpleEROSubobjectHandlerRegistry();
+ private final SimpleEROSubobjectRegistry eroSubReg = new SimpleEROSubobjectRegistry();
private final SimpleRROSubobjectRegistry rroSubReg = new SimpleRROSubobjectRegistry();
private final SimpleXROSubobjectRegistry xroSubReg = new SimpleXROSubobjectRegistry();
private final SimpleTlvRegistry tlvReg = new SimpleTlvRegistry();
}
@Override
- public final EROSubobjectHandlerRegistry getEROSubobjectHandlerRegistry() {
+ public final EROSubobjectRegistry getEROSubobjectHandlerRegistry() {
return this.eroSubReg;
}