import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Pcinitiate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.PcinitiateBuilder;
public class PcinitiateMessageParser extends AbstractMessageParser {
public static final int TYPE = 12;
- public PcinitiateMessageParser(final ObjectHandlerRegistry registry) {
+ public PcinitiateMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Replies1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Replies1Builder;
*/
public final class Stateful02PCReplyMessageParser extends PCEPReplyMessageParser {
- public Stateful02PCReplyMessageParser(final ObjectHandlerRegistry registry) {
+ public Stateful02PCReplyMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Pcrpt;
public static final int TYPE = 10;
- public Stateful02PCReportMessageParser(final ObjectHandlerRegistry registry) {
+ public Stateful02PCReportMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.P2p1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.P2p1Builder;
*/
public final class Stateful02PCRequestMessageParser extends PCEPRequestMessageParser {
- public Stateful02PCRequestMessageParser(final ObjectHandlerRegistry registry) {
+ public Stateful02PCRequestMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Pcupd;
public static final int TYPE = 11;
- public Stateful02PCUpdateRequestMessageParser(final ObjectHandlerRegistry registry) {
+ public Stateful02PCUpdateRequestMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Pcinitiate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.PcinitiateBuilder;
public static final int TYPE = 12;
- public CInitiated00PCInitiateMessageParser(final ObjectHandlerRegistry registry) {
+ public CInitiated00PCInitiateMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.protocol.pcep.spi.UnknownObject;
*/
public final class Stateful07ErrorMessageParser extends PCEPErrorMessageParser {
- public Stateful07ErrorMessageParser(final ObjectHandlerRegistry registry) {
+ public Stateful07ErrorMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Pcrpt;
public static final int TYPE = 10;
- public Stateful07PCReportMessageParser(final ObjectHandlerRegistry registry) {
+ public Stateful07PCReportMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Pcupd;
public static final int TYPE = 11;
- public Stateful07PCUpdateRequestMessageParser(final ObjectHandlerRegistry registry) {
+ public Stateful07PCUpdateRequestMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.ArrayList;
import java.util.List;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator;
protected List<AutoCloseable> startImpl(final PCEPExtensionProviderContext context) {
final List<AutoCloseable> regs = new ArrayList<>();
- final ObjectHandlerRegistry objReg = context.getObjectHandlerRegistry();
+ final ObjectRegistry objReg = context.getObjectHandlerRegistry();
regs.add(context.registerMessageParser(Stateful07PCUpdateRequestMessageParser.TYPE, new Stateful07PCUpdateRequestMessageParser(objReg)));
regs.add(context.registerMessageSerializer(Pcupd.class, new Stateful07PCUpdateRequestMessageParser(objReg)));
regs.add(context.registerMessageParser(Stateful07PCReportMessageParser.TYPE, new Stateful07PCReportMessageParser(objReg)));
import org.opendaylight.protocol.pcep.impl.message.PCEPOpenMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
import org.opendaylight.protocol.util.ByteArray;
public class PCEPValidatorTest {
- private ObjectHandlerRegistry objectRegistry;
+ private ObjectRegistry objectRegistry;
private Rp rpTrue;
private Rp rpFalse;
import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
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.LabelRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
import org.opendaylight.protocol.pcep.spi.RROSubobjectRegistry;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
protected List<AutoCloseable> startImpl(final PCEPExtensionProviderContext context) {
final List<AutoCloseable> regs = new ArrayList<>();
- final LabelHandlerRegistry labelReg = context.getLabelHandlerRegistry();
+ final LabelRegistry labelReg = context.getLabelHandlerRegistry();
context.registerLabelParser(Type1LabelParser.CTYPE, new Type1LabelParser());
context.registerLabelParser(GeneralizedLabelParser.CTYPE, new GeneralizedLabelParser());
context.registerLabelParser(WavebandSwitchingLabelParser.CTYPE, new WavebandSwitchingLabelParser());
context.registerTlvSerializer(OfList.class, new OFListTlvParser());
context.registerTlvSerializer(Order.class, new OrderTlvParser());
- final ObjectHandlerRegistry objReg = context.getObjectHandlerRegistry();
+ final ObjectRegistry objReg = context.getObjectHandlerRegistry();
context.registerObjectParser(PCEPRequestParameterObjectParser.CLASS, PCEPRequestParameterObjectParser.TYPE,
new PCEPRequestParameterObjectParser(tlvReg));
context.registerObjectParser(PCEPNoPathObjectParser.CLASS, PCEPNoPathObjectParser.TYPE, new PCEPNoPathObjectParser(tlvReg));
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
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.CloseBuilder;
public static final int TYPE = 7;
- public PCEPCloseMessageParser(final ObjectHandlerRegistry registry) {
+ public PCEPCloseMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.protocol.pcep.spi.UnknownObject;
public static final int TYPE = 6;
- public PCEPErrorMessageParser(final ObjectHandlerRegistry registry) {
+ public PCEPErrorMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage;
private static final KeepaliveMessage MESSAGE = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
public static final int TYPE = 2;
- public PCEPKeepAliveMessageParser(final ObjectHandlerRegistry registry) {
+ public PCEPKeepAliveMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcntfBuilder;
public static final int TYPE = 5;
- public PCEPNotificationMessageParser(final ObjectHandlerRegistry registry) {
+ public PCEPNotificationMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
public static final int TYPE = 1;
- public PCEPOpenMessageParser(final ObjectHandlerRegistry registry) {
+ public PCEPOpenMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcrep;
public static final int TYPE = 4;
- public PCEPReplyMessageParser(final ObjectHandlerRegistry registry) {
+ public PCEPReplyMessageParser(final ObjectRegistry registry) {
super(registry);
}
import java.util.List;
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcreq;
public static final int TYPE = 3;
- public PCEPRequestMessageParser(final ObjectHandlerRegistry registry) {
+ public PCEPRequestMessageParser(final ObjectRegistry registry) {
super(registry);
}
import org.opendaylight.protocol.pcep.impl.object.EROSubobjectUtil;
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
-import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.LabelParser;
-import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+import org.opendaylight.protocol.pcep.spi.LabelRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
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;
private static final int U_FLAG_OFFSET = 0;
- private final LabelHandlerRegistry registry;
+ private final LabelRegistry registry;
- public EROLabelSubobjectParser(final LabelHandlerRegistry labelReg) {
+ public EROLabelSubobjectParser(final LabelRegistry labelReg) {
this.registry = Preconditions.checkNotNull(labelReg);
}
final short cType = (short) UnsignedBytes.toInt(buffer[C_TYPE_F_OFFSET]);
- final LabelParser parser = this.registry.getLabelParser(cType);
+ final LabelType labelType = this.registry.parseLabel(cType, ByteArray.cutBytes(buffer, HEADER_LENGTH));
- if (parser == null) {
+ if (labelType == null) {
throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
}
final LabelBuilder builder = new LabelBuilder();
builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
- builder.setLabelType(parser.parseLabel(ByteArray.cutBytes(buffer, HEADER_LENGTH)));
+ builder.setLabelType(labelType);
return new SubobjectBuilder().setLoose(loose).setSubobjectType(new LabelCaseBuilder().setLabel(builder.build()).build()).build();
}
@Override
public byte[] serializeSubobject(final Subobject subobject) {
Preconditions.checkNotNull(subobject.getSubobjectType(), "Subobject type cannot be empty.");
-
final Label label = ((LabelCase) subobject.getSubobjectType()).getLabel();
- final LabelType l = label.getLabelType();
-
- final LabelSerializer serializer = this.registry.getLabelSerializer(l);
-
- if (serializer == null) {
+ final byte[] labelbytes = this.registry.serializeLabel(label.isUniDirectional(), false, label.getLabelType());
+ if (labelbytes == null) {
throw new IllegalArgumentException("Unknown EROLabelSubobject instance. Passed "
+ label.getLabelType().getImplementedInterface());
}
- final byte[] labelbytes = serializer.serializeLabel(l);
- final byte[] retBytes = new byte[labelbytes.length + HEADER_LENGTH];
-
- System.arraycopy(labelbytes, 0, retBytes, HEADER_LENGTH, labelbytes.length);
-
- final BitSet reserved = new BitSet();
- reserved.set(U_FLAG_OFFSET, label.isUniDirectional());
- System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
- retBytes[C_TYPE_F_OFFSET] = UnsignedBytes.checkedCast(serializer.getType());
- return EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), retBytes);
+ return EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), labelbytes);
}
@Override
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+import org.opendaylight.protocol.pcep.spi.LabelUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelCase;
}
@Override
- public byte[] serializeLabel(final LabelType subobject) {
+ public byte[] serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject) {
if (!(subobject instanceof GeneralizedLabelCase)) {
throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass()
+ ". Needed GeneralizedLabelCase.");
}
- return ((GeneralizedLabelCase) subobject).getGeneralizedLabel().getGeneralizedLabel();
+ return LabelUtil.formatLabel(CTYPE, unidirectional, global, ((GeneralizedLabelCase) subobject).getGeneralizedLabel().getGeneralizedLabel());
}
@Override
import java.util.BitSet;
import org.opendaylight.protocol.pcep.impl.object.RROSubobjectUtil;
-import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.LabelParser;
-import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+import org.opendaylight.protocol.pcep.spi.LabelRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
public static final int U_FLAG_OFFSET = 0;
public static final int G_FLAG_OFFSET = 7;
- private final LabelHandlerRegistry registry;
+ private final LabelRegistry registry;
- public RROLabelSubobjectParser(final LabelHandlerRegistry labelReg) {
+ public RROLabelSubobjectParser(final LabelRegistry labelReg) {
this.registry = Preconditions.checkNotNull(labelReg);
}
final short cType = (short) UnsignedBytes.toInt(buffer[C_TYPE_F_OFFSET]);
- final LabelParser parser = this.registry.getLabelParser(cType);
-
- if (parser == null) {
+ final LabelType labelType = this.registry.parseLabel(cType, ByteArray.cutBytes(buffer, HEADER_LENGTH));
+ if (labelType == null) {
throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
}
final LabelBuilder builder = new LabelBuilder();
builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
builder.setGlobal(reserved.get(G_FLAG_OFFSET));
- builder.setLabelType(parser.parseLabel(ByteArray.cutBytes(buffer, HEADER_LENGTH)));
+ builder.setLabelType(labelType);
return new SubobjectBuilder().setSubobjectType(new LabelCaseBuilder().setLabel(builder.build()).build()).build();
}
@Override
public byte[] serializeSubobject(final Subobject subobject) {
+ Preconditions.checkNotNull(subobject.getSubobjectType(), "Subobject type cannot be empty.");
final Label label = ((LabelCase) subobject.getSubobjectType()).getLabel();
- final LabelType l = label.getLabelType();
- final LabelSerializer parser = this.registry.getLabelSerializer(l);
- if (parser == null) {
- throw new IllegalArgumentException("Unknown RROLabelSubobject instance. Passed " + subobject.getSubobjectType().getClass());
+ final byte[] labelbytes = this.registry.serializeLabel(label.isUniDirectional(), false, label.getLabelType());
+ if (labelbytes == null) {
+ throw new IllegalArgumentException("Unknown EROLabelSubobject instance. Passed "
+ + label.getLabelType().getImplementedInterface());
}
- final byte[] labelbytes = parser.serializeLabel(l);
- final byte[] retBytes = new byte[labelbytes.length + HEADER_LENGTH];
- System.arraycopy(labelbytes, 0, retBytes, HEADER_LENGTH, labelbytes.length);
-
- final BitSet reserved = new BitSet();
- reserved.set(U_FLAG_OFFSET, label.isUniDirectional());
- reserved.set(G_FLAG_OFFSET, label.isGlobal());
- System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
- retBytes[C_TYPE_F_OFFSET] = UnsignedBytes.checkedCast(parser.getType());
- return RROSubobjectUtil.formatSubobject(TYPE, retBytes);
+ return RROSubobjectUtil.formatSubobject(TYPE, labelbytes);
}
@Override
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+import org.opendaylight.protocol.pcep.spi.LabelUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
}
@Override
- public byte[] serializeLabel(final LabelType subobject) {
+ public byte[] serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject) {
if (!(subobject instanceof Type1LabelCase)) {
throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass()
+ ". Needed Type1LabelCase.");
}
- return ByteArray.longToBytes(((Type1LabelCase) subobject).getType1Label().getType1Label().longValue(), LABEL_LENGTH);
+ return LabelUtil.formatLabel(CTYPE, unidirectional, global, ByteArray.longToBytes(((Type1LabelCase) subobject).getType1Label().getType1Label().longValue(), LABEL_LENGTH));
}
@Override
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+import org.opendaylight.protocol.pcep.spi.LabelUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
}
@Override
- public byte[] serializeLabel(final LabelType subobject) {
+ public byte[] serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject) {
if (!(subobject instanceof WavebandSwitchingLabelCase)) {
throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass()
+ ". Needed WavebandSwitchingLabelCase.");
System.arraycopy(ByteArray.intToBytes(obj.getStartLabel().intValue(), START_F_LENGTH), 0, retBytes, WAVEB_F_LENGTH, START_F_LENGTH);
System.arraycopy(ByteArray.intToBytes(obj.getEndLabel().intValue(), END_F_LENGTH), 0, retBytes, WAVEB_F_LENGTH + START_F_LENGTH,
END_F_LENGTH);
- return retBytes;
+ return LabelUtil.formatLabel(CTYPE, unidirectional, global, retBytes);
}
@Override
* 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;
+package org.opendaylight.protocol.pcep.impl.tlv;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.TlvParser;
+import org.opendaylight.protocol.pcep.spi.TlvSerializer;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
final byte[] bytes = new byte[ianaNumBytes.length + payloadBytes.length];
System.arraycopy(ianaNumBytes, 0, bytes, 0, ENTERPRISE_NUM_LENGTH);
System.arraycopy(payloadBytes, 0, bytes, ENTERPRISE_NUM_LENGTH, payloadBytes.length);
- return bytes;
+ return TlvUtil.formatTlv(TYPE, bytes);
}
return new byte[0];
}
import org.opendaylight.protocol.pcep.impl.subobject.Type1LabelParser;
import org.opendaylight.protocol.pcep.impl.subobject.WavebandSwitchingLabelParser;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1LabelCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.WavebandSwitchingLabelCaseBuilder;
public class LabelSubobjectParserTest {
- private static final byte[] generalizedLabelBytes = { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF };
+ private static final byte[] generalizedLabelBytes = { (byte) 0x80, 0x02, 0x00, 0x04, 0x12, 0x00, 0x25, (byte) 0xFF };
- private static final byte[] wavebandLabelBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x12, (byte) 0x34, (byte) 0x00, (byte) 0x00,
- (byte) 0x99, (byte) 0x99, (byte) 0x00, (byte) 0x00, (byte) 0x11, (byte) 0x11 };
+ private static final byte[] typeOneLabelBytes = { (byte) 0x81, 0x01, 0x12, 0x00, 0x25, (byte) 0xFF };
+
+ private static final byte[] wavebandLabelBytes = { 0x01, 0x03, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, (byte) 0x99, (byte) 0x99, 0x00, 0x00, 0x11, 0x11 };
@Test
public void testGeneralizedLabel() throws PCEPDeserializerException {
final GeneralizedLabelParser parser = new GeneralizedLabelParser();
final GeneralizedLabelBuilder iBuilder = new GeneralizedLabelBuilder();
- iBuilder.setGeneralizedLabel(generalizedLabelBytes);
+ iBuilder.setGeneralizedLabel(ByteArray.cutBytes(generalizedLabelBytes, 2));
final GeneralizedLabelCaseBuilder builder = new GeneralizedLabelCaseBuilder().setGeneralizedLabel(iBuilder.build());
- assertEquals(builder.build(), parser.parseLabel(generalizedLabelBytes));
- assertArrayEquals(generalizedLabelBytes, parser.serializeLabel(builder.build()));
+ assertEquals(builder.build(), parser.parseLabel(ByteArray.cutBytes(generalizedLabelBytes, 2)));
+ assertArrayEquals(generalizedLabelBytes, parser.serializeLabel(true, false, builder.build()));
}
@Test
iBuilder.setStartLabel(0x9999L);
iBuilder.setEndLabel(0x1111L);
final WavebandSwitchingLabelCaseBuilder builder = new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(iBuilder.build());
- assertEquals(builder.build(), parser.parseLabel(wavebandLabelBytes));
- assertArrayEquals(wavebandLabelBytes, parser.serializeLabel(builder.build()));
+ assertEquals(builder.build(), parser.parseLabel(ByteArray.cutBytes(wavebandLabelBytes, 2)));
+ assertArrayEquals(wavebandLabelBytes, parser.serializeLabel(false, true, builder.build()));
}
@Test
final Type1LabelBuilder iBuilder = new Type1LabelBuilder();
iBuilder.setType1Label(0x120025ffL);
final Type1LabelCaseBuilder builder = new Type1LabelCaseBuilder().setType1Label(iBuilder.build());
- assertEquals(builder.build(), parser.parseLabel(generalizedLabelBytes));
- assertArrayEquals(generalizedLabelBytes, parser.serializeLabel(builder.build()));
+ assertEquals(builder.build(), parser.parseLabel(ByteArray.cutBytes(typeOneLabelBytes, 2)));
+ assertArrayEquals(typeOneLabelBytes, parser.serializeLabel(true, true, builder.build()));
}
}
public class PCEPRROSubobjectParserTest {
private static final byte[] ip4PrefixBytes = { (byte) 0x01, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- (byte) 0x16, (byte) 0x01 };
+ (byte) 0x16, (byte) 0x01 };
private static final byte[] ip6PrefixBytes = { (byte) 0x02, (byte) 0x14, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x02 };
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x02 };
private static final byte[] unnumberedBytes = { (byte) 0x04, (byte) 0x0c, (byte) 0x02, (byte) 0x00, (byte) 0x12, (byte) 0x34,
- (byte) 0x50, (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+ (byte) 0x50, (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
private static final byte[] pathKey32Bytes = { (byte) 0x40, (byte) 0x08, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34,
- (byte) 0x50, (byte) 0x00 };
+ (byte) 0x50, (byte) 0x00 };
private static final byte[] pathKey128Bytes = { (byte) 0x41, (byte) 0x14, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34,
- (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
- private static final byte[] labelBytes = { (byte) 0x03, (byte) 0x08, (byte) 0x81, (byte) 0x02, (byte) 0x12, (byte) 0x00, (byte) 0x25,
- (byte) 0xFF };
+ (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
+ private static final byte[] labelBytes = { 0x03, 0x08, (byte) 0x80, 0x02, 0x12, 0x00, 0x25, (byte) 0xFF };
@Test
public void testRROIp4PrefixSubobject() throws PCEPDeserializerException {
final RROLabelSubobjectParser parser = new RROLabelSubobjectParser(ctx.getLabelHandlerRegistry());
final SubobjectBuilder subs = new SubobjectBuilder();
subs.setSubobjectType(new LabelCaseBuilder().setLabel(
- new LabelBuilder().setUniDirectional(true).setGlobal(true).setLabelType(
+ new LabelBuilder().setUniDirectional(true).setGlobal(false).setLabelType(
new GeneralizedLabelCaseBuilder().setGeneralizedLabel(
new GeneralizedLabelBuilder().setGeneralizedLabel(
new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF }).build()).build()).build()).build());
private static final int P_FLAG_OFFSET = 6;
private static final int I_FLAG_OFFSET = 7;
- private final ObjectHandlerRegistry registry;
+ private final ObjectRegistry registry;
- protected AbstractMessageParser(final ObjectHandlerRegistry registry) {
+ protected AbstractMessageParser(final ObjectRegistry registry) {
this.registry = Preconditions.checkNotNull(registry);
}
if (object == null) {
return new byte[] {};
}
- final ObjectSerializer serializer = this.registry.getObjectSerializer(object);
- LOG.trace("Choosen serializer {}", serializer);
- return serializer.serializeObject(object);
+ return this.registry.serializeObject(object);
}
private List<Object> parseObjects(final byte[] bytes) throws PCEPDeserializerException {
offset += objLength - COMMON_OBJECT_HEADER_LENGTH;
- final ObjectParser parser = Preconditions.checkNotNull(this.registry.getObjectParser(objClass, objType));
final ObjectHeader header = new ObjectHeaderImpl(flags.get(P_FLAG_OFFSET), flags.get(I_FLAG_OFFSET));
// parseObject is required to return null for P=0 errored objects
- final Object o = parser.parseObject(header, bytesToPass);
+ final Object o = this.registry.parseObject(objClass, objType, header, bytesToPass);
if (o != null) {
objs.add(o);
}
new PcerrMessageBuilder().setErrorType(
new RequestCaseBuilder().setRequest(
new RequestBuilder().setRps(Lists.newArrayList(new RpsBuilder().setRp(rp).build())).build()).build()).setErrors(
- Arrays.asList(new ErrorsBuilder().setErrorObject(
- new ErrorObjectBuilder().setType(maping.getFromErrorsEnum(e).type).setValue(
- maping.getFromErrorsEnum(e).value).build()).build())).build()).build();
+ Arrays.asList(new ErrorsBuilder().setErrorObject(
+ new ErrorObjectBuilder().setType(maping.getFromErrorsEnum(e).type).setValue(
+ maping.getFromErrorsEnum(e).value).build()).build())).build()).build();
}
protected abstract Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException;
+++ /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.label.subobject.LabelType;
-
-public interface LabelHandlerRegistry {
- LabelParser getLabelParser(int cType);
- LabelSerializer getLabelSerializer(LabelType label);
-}
--- /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.label.subobject.LabelType;
+
+public interface LabelRegistry {
+ /**
+ * Finds parser for given label C-type in the registry. Delegates parsing to found parser.
+ * @param cType label type, key in parser registry
+ * @param buffer label raw binary value to be parsed
+ * @return null if the parser for this label could not be found
+ * @throws PCEPDeserializerException if the parsing did not succeed
+ */
+ LabelType parseLabel(final int cType, final byte[] buffer) throws PCEPDeserializerException;
+
+ /**
+ * Find serializer for given label. Delegates parsing to found serializer.
+ * @param label to be parsed
+ * @param unidirectional label common header flag
+ * @param global label commom header flag
+ * @return null if the serializer for this label could not be found
+ */
+ byte[] serializeLabel(final boolean unidirectional, final boolean global, final LabelType label);
+}
public interface LabelSerializer {
@Deprecated
int getType();
- byte[] serializeLabel(LabelType subobject);
+ byte[] serializeLabel(boolean unidirectional, boolean global, LabelType subobject);
}
--- /dev/null
+/*
+ * Copyright (c) 2014 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 java.util.BitSet;
+
+import org.opendaylight.protocol.util.ByteArray;
+
+import com.google.common.primitives.UnsignedBytes;
+
+public class LabelUtil {
+
+ private static final int RES_F_LENGTH = 1;
+
+ private static final int C_TYPE_F_LENGTH = 1;
+
+ private static final int RES_F_OFFSET = 0;
+
+ private static final int C_TYPE_F_OFFSET = RES_F_OFFSET + RES_F_LENGTH;
+
+ private static final int HEADER_LENGTH = C_TYPE_F_OFFSET + C_TYPE_F_LENGTH;
+
+ private static final int U_FLAG_OFFSET = 0;
+
+ private static final int G_FLAG_OFFSET = 7;
+
+ private LabelUtil() {
+
+ }
+
+ public static byte[] formatLabel(final int type, final boolean unidirectional, final boolean global, final byte[] labelbytes) {
+
+ final byte[] retBytes = new byte[labelbytes.length + HEADER_LENGTH];
+
+ System.arraycopy(labelbytes, 0, retBytes, HEADER_LENGTH, labelbytes.length);
+
+ final BitSet reserved = new BitSet();
+ reserved.set(U_FLAG_OFFSET, unidirectional);
+ reserved.set(G_FLAG_OFFSET, global);
+ System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
+ retBytes[C_TYPE_F_OFFSET] = UnsignedBytes.checkedCast(type);
+ return retBytes;
+ }
+}
+++ /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.Object;
-
-public interface ObjectHandlerRegistry {
- ObjectParser getObjectParser(int objectClass, int objectType);
- ObjectSerializer getObjectSerializer(Object object);
-}
--- /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.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
+
+public interface ObjectRegistry {
+ /**
+ * Finds parser for given object type and class in the registry. Delegates parsing to found parser.
+ * @param objectType object type
+ * @param objectClass object class
+ * @param buffer object raw binary value to be parsed
+ * @return null if the parser for this object could not be found
+ * @throws PCEPDeserializerException if the parsing did not succeed
+ */
+ Object parseObject(final int objectClass, final int objectType, final ObjectHeader header, final byte[] buffer) throws PCEPDeserializerException;
+
+ /**
+ * Find serializer for given object. Delegates parsing to found serializer.
+ * @param object to be parsed
+ * @return null if the serializer for this object could not be found
+ */
+ byte[] serializeObject(Object object);
+}
public interface PCEPExtensionConsumerContext {
- LabelHandlerRegistry getLabelHandlerRegistry();
+ LabelRegistry getLabelHandlerRegistry();
MessageHandlerRegistry getMessageHandlerRegistry();
- ObjectHandlerRegistry getObjectHandlerRegistry();
+ ObjectRegistry getObjectHandlerRegistry();
EROSubobjectRegistry getEROSubobjectHandlerRegistry();
package org.opendaylight.protocol.pcep.spi.pojo;
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.LabelRegistry;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+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.rsvp.rev130820.label.subobject.LabelType;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import com.google.common.base.Preconditions;
-public class SimpleLabelHandlerRegistry implements LabelHandlerRegistry {
+public class SimpleLabelRegistry implements LabelRegistry {
private final HandlerRegistry<DataContainer, LabelParser, LabelSerializer> handlers = new HandlerRegistry<>();
public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
}
@Override
- public LabelParser getLabelParser(final int cType) {
+ public LabelType parseLabel(int cType, byte[] buffer) throws PCEPDeserializerException {
Preconditions.checkArgument(cType >= 0 && cType <= Values.UNSIGNED_BYTE_MAX_VALUE);
- return this.handlers.getParser(cType);
+ final LabelParser parser = this.handlers.getParser(cType);
+ if (parser == null) {
+ return null;
+ }
+ return parser.parseLabel(buffer);
}
@Override
- public LabelSerializer getLabelSerializer(final LabelType label) {
- return this.handlers.getSerializer(label.getImplementedInterface());
+ public byte[] serializeLabel(final boolean unidirectional, final boolean global, final LabelType label) {
+ final LabelSerializer serializer = this.handlers.getSerializer(label.getImplementedInterface());
+ if (serializer == null) {
+ return null;
+ }
+ return serializer.serializeLabel(unidirectional, global, label);
}
}
package org.opendaylight.protocol.pcep.spi.pojo;
import org.opendaylight.protocol.concepts.HandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.protocol.pcep.spi.UnknownObject;
import org.opendaylight.protocol.util.Values;
/**
*
*/
-public final class SimpleObjectHandlerRegistry implements ObjectHandlerRegistry {
+public final class SimpleObjectRegistry implements ObjectRegistry {
private final HandlerRegistry<DataContainer, ObjectParser, ObjectSerializer> handlers = new HandlerRegistry<>();
private static int createKey(final int objectClass, final int objectType) {
}
@Override
- public ObjectParser getObjectParser(final int objectClass, final int objectType) {
- final ObjectParser ret = this.handlers.getParser(createKey(objectClass, objectType));
- if (ret != null) {
- return ret;
- }
+ public Object parseObject(int objectClass, int objectType, ObjectHeader header, byte[] buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(objectType >= 0 && objectType <= Values.UNSIGNED_SHORT_MAX_VALUE);
+ final ObjectParser parser = this.handlers.getParser(createKey(objectClass, objectType));
+
+ if (parser == null) {
- final boolean foundClass = false;
+ final boolean foundClass = false;
- // FIXME: BUG-187: search the parsers, check classes
+ // FIXME: BUG-187: search the parsers, check classes
- if (!foundClass) {
- return new ObjectParser() {
- @Override
- public Object parseObject(final ObjectHeader header, final byte[] buffer) {
- return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
- }
- };
- } else {
- return new ObjectParser() {
- @Override
- public Object parseObject(final ObjectHeader header, final byte[] buffer) {
- return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
- }
- };
+ if (!foundClass) {
+ return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
+ } else {
+ return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
+ }
}
+ return parser.parseObject(header, buffer);
}
@Override
- public ObjectSerializer getObjectSerializer(final Object object) {
- return this.handlers.getSerializer(object.getImplementedInterface());
+ public byte[] serializeObject(Object object) {
+ final ObjectSerializer serializer = this.handlers.getSerializer(object.getImplementedInterface());
+ if (serializer == null) {
+ return null;
+ }
+ return serializer.serializeObject(object);
}
}
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;
+import org.opendaylight.protocol.pcep.spi.LabelRegistry;
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.MessageParser;
import org.opendaylight.protocol.pcep.spi.MessageSerializer;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.ObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
*/
@ThreadSafe
public class SimplePCEPExtensionProviderContext implements PCEPExtensionProviderContext {
- private final SimpleLabelHandlerRegistry labelReg = new SimpleLabelHandlerRegistry();
+ private final SimpleLabelRegistry labelReg = new SimpleLabelRegistry();
private final SimpleMessageHandlerRegistry msgReg = new SimpleMessageHandlerRegistry();
- private final SimpleObjectHandlerRegistry objReg = new SimpleObjectHandlerRegistry();
+ private final SimpleObjectRegistry objReg = new SimpleObjectRegistry();
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 LabelHandlerRegistry getLabelHandlerRegistry() {
+ public final LabelRegistry getLabelHandlerRegistry() {
return this.labelReg;
}
}
@Override
- public final ObjectHandlerRegistry getObjectHandlerRegistry() {
+ public final ObjectRegistry getObjectHandlerRegistry() {
return this.objReg;
}
// Build the request and send it
final UpdatesBuilder rb = new UpdatesBuilder();
- rb.setLsp(new LspBuilder().setRemove(Boolean.TRUE).setPlspId(ra.getLsp().getPlspId()).setDelegate(Boolean.TRUE).build());
+ rb.setLsp(new LspBuilder().setRemove(Boolean.TRUE).setPlspId(ra.getLsp().getPlspId()).setDelegate(ra.getLsp().isDelegate()).build());
final PcupdMessageBuilder ib = new PcupdMessageBuilder(MESSAGE_HEADER);
ib.setUpdates(ImmutableList.of(rb.build()));
// Build the PCUpd request and send it
final UpdatesBuilder rb = new UpdatesBuilder();
- rb.setLsp(new LspBuilder().setPlspId(ra.getLsp().getPlspId()).setDelegate(Boolean.TRUE).setOperational(input.getArguments().getAugmentation(Arguments2.class).isOperational()).build());
+ rb.setLsp(new LspBuilder().setPlspId(ra.getLsp().getPlspId()).setDelegate(ra.getLsp().isDelegate()).setOperational(input.getArguments().getAugmentation(Arguments2.class).isOperational()).build());
final PathBuilder pb = new PathBuilder();
rb.setPath(pb.setEro(input.getArguments().getEro()).build());
pb.fieldsFrom(input.getArguments());
final RequestsBuilder rb = new RequestsBuilder();
rb.fieldsFrom(input.getArguments());
rb.setSrp(new SrpBuilder().setOperationId(nextRequest()).setProcessingRule(Boolean.TRUE).build());
- rb.setLsp(new LspBuilder().setAdministrative(input.getArguments().isAdministrative()).setDelegate(Boolean.TRUE).setPlspId(
+ rb.setLsp(new LspBuilder().setAdministrative(input.getArguments().isAdministrative()).setDelegate(rb.getLsp().isDelegate()).setPlspId(
new PlspId(0L)).setTlvs(
new TlvsBuilder().setSymbolicPathName(
new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(input.getName().getBytes(Charsets.UTF_8))).build()).build()).build());
// Build the request and send it
final RequestsBuilder rb = new RequestsBuilder();
rb.setSrp(new SrpBuilder().setOperationId(nextRequest()).setProcessingRule(Boolean.TRUE).build());
- rb.setLsp(new LspBuilder().setRemove(Boolean.TRUE).setPlspId(ra.getLsp().getPlspId()).setDelegate(Boolean.TRUE).build());
+ rb.setLsp(new LspBuilder().setRemove(Boolean.TRUE).setPlspId(ra.getLsp().getPlspId()).setDelegate(ra.getLsp().isDelegate()).build());
final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(MESSAGE_HEADER);
ib.setRequests(ImmutableList.of(rb.build()));
// Build the PCUpd request and send it
final UpdatesBuilder rb = new UpdatesBuilder();
rb.setSrp(new SrpBuilder().setOperationId(nextRequest()).setProcessingRule(Boolean.TRUE).build());
- rb.setLsp(new LspBuilder().setPlspId(ra.getLsp().getPlspId()).setDelegate(Boolean.TRUE).build());
+ rb.setLsp(new LspBuilder().setPlspId(ra.getLsp().getPlspId()).setDelegate(ra.getLsp().isDelegate()).build());
final PathBuilder pb = new PathBuilder();
rb.setPath(pb.setEro(input.getArguments().getEro()).build());
pb.fieldsFrom(input.getArguments());
<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>tcpmd5-parent</artifactId>
- <version>0.3.1-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>tcpmd5-parent</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>tcpmd5-core</artifactId>
- <description>RFC2385-enable sockets</description>
- <packaging>bundle</packaging>
- <name>${project.artifactId}</name>
- <prerequisites>
- <maven>3.0.4</maven>
- </prerequisites>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>tcpmd5-core</artifactId>
+ <description>RFC2385-enable sockets</description>
+ <packaging>bundle</packaging>
+ <name>${project.artifactId}</name>
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
<dependencies>
<dependency>
</plugin>
</plugins>
</build>
-
- <distributionManagement>
- <site>
- <id>${project.artifactId}</id>
- <name>TCPMD5-CORE Module site</name>
- <url>${basedir}/target/site/${project.artifactId}</url>
- </site>
- </distributionManagement>
</project>
</plugins>
</pluginManagement>
</build>
-
- <pluginRepositories>
- <pluginRepository>
- <id>imagej.thirdparty</id>
- <url>http://maven.imagej.net/content/repositories/thirdparty</url>
- </pluginRepository>
- </pluginRepositories>
-
- <distributionManagement>
- <site>
- <id>${project.artifactId}</id>
- <name>TCPMD5-JNI Module site</name>
- <url>${basedir}/target/site/${project.artifactId}</url>
- </site>
- </distributionManagement>
</project>