}
}
+ grouping vendor-information-objects {
+ list vendor-information-object {
+ description "VENDOR-INFORMATION-OBJECT";
+ reference "http://tools.ietf.org/html/draft-ietf-pce-rfc7150bis-00#section-2";
+ uses object;
+ uses vendor-information;
+ }
+ }
+
grouping open-object {
description "OPEN Object";
reference "https://tools.ietf.org/html/rfc5440#section-7.3";
uses bandwidth-object;
}
+ uses vendor-information-objects;
+
uses load-balancing-object;
uses lsp-attributes;
}
}
+
+ uses vendor-information-objects;
}
list svec {
list metric {
uses metric-object;
}
+
+ uses vendor-information-objects;
}
}
}
list replies {
uses rp-object;
+ uses vendor-information-objects;
choice result {
case success-case {
list paths {
uses path-definition;
}
+ uses vendor-information-objects;
}
}
case failure-case {
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.List;
-
import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.protocol.pcep.spi.VendorInformationObjectRegistry;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.object.Lsp;
*/
public final class Stateful02PCReplyMessageParser extends PCEPReplyMessageParser {
- public Stateful02PCReplyMessageParser(final ObjectRegistry registry) {
- super(registry);
+ public Stateful02PCReplyMessageParser(final ObjectRegistry registry, final VendorInformationObjectRegistry viReg) {
+ super(registry, viReg);
}
@Override
import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.protocol.pcep.spi.VendorInformationObjectRegistry;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.object.Lsp;
*/
public final class Stateful02PCRequestMessageParser extends PCEPRequestMessageParser {
- public Stateful02PCRequestMessageParser(final ObjectRegistry registry) {
- super(registry);
+ public Stateful02PCRequestMessageParser(final ObjectRegistry registry, final VendorInformationObjectRegistry viReg) {
+ super(registry, viReg);
}
@Override
regs.add(context.registerMessageSerializer(Pcrpt.class, new Stateful02PCReportMessageParser(context.getObjectHandlerRegistry())));
regs.add(context.registerMessageParser(Stateful02PCReplyMessageParser.TYPE,
- new Stateful02PCReplyMessageParser(context.getObjectHandlerRegistry())));
- regs.add(context.registerMessageSerializer(Pcrep.class, new Stateful02PCReplyMessageParser(context.getObjectHandlerRegistry())));
+ new Stateful02PCReplyMessageParser(context.getObjectHandlerRegistry(), context.getVendorInformationObjectRegistry())));
+ regs.add(context.registerMessageSerializer(Pcrep.class, new Stateful02PCReplyMessageParser(context.getObjectHandlerRegistry(),
+ context.getVendorInformationObjectRegistry())));
regs.add(context.registerMessageParser(Stateful02PCRequestMessageParser.TYPE,
- new Stateful02PCRequestMessageParser(context.getObjectHandlerRegistry())));
- regs.add(context.registerMessageSerializer(Pcreq.class, new Stateful02PCRequestMessageParser(context.getObjectHandlerRegistry())));
+ new Stateful02PCRequestMessageParser(context.getObjectHandlerRegistry(),
+ context.getVendorInformationObjectRegistry())));
+ regs.add(context.registerMessageSerializer(Pcreq.class, new Stateful02PCRequestMessageParser(context.getObjectHandlerRegistry(),
+ context.getVendorInformationObjectRegistry())));
regs.add(context.registerObjectParser(Stateful02LspObjectParser.CLASS, Stateful02LspObjectParser.TYPE,
new Stateful02LspObjectParser(context.getTlvHandlerRegistry(), context.getVendorInformationTlvRegistry())));
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.VendorInformationObjectRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close;
registerObjectParsers(regs, context);
final ObjectRegistry objReg = context.getObjectHandlerRegistry();
+ final VendorInformationObjectRegistry viObjReg = context.getVendorInformationObjectRegistry();
final PCEPOpenMessageParser openParser = new PCEPOpenMessageParser(objReg);
regs.add(context.registerMessageParser(PCEPOpenMessageParser.TYPE, openParser));
regs.add(context.registerMessageSerializer(
regs.add(context.registerMessageParser(PCEPKeepAliveMessageParser.TYPE, kaParser));
regs.add(context.registerMessageSerializer(Keepalive.class, kaParser));
- final PCEPRequestMessageParser reqParser = new PCEPRequestMessageParser(objReg);
+ final PCEPRequestMessageParser reqParser = new PCEPRequestMessageParser(objReg, viObjReg);
regs.add(context.registerMessageParser(PCEPRequestMessageParser.TYPE, reqParser));
regs.add(context.registerMessageSerializer(Pcreq.class, reqParser));
- final PCEPReplyMessageParser repParser = new PCEPReplyMessageParser(objReg);
+ final PCEPReplyMessageParser repParser = new PCEPReplyMessageParser(objReg, viObjReg);
regs.add(context.registerMessageParser(PCEPReplyMessageParser.TYPE, repParser));
regs.add(context.registerMessageSerializer(Pcrep.class, repParser));
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.VendorInformationObjectRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcrep;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcrepBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.Paths;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
/**
* Parser for {@link Pcrep}
public static final int TYPE = 4;
- public PCEPReplyMessageParser(final ObjectRegistry registry) {
- super(registry);
+ public PCEPReplyMessageParser(final ObjectRegistry registry, final VendorInformationObjectRegistry viRegistry) {
+ super(registry, viRegistry);
}
@Override
protected void serializeReply(final Replies reply, final ByteBuf buffer) {
serializeObject(reply.getRp(), buffer);
+ serializeVendorInformationObjects(reply.getVendorInformationObject(), buffer);
if (reply.getResult() != null) {
if (reply.getResult() instanceof FailureCase) {
final FailureCase f = ((FailureCase) reply.getResult());
serializeObject(p.getIro(), buffer);
}
}
+ serializeVendorInformationObjects(s.getSuccess().getVendorInformationObject(), buffer);
}
}
}
}
final Rp rp = (Rp) objects.get(0);
objects.remove(0);
+ final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
Result res = null;
if (!objects.isEmpty()) {
if (objects.get(0) instanceof NoPath) {
final PathsBuilder pBuilder = new PathsBuilder();
pBuilder.setEro(ero);
while (!objects.isEmpty()) {
+ final List<VendorInformationObject> vendorInfoObjects = addVendorInformationObjects(objects);
+ if (!vendorInfoObjects.isEmpty()) {
+ builder.setVendorInformationObject(vendorInfoObjects);
+ }
this.parsePath(pBuilder, objects);
paths.add(pBuilder.build());
}
res = new SuccessCaseBuilder().setSuccess(builder.build()).build();
}
}
- return new RepliesBuilder().setRp(rp).setResult(res).build();
+ final RepliesBuilder builder = new RepliesBuilder();
+ if (!vendorInfo.isEmpty()) {
+ builder.setVendorInformationObject(vendorInfo);
+ }
+ return builder.setRp(rp).setResult(res).build();
}
protected void parseAttributes(final FailureCaseBuilder builder, final List<Object> objects) {
objects.remove(0);
}
}
- builder.setMetrics(pathMetrics);
+ if (!pathMetrics.isEmpty()) {
+ builder.setMetrics(pathMetrics);
+ }
}
protected void parsePath(final PathsBuilder builder, final List<Object> objects) {
objects.remove(0);
}
}
- builder.setMetrics(pathMetrics);
+ if (!pathMetrics.isEmpty()) {
+ builder.setMetrics(pathMetrics);
+ }
}
private enum State {
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.VendorInformationObjectRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcreq;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcreqBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.ReportedRouteBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Rro;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
/**
* Parser for {@link Pcreq}
public static final int TYPE = 3;
- public PCEPRequestMessageParser(final ObjectRegistry registry) {
- super(registry);
+ public PCEPRequestMessageParser(final ObjectRegistry registry, final VendorInformationObjectRegistry viRegistry) {
+ super(registry, viRegistry);
}
@Override
final ByteBuf buffer = Unpooled.buffer();
for (final Requests req : msg.getRequests()) {
serializeObject(req.getRp(), buffer);
+ serializeVendorInformationObjects(req.getVendorInformationObject(), buffer);
if (req.getPathKeyExpansion() != null) {
serializeObject(req.getPathKeyExpansion().getPathKey(), buffer);
}
serializeObject(m.getMetric(), buffer);
}
}
+ serializeVendorInformationObjects(s.getVendorInformationObject(), buffer);
}
}
MessageUtil.formatMessage(TYPE, buffer, out);
if (p2p.getEndpointsObj() != null) {
serializeObject(p2p.getEndpointsObj(), buffer);
}
+ serializeVendorInformationObjects(p2p.getVendorInformationObject(), buffer);
if (p2p.getReportedRoute() != null) {
final ReportedRoute rr = p2p.getReportedRoute();
if (rr.getRro() != null) {
errors.add(createErrorMsg(PCEPErrors.RP_MISSING));
return null;
}
-
+ final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
+ if (!vendorInfo.isEmpty()) {
+ rBuilder.setVendorInformationObject(vendorInfo);
+ }
// expansion
if (rpObj.isPathKey()) {
if (objects.get(0) instanceof PathKey) {
protected SegmentComputation getSegmentComputation(final P2pBuilder builder, final List<Object> objects, final List<Message> errors,
final Rp rp) {
final List<Metrics> metrics = Lists.newArrayList();
+ final List<VendorInformationObject> viObjects = Lists.newArrayList();
State state = State.Init;
while (!objects.isEmpty() && state != State.End) {
break;
}
case ReportedIn:
+ state = State.VendorInfoList;
+ if (obj instanceof VendorInformationObject) {
+ viObjects.add((VendorInformationObject) obj);
+ state = State.ReportedIn;
+ break;
+ }
+ case VendorInfoList:
state = State.LoadBIn;
if (obj instanceof LoadBalancing) {
builder.setLoadBalancing((LoadBalancing) obj);
if (!metrics.isEmpty()) {
builder.setMetrics(metrics);
}
+ if (!viObjects.isEmpty()) {
+ builder.setVendorInformationObject(viObjects);
+ }
if (rp.isReoptimization()
&& builder.getBandwidth() != null
}
private enum State {
- Init, ReportedIn, LoadBIn, LspaIn, BandwidthIn, MetricIn, IroIn, RroIn, XroIn, OfIn, CtIn, End
+ Init, ReportedIn, VendorInfoList, LoadBIn, LspaIn, BandwidthIn, MetricIn, IroIn, RroIn, XroIn, OfIn, CtIn, End
}
private Svec getValidSvec(final SvecBuilder builder, final List<Object> objects) {
}
final List<Metrics> metrics = Lists.newArrayList();
+ final List<VendorInformationObject> viObjects = Lists.newArrayList();
Object obj = null;
SvecState state = SvecState.Init;
break;
}
case MetricIn:
+ state = SvecState.VendorInfo;
+ if (obj instanceof VendorInformationObject) {
+ viObjects.add((VendorInformationObject) obj);
+ state = SvecState.MetricIn;
+ break;
+ }
+ case VendorInfo:
state = SvecState.End;
break;
case End:
objects.remove(0);
}
}
+ if (!viObjects.isEmpty()) {
+ builder.setVendorInformationObject(viObjects);
+ }
return builder.build();
}
private enum SvecState {
- Init, OfIn, GcIn, XroIn, MetricIn, End
+ Init, OfIn, GcIn, XroIn, MetricIn, VendorInfo, End
}
}
--- /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.impl.object;
+
+import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS;
+import static org.opendaylight.protocol.pcep.spi.VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+
+import com.google.common.base.Preconditions;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+import org.opendaylight.protocol.pcep.spi.EnterpriseSpecificInformationParser;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+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.iana.rev130816.EnterpriseNumber;
+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.vendor.information.objects.VendorInformationObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObjectBuilder;
+
+public abstract class AbstractVendorInformationObjectParser implements ObjectSerializer, ObjectParser, EnterpriseSpecificInformationParser {
+
+ @Override
+ public final Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final VendorInformationObjectBuilder builder = new VendorInformationObjectBuilder();
+ buffer.readUnsignedInt();
+ builder.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()));
+ builder.setEnterpriseSpecificInformation(parseEnterpriseSpecificInformation(buffer));
+ return builder.build();
+ }
+
+ @Override
+ public final void serializeObject(final Object object, final ByteBuf buffer) {
+ Preconditions.checkArgument(object instanceof VendorInformationObject, "Wrong instance of PCEPObject. Passed %s. Needed VendorInformationObject.", object.getClass());
+ final ByteBuf body = Unpooled.buffer();
+ writeUnsignedInt(getEnterpriseNumber().getValue(), body);
+ serializeEnterpriseSpecificInformation(((VendorInformationObject) object).getEnterpriseSpecificInformation(), body);
+ ObjectUtil.formatSubobject(VENDOR_INFORMATION_OBJECT_TYPE, VENDOR_INFORMATION_OBJECT_CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+ }
+
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
parser.serializeObject(builder.build(), buf);
assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
}
+
+ @Test
+ public void testVendorInformationObject() throws PCEPDeserializerException {
+ final byte[] viObjBytes = {
+ /* vendor-information object */
+ 0x22, 0x10, 0x00, 0x0C,
+ /* enterprise number */
+ 0x00, 0x00, 0x00, 0x00,
+ /* enterprise specific information */
+ 0x00, 0x00, 0x00, 0x05
+ };
+ final TestVendorInformationObjectParser parser = new TestVendorInformationObjectParser();
+ final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
+ final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
+ .setEnterpriseSpecificInformation(esInfo).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(viObjBytes);
+
+ assertEquals(viObj, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(viObjBytes.length);
+ parser.serializeObject(viObj, buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+ }
}
import java.util.List;
import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation;
import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.VendorInformationObjectRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+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.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.CloseBuilder;
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.rp.object.RpBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
public class PCEPValidatorTest {
private ObjectRegistry objectRegistry;
+ private VendorInformationObjectRegistry viObjRegistry;
private Open open;
private Rp rpTrue;
private Of of;
private EndpointsObj endpoints;
private Svec svec;
+ private List<VendorInformationObject> viObjects;
private AsNumberCase eroASSubobject;
private SimplePCEPExtensionProviderContext ctx;
private Activator act;
+ private TestVendorInformationActivator viObjAct;
@Before
public void setUp() throws Exception {
this.ctx = new SimplePCEPExtensionProviderContext();
this.act = new Activator();
+ this.viObjAct = new TestVendorInformationActivator();
this.act.start(this.ctx);
+ this.viObjAct.start(this.ctx);
this.objectRegistry = this.ctx.getObjectHandlerRegistry();
+ this.viObjRegistry = this.ctx.getVendorInformationObjectRegistry();
final RpBuilder rpBuilder = new RpBuilder();
rpBuilder.setProcessingRule(true);
rpBuilder.setIgnore(false);
sBuilder.setSrlgDiverse(false);
sBuilder.setRequestsIds(Lists.newArrayList(new RequestId(1L)));
this.svec = sBuilder.build();
+
+ this.viObjects = Lists.newArrayList();
+ final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
+ final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
+ .setEnterpriseSpecificInformation(esInfo).build();
+ this.viObjects.add(viObj);
}
@Test
public void testRequestMsg() throws IOException, PCEPDeserializerException {
ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRequestMessage1.bin"));
- final PCEPRequestMessageParser parser = new PCEPRequestMessageParser(this.objectRegistry);
+ final PCEPRequestMessageParser parser = new PCEPRequestMessageParser(this.objectRegistry, this.viObjRegistry);
final PcreqMessageBuilder builder = new PcreqMessageBuilder();
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests> reqs1 = Lists.newArrayList();
// only RP
ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.1.bin"));
- final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
+ final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry, this.viObjRegistry);
final PcrepMessageBuilder builder = new PcrepMessageBuilder();
RepliesBuilder rBuilder = new RepliesBuilder();
parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
}
+
+ @Test
+ public void testReqMsgWithVendorInfoObjects() throws IOException, PCEPDeserializerException {
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCReq.7.bin"));
+ final PCEPRequestMessageParser parser = new PCEPRequestMessageParser(this.objectRegistry, this.viObjRegistry);
+
+ final PcreqMessageBuilder builder = new PcreqMessageBuilder();
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests> reqs1 = Lists.newArrayList();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder rBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder();
+ rBuilder.setRp(this.rpTrue);
+ rBuilder.setVendorInformationObject(this.viObjects);
+ final SegmentComputationBuilder sBuilder = new SegmentComputationBuilder();
+ sBuilder.setP2p(new P2pBuilder().setEndpointsObj(this.endpoints).setVendorInformationObject(this.viObjects).build());
+ rBuilder.setSegmentComputation(sBuilder.build());
+ reqs1.add(rBuilder.build());
+ builder.setSvec(Lists.newArrayList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder().setSvec(
+ this.svec).setVendorInformationObject(this.viObjects).build()));
+ builder.setRequests(reqs1);
+
+ assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4,
+ result.readableBytes() - 4), Collections.<Message> emptyList()));
+ ByteBuf buf = Unpooled.buffer(result.readableBytes());
+ parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);
+
+ assertArrayEquals(result.array(), buf.array());
+ }
+
+ @Test
+ public void testRepMsgWithVendorInforObjects() throws IOException, PCEPDeserializerException {
+ final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry, this.viObjRegistry);
+
+ final PcrepMessageBuilder builder = new PcrepMessageBuilder();
+ RepliesBuilder rBuilder = new RepliesBuilder();
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.6.bin"));
+ final List<Replies> replies = Lists.newArrayList();
+ rBuilder = new RepliesBuilder();
+ rBuilder.setRp(this.rpTrue);
+ rBuilder.setVendorInformationObject(this.viObjects);
+ final List<Paths> paths = Lists.newArrayList();
+ final PathsBuilder paBuilder = new PathsBuilder();
+ paBuilder.setEro(this.ero);
+ paths.add(paBuilder.build());
+ rBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).setVendorInformationObject(this.viObjects).build()).build()).build();
+ replies.add(rBuilder.build());
+ builder.setReplies(replies);
+
+ assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4,
+ result.readableBytes() - 4), Collections.<Message> emptyList()));
+ final ByteBuf buf = Unpooled.buffer(result.readableBytes());
+ parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
+ assertArrayEquals(result.array(), buf.array());
+ }
}
final TestVendorInformationTlvParser parser = new TestVendorInformationTlvParser();
regs.add(context.registerVendorInformationTlvParser(parser.getEnterpriseNumber(), parser));
regs.add(context.registerVendorInformationTlvSerializer(TestEnterpriseSpecificInformation.class, parser));
+
+ // Vendor-information object registration
+ final TestVendorInformationObjectParser objParser = new TestVendorInformationObjectParser();
+ regs.add(context.registerVendorInformationObjectParser(parser.getEnterpriseNumber(), objParser));
+ regs.add(context.registerVendorInformationObjectSerializer(TestEnterpriseSpecificInformation.class, objParser));
return regs;
}
--- /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.impl;
+
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation;
+import org.opendaylight.protocol.pcep.impl.object.AbstractVendorInformationObjectParser;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+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.vendor.information.EnterpriseSpecificInformation;
+
+public class TestVendorInformationObjectParser extends AbstractVendorInformationObjectParser {
+
+ private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(0L);
+
+ @Override
+ public void serializeEnterpriseSpecificInformation(final EnterpriseSpecificInformation enterpriseSpecificInformation,
+ final ByteBuf buffer) {
+ buffer.writeInt(((TestEnterpriseSpecificInformation) enterpriseSpecificInformation).getValue());
+ }
+
+ @Override
+ public EnterpriseSpecificInformation parseEnterpriseSpecificInformation(final ByteBuf buffer)
+ throws PCEPDeserializerException {
+ return new TestEnterpriseSpecificInformation(buffer.readInt());
+ }
+
+ @Override
+ public EnterpriseNumber getEnterpriseNumber() {
+ return TEST_ENTERPRISE_NUMBER;
+ }
+
+}
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.VendorInformationObjectRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Pcinitiate;
/* Messages */
final ObjectRegistry objRegistry = context.getObjectHandlerRegistry();
- regs.add(context.registerMessageParser(SrPcRepMessageParser.TYPE, new SrPcRepMessageParser(objRegistry)));
+ final VendorInformationObjectRegistry objReg = context.getVendorInformationObjectRegistry();
+ regs.add(context.registerMessageParser(SrPcRepMessageParser.TYPE, new SrPcRepMessageParser(objRegistry, objReg)));
regs.add(context.registerMessageParser(SrPcInitiateMessageParser.TYPE, new SrPcInitiateMessageParser(
objRegistry)));
regs.add(context.registerMessageParser(SrPcRptMessageParser.TYPE, new SrPcRptMessageParser(objRegistry)));
regs.add(context.registerMessageParser(SrPcUpdMessageParser.TYPE, new SrPcUpdMessageParser(objRegistry)));
- regs.add(context.registerMessageSerializer(Pcrep.class, new SrPcRepMessageParser(objRegistry)));
+ regs.add(context.registerMessageSerializer(Pcrep.class, new SrPcRepMessageParser(objRegistry, objReg)));
regs.add(context.registerMessageSerializer(Pcinitiate.class, new SrPcInitiateMessageParser(objRegistry)));
regs.add(context.registerMessageSerializer(Pcrpt.class, new SrPcRptMessageParser(objRegistry)));
regs.add(context.registerMessageSerializer(Pcupd.class, new SrPcUpdMessageParser(objRegistry)));
import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.protocol.pcep.spi.VendorInformationObjectRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
public class SrPcRepMessageParser extends PCEPReplyMessageParser {
- public SrPcRepMessageParser(ObjectRegistry registry) {
- super(registry);
+ public SrPcRepMessageParser(final ObjectRegistry registry, final VendorInformationObjectRegistry viRegistry) {
+ super(registry, viRegistry);
}
@Override
import org.opendaylight.protocol.pcep.impl.Activator;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.VendorInformationObjectRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
private Activator activator;
private StatefulActivator statefulActivator;
private ObjectRegistry objectRegistry;
+ private VendorInformationObjectRegistry viObjReg;
@Before
public void setup() {
this.srActivator = new SegmentRoutingActivator();
this.srActivator.start(this.ctx);
this.objectRegistry = this.ctx.getObjectHandlerRegistry();
+ this.viObjReg = this.ctx.getVendorInformationObjectRegistry();
}
@Test
0x00,0x01,(byte) 0xe2,0x40,
0x4A,0x7D,0x2b,0x63};
- final SrPcRepMessageParser parser = new SrPcRepMessageParser(this.objectRegistry);
+ final SrPcRepMessageParser parser = new SrPcRepMessageParser(this.objectRegistry, this.viObjReg);
final PcrepMessageBuilder builder = new PcrepMessageBuilder();
final RepliesBuilder rBuilder = new RepliesBuilder();
*/
package org.opendaylight.protocol.pcep.spi;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.primitives.UnsignedBytes;
import java.util.List;
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.message.rev131007.PcerrBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
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.pcerr.message.pcerr.message.error.type.request._case.RequestBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.RpsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
public abstract class AbstractMessageParser implements MessageParser, MessageSerializer {
private static final int I_FLAG_OFFSET = 7;
private final ObjectRegistry registry;
+ private final VendorInformationObjectRegistry viRegistry;
protected AbstractMessageParser(final ObjectRegistry registry) {
this.registry = Preconditions.checkNotNull(registry);
+ this.viRegistry = null;
+ }
+
+ protected AbstractMessageParser(final ObjectRegistry registry, final VendorInformationObjectRegistry viRegistry) {
+ this.registry = Preconditions.checkNotNull(registry);
+ this.viRegistry = Preconditions.checkNotNull(viRegistry);
}
protected void serializeObject(final Object object, final ByteBuf buffer) {
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 = this.registry.parseObject(objClass, objType, header, bytesToPass);
- if (o != null) {
- objs.add(o);
+ if (VendorInformationUtil.isVendorInformationObject(objClass, objType)) {
+ Preconditions.checkState(this.viRegistry != null);
+ final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(bytes.getUnsignedInt(bytes.readerIndex()));
+ final Optional<? extends Object> obj = this.viRegistry.parseVendorInformationObject(enterpriseNumber, header, bytesToPass);
+ if (obj.isPresent()) {
+ objs.add(obj.get());
+ }
+ } else {
+ // parseObject is required to return null for P=0 errored objects
+ final Object o = this.registry.parseObject(objClass, objType, header, bytesToPass);
+ if (o != null) {
+ objs.add(o);
+ }
}
+
bytes.readerIndex(bytes.readerIndex() + objLength - COMMON_OBJECT_HEADER_LENGTH);
}
// Run validation
return validate(objs, errors);
}
+
+ protected final void serializeVendorInformationObjects(final List<VendorInformationObject> viObjects, final ByteBuf buffer) {
+ if (viObjects != null && !viObjects.isEmpty()) {
+ for (final VendorInformationObject viObject : viObjects) {
+ this.viRegistry.serializeVendorInformationObject(viObject, buffer);
+ }
+ }
+ }
+
+ protected final List<VendorInformationObject> addVendorInformationObjects(final List<Object> objects) {
+ final List<VendorInformationObject> vendorInfo = Lists.newArrayList();
+ while (!objects.isEmpty() && objects.get(0) instanceof VendorInformationObject) {
+ final VendorInformationObject viObject = (VendorInformationObject) objects.get(0);
+ vendorInfo.add(viObject);
+ objects.remove(0);
+ }
+ return vendorInfo;
+ }
}
TlvRegistry getTlvHandlerRegistry();
VendorInformationTlvRegistry getVendorInformationTlvRegistry();
+
+ VendorInformationObjectRegistry getVendorInformationObjectRegistry();
}
AutoCloseable registerXROSubobjectSerializer(Class<? extends SubobjectType> subobjectClass, XROSubobjectSerializer serializer);
AutoCloseable registerXROSubobjectParser(int subobjectType, XROSubobjectParser parser);
+
+ AutoCloseable registerVendorInformationObjectSerializer(Class<? extends EnterpriseSpecificInformation> esInformationClass, ObjectSerializer serializer);
+
+ AutoCloseable registerVendorInformationObjectParser(EnterpriseNumber enterpriseNumber, ObjectParser parser);
}
--- /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 com.google.common.base.Optional;
+
+import io.netty.buffer.ByteBuf;
+
+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.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.vendor.information.objects.VendorInformationObject;
+
+public interface VendorInformationObjectRegistry {
+
+ Optional<? extends Object> parseVendorInformationObject(final EnterpriseNumber enterpriseNumber, final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException;
+
+ void serializeVendorInformationObject(final VendorInformationObject viObject, final ByteBuf buffer);
+
+}
public static final int VENDOR_INFORMATION_TLV_TYPE = 7;
+ public static final int VENDOR_INFORMATION_OBJECT_CLASS = 34;
+
+ public static final int VENDOR_INFORMATION_OBJECT_TYPE = 1;
+
private VendorInformationUtil() {
}
public static boolean isVendorInformationTlv(final int type) {
return type == VENDOR_INFORMATION_TLV_TYPE;
}
+
+ public static boolean isVendorInformationObject(final int objectClass, final int objectType) {
+ return objectType == VENDOR_INFORMATION_OBJECT_TYPE && objectClass == VENDOR_INFORMATION_OBJECT_CLASS;
+ }
}
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.pcep.spi.VendorInformationObjectRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
private final SimpleXROSubobjectRegistry xroSubReg = new SimpleXROSubobjectRegistry();
private final SimpleTlvRegistry tlvReg = new SimpleTlvRegistry();
private final SimpleVendorInformationTlvRegistry viTlvReg = new SimpleVendorInformationTlvRegistry();
+ private final SimpleVendorInformationObjectRegistry viObjReg = new SimpleVendorInformationObjectRegistry();
@Override
public final LabelRegistry getLabelHandlerRegistry() {
public AutoCloseable registerVendorInformationTlvParser(final EnterpriseNumber enterpriseNumber, final TlvParser parser) {
return this.viTlvReg.registerVendorInformationTlvParser(enterpriseNumber, parser);
}
+
+ @Override
+ public AutoCloseable registerVendorInformationObjectSerializer(
+ final Class<? extends EnterpriseSpecificInformation> esInformationClass, final ObjectSerializer serializer) {
+ return this.viObjReg.registerVendorInformationObjectSerializer(esInformationClass, serializer);
+ }
+
+ @Override
+ public AutoCloseable registerVendorInformationObjectParser(final EnterpriseNumber enterpriseNumber, final ObjectParser parser) {
+ return this.viObjReg.registerVendorInformationObjectParser(enterpriseNumber, parser);
+ }
+
+ @Override
+ public VendorInformationObjectRegistry getVendorInformationObjectRegistry() {
+ return this.viObjReg;
+ }
}
--- /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.pojo;
+
+import com.google.common.base.Optional;
+import com.google.common.primitives.Ints;
+
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.protocol.concepts.HandlerRegistry;
+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.PCEPErrors;
+import org.opendaylight.protocol.pcep.spi.UnknownObject;
+import org.opendaylight.protocol.pcep.spi.VendorInformationObjectRegistry;
+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.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.vendor.information.EnterpriseSpecificInformation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+
+public class SimpleVendorInformationObjectRegistry implements VendorInformationObjectRegistry {
+
+ private final HandlerRegistry<DataContainer, ObjectParser, ObjectSerializer> handlers = new HandlerRegistry<>();
+
+ public AutoCloseable registerVendorInformationObjectParser(final EnterpriseNumber enterpriseNumber, final ObjectParser parser) {
+ return this.handlers.registerParser(Ints.checkedCast(enterpriseNumber.getValue()), parser);
+ }
+
+ public AutoCloseable registerVendorInformationObjectSerializer(final Class<? extends EnterpriseSpecificInformation> esInformationClass, final ObjectSerializer serializer) {
+ return this.handlers.registerSerializer(esInformationClass, serializer);
+ }
+
+ @Override
+ public Optional<? extends Object> parseVendorInformationObject(final EnterpriseNumber enterpriseNumber, final ObjectHeader header, final ByteBuf buffer)
+ throws PCEPDeserializerException {
+ final ObjectParser parser = this.handlers.getParser(Ints.checkedCast(enterpriseNumber.getValue()));
+ if (parser == null) {
+ if (!header.isProcessingRule()) {
+ return Optional.absent();
+ }
+ return Optional.of(new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS));
+ }
+ return Optional.of(parser.parseObject(header, buffer));
+ }
+
+ @Override
+ public void serializeVendorInformationObject(final VendorInformationObject viObject, final ByteBuf buffer) {
+ final ObjectSerializer serializer = this.handlers.getSerializer(viObject.getEnterpriseSpecificInformation().getImplementedInterface());
+ if (serializer == null) {
+ return;
+ }
+ serializer.serializeObject(viObject, buffer);
+ }
+
+}
package org.opendaylight.protocol.pcep.spi;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
EROSubobjectUtil.formatSubobject(2, false, body, out);
assertArrayEquals(expected, ByteArray.getAllBytes(out));
}
+
+ @Test
+ public void testVendorInformationUtil() {
+ assertTrue(VendorInformationUtil.isVendorInformationTlv(VendorInformationUtil.VENDOR_INFORMATION_TLV_TYPE));
+ assertFalse(VendorInformationUtil.isVendorInformationTlv(VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS));
+
+ assertTrue(VendorInformationUtil.isVendorInformationObject(VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS, VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE));
+ assertFalse(VendorInformationUtil.isVendorInformationObject(VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS, VendorInformationUtil.VENDOR_INFORMATION_TLV_TYPE));
+ assertFalse(VendorInformationUtil.isVendorInformationObject(VendorInformationUtil.VENDOR_INFORMATION_TLV_TYPE, VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE));
+ assertFalse(VendorInformationUtil.isVendorInformationObject(VendorInformationUtil.VENDOR_INFORMATION_OBJECT_TYPE, VendorInformationUtil.VENDOR_INFORMATION_OBJECT_CLASS));
+ }
}