--- /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.lsp.setup.type01;
+
+import org.opendaylight.protocol.pcep.ietf.initiated00.CInitiated00SrpObjectParser;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.SrpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs8;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs8Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+
+public class CInitiated00SrpObjectWithPstTlvParser extends CInitiated00SrpObjectParser {
+
+ public CInitiated00SrpObjectWithPstTlvParser(TlvRegistry tlvReg) {
+ super(tlvReg);
+ }
+
+ @Override
+ public void addTlv(SrpBuilder builder, Tlv tlv) {
+ super.addTlv(builder, tlv);
+ final Tlvs8Builder tlvBuilder = new Tlvs8Builder();
+ if (builder.getTlvs() != null) {
+ if (builder.getTlvs().getAugmentation(Tlvs8.class) != null) {
+ final Tlvs8 t = builder.getTlvs().getAugmentation(Tlvs8.class);
+ if (t.getPathSetupType() != null) {
+ tlvBuilder.setPathSetupType(t.getPathSetupType());
+ }
+ }
+ }
+ if (tlv instanceof PathSetupType) {
+ tlvBuilder.setPathSetupType((PathSetupType) tlv);
+ }
+ builder.setTlvs(new TlvsBuilder().addAugmentation(Tlvs8.class, tlvBuilder.build()).build());
+ }
+
+ @Override
+ public byte[] serializeTlvs(Tlvs tlvs) {
+ if (tlvs == null) {
+ return new byte[0];
+ }
+ final byte[] prev = super.serializeTlvs(tlvs);
+ int finalLength = prev.length;
+ byte[] nameBytes = null;
+ if (tlvs.getAugmentation(Tlvs8.class) != null) {
+ final Tlvs8 nameTlvs = tlvs.getAugmentation(Tlvs8.class);
+ if (nameTlvs.getPathSetupType() != null) {
+ nameBytes = serializeTlv(nameTlvs.getPathSetupType());
+ finalLength += nameBytes.length;
+ }
+ }
+ final byte[] result = new byte[finalLength];
+ ByteArray.copyWhole(prev, result, 0);
+ int offset = prev.length;
+ if (nameBytes != null) {
+ ByteArray.copyWhole(nameBytes, result, offset);
+ offset += nameBytes.length;
+ }
+ return result;
+ }
+
+}
--- /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.lsp.setup.type01;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.TlvParser;
+import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupTypeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+
+public class PathSetupTypeTlvParser implements TlvParser, TlvSerializer {
+
+ // http://tools.ietf.org/html/draft-sivabalan-pce-segment-routing-01#section-9.3
+ public static final int TYPE = 27;
+ private static final int PST_LENGTH = 1;
+ private static final int OFFSET = 4 - PST_LENGTH;
+
+ @Override
+ public byte[] serializeTlv(Tlv tlv) {
+ Preconditions.checkNotNull(tlv, "PathSetupType is mandatory.");
+ final PathSetupType pstTlv = (PathSetupType) tlv;
+ return TlvUtil.formatTlv(TYPE, new byte[] { 0, 0, 0, (byte) (pstTlv.isPst() ? 1 : 0) });
+ }
+
+ @Override
+ public Tlv parseTlv(ByteBuf buffer) throws PCEPDeserializerException {
+ if (buffer == null) {
+ return null;
+ }
+ final boolean pst = buffer.readerIndex(OFFSET).readBoolean();
+ return new PathSetupTypeBuilder().setPst(pst).build();
+ }
+
+}
--- /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.lsp.setup.type01;
+
+import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs3Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder;
+
+public class PcepRpObjectWithPstTlvParser extends PCEPRequestParameterObjectParser {
+
+ public PcepRpObjectWithPstTlvParser(TlvRegistry tlvReg) {
+ super(tlvReg);
+ }
+
+ @Override
+ public void addTlv(RpBuilder builder, Tlv tlv) {
+ super.addTlv(builder, tlv);
+ final Tlvs3Builder tlvBuilder = new Tlvs3Builder();
+ if (builder.getTlvs() != null) {
+ if (builder.getTlvs().getAugmentation(Tlvs3.class) != null) {
+ final Tlvs3 t = builder.getTlvs().getAugmentation(Tlvs3.class);
+ if (t.getPathSetupType() != null) {
+ tlvBuilder.setPathSetupType(t.getPathSetupType());
+ }
+ }
+ }
+ if (tlv instanceof PathSetupType) {
+ tlvBuilder.setPathSetupType((PathSetupType) tlv);
+ }
+ builder.setTlvs(new TlvsBuilder().addAugmentation(Tlvs3.class, tlvBuilder.build()).build());
+ }
+
+ @Override
+ public byte[] serializeTlvs(Tlvs tlvs) {
+ if (tlvs == null) {
+ return new byte[0];
+ }
+ final byte[] prev = super.serializeTlvs(tlvs);
+ int finalLength = prev.length;
+ byte[] nameBytes = null;
+ if (tlvs.getAugmentation(Tlvs3.class) != null) {
+ final Tlvs3 nameTlvs = tlvs.getAugmentation(Tlvs3.class);
+ if (nameTlvs.getPathSetupType() != null) {
+ nameBytes = serializeTlv(nameTlvs.getPathSetupType());
+ finalLength += nameBytes.length;
+ }
+ }
+ final byte[] result = new byte[finalLength];
+ ByteArray.copyWhole(prev, result, 0);
+ int offset = prev.length;
+ if (nameBytes != null) {
+ ByteArray.copyWhole(nameBytes, result, offset);
+ offset += nameBytes.length;
+ }
+ return result;
+ }
+
+}
--- /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.segment.routing02;
+
+import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.Tlvs1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.Tlvs1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.sr.pce.capability.tlv.SrPceCapability;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
+
+public class PcepOpenObjectWithSpcTlvParser extends PCEPOpenObjectParser {
+
+ public PcepOpenObjectWithSpcTlvParser(TlvRegistry tlvReg) {
+ super(tlvReg);
+ }
+
+ @Override
+ public void addTlv(TlvsBuilder tbuilder, Tlv tlv) {
+ super.addTlv(tbuilder, tlv);
+ final Tlvs1Builder tlvBuilder = new Tlvs1Builder();
+ if (tbuilder.getAugmentation(Tlvs1.class) != null) {
+ final Tlvs1 tlvs = tbuilder.getAugmentation(Tlvs1.class);
+ if (tlvs.getSrPceCapability() != null) {
+ tlvBuilder.setSrPceCapability(tlvs.getSrPceCapability());
+ }
+ }
+ if (tlv instanceof SrPceCapability) {
+ tlvBuilder.setSrPceCapability((SrPceCapability) tlv);
+ }
+ tbuilder.addAugmentation(Tlvs1.class, tlvBuilder.build());
+ }
+
+ @Override
+ public byte[] serializeTlvs(Tlvs tlvs) {
+ if (tlvs == null) {
+ return new byte[0];
+ }
+ final byte[] prev = super.serializeTlvs(tlvs);
+ int finalLength = prev.length;
+ byte[] nameBytes = null;
+ if (tlvs.getAugmentation(Tlvs1.class) != null) {
+ final Tlvs1 spcTlvs = tlvs.getAugmentation(Tlvs1.class);
+ if (spcTlvs.getSrPceCapability() != null) {
+ nameBytes = serializeTlv(spcTlvs.getSrPceCapability());
+ finalLength += nameBytes.length;
+ }
+ }
+ final byte[] result = new byte[finalLength];
+ ByteArray.copyWhole(prev, result, 0);
+ int offset = prev.length;
+ if (nameBytes != null) {
+ ByteArray.copyWhole(nameBytes, result, offset);
+ offset += nameBytes.length;
+ }
+ return result;
+ }
+
+}
--- /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.segment.routing02;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.opendaylight.protocol.pcep.lsp.setup.type01.PathSetupTypeTlvParser;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.sr.pce.capability.tlv.SrPceCapability;
+
+public class SegmentRoutingActivator extends AbstractPCEPExtensionProviderActivator {
+
+ @Override
+ protected List<AutoCloseable> startImpl(PCEPExtensionProviderContext context) {
+ final List<AutoCloseable> regs = Lists.newArrayList();
+
+ regs.add(context.registerTlvParser(SrPceCapabilityTlvParser.TYPE, new SrPceCapabilityTlvParser()));
+ regs.add(context.registerTlvSerializer(SrPceCapability.class, new SrPceCapabilityTlvParser()));
+
+ regs.add(context.registerTlvParser(PathSetupTypeTlvParser.TYPE, new PathSetupTypeTlvParser()));
+ regs.add(context.registerTlvSerializer(PathSetupType.class, new PathSetupTypeTlvParser()));
+ 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.segment.routing02;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
+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.pcep.segment.routing._02.rev140506.sr.pce.capability.tlv.SrPceCapability;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.sr.pce.capability.tlv.SrPceCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+
+public class SrPceCapabilityTlvParser implements TlvParser, TlvSerializer {
+
+ public static final int TYPE = 26;
+
+ private static final int MSD_LENGTH = 1;
+ private static final int OFFSET = 4 - MSD_LENGTH;
+
+ @Override
+ public byte[] serializeTlv(Tlv tlv) {
+ Preconditions.checkNotNull(tlv, "SrPceCapability is mandatory.");
+ final SrPceCapability spcTlv = (SrPceCapability) tlv;
+ return TlvUtil.formatTlv(TYPE, ByteArray.intToBytes(spcTlv.getMsd()));
+ }
+
+ @Override
+ public Tlv parseTlv(ByteBuf buffer) throws PCEPDeserializerException {
+ if (buffer == null) {
+ return null;
+ }
+ final short msd = buffer.readerIndex(OFFSET).readUnsignedByte();
+ return new SrPceCapabilityBuilder().setMsd(msd).build();
+ }
+
+}
--- /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.lsp.setup.type01;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.pcep.segment.routing02.SegmentRoutingActivator;
+import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
+import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SrpIdNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.SrpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs3Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs8;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs8Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupTypeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
+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.rp.object.rp.TlvsBuilder;
+
+public class PcepObjectParserTest {
+
+ private static final byte[] rpObjectWithPstTlvBytes = { 0x2, 0x10, 0x0, 0x14, 0x0, 0x0, 0x4, 0x2d, (byte) 0xde,
+ (byte) 0xad, (byte) 0xbe, (byte) 0xef,
+ /* pst-tlv */
+ 0x0, 0x1b, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1 };
+
+ private static final byte[] srpObjectWithPstTlvBytes = { 0x21, 0x10, 0x00, 0x14, 0x0, 0x0, 0x0, 0x01, 0x0, 0x0,
+ 0x0, 0x01,
+ /* pst-tlv */
+ 0x0, 0x1b, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1 };
+
+ private TlvRegistry tlvRegistry;
+
+ private SimplePCEPExtensionProviderContext ctx;
+ private SegmentRoutingActivator act;
+
+ @Before
+ public void setUp() {
+ this.ctx = new SimplePCEPExtensionProviderContext();
+ this.act = new SegmentRoutingActivator();
+ this.act.start(this.ctx);
+ this.tlvRegistry = this.ctx.getTlvHandlerRegistry();
+ }
+
+ @Test
+ public void testRpObjectWithPstTlvParser() throws PCEPDeserializerException {
+ final PcepRpObjectWithPstTlvParser parser = new PcepRpObjectWithPstTlvParser(this.tlvRegistry);
+ final RpBuilder builder = new RpBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setReoptimization(true);
+ builder.setBiDirectional(false);
+ builder.setLoose(true);
+ builder.setMakeBeforeBreak(true);
+ builder.setOrder(false);
+ builder.setPathKey(false);
+ builder.setSupplyOf(false);
+ builder.setFragmentation(false);
+ builder.setP2mp(false);
+ builder.setEroCompression(false);
+ builder.setPriority((short) 5);
+ builder.setRequestId(new RequestId(0xdeadbeefL));
+ builder.setTlvs(new TlvsBuilder().addAugmentation(Tlvs3.class,
+ new Tlvs3Builder().setPathSetupType(new PathSetupTypeBuilder().setPst(true).build()).build()).build());
+
+ final ByteBuf result = Unpooled.wrappedBuffer(rpObjectWithPstTlvBytes);
+ assertEquals(builder.build(),
+ parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+ assertArrayEquals(rpObjectWithPstTlvBytes, parser.serializeObject(builder.build()));
+ }
+
+ @Test
+ public void testSrpObjectWithPstTlvParser() throws PCEPDeserializerException {
+ final CInitiated00SrpObjectWithPstTlvParser parser = new CInitiated00SrpObjectWithPstTlvParser(this.tlvRegistry);
+ final SrpBuilder builder = new SrpBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setOperationId(new SrpIdNumber(1L));
+ builder.addAugmentation(Srp1.class, new Srp1Builder().setRemove(true).build());
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder()
+ .addAugmentation(Tlvs8.class,
+ new Tlvs8Builder().setPathSetupType(new PathSetupTypeBuilder().setPst(true).build()).build())
+ .build());
+
+ final ByteBuf result = Unpooled.wrappedBuffer(srpObjectWithPstTlvBytes);
+ assertEquals(builder.build(),
+ parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+ assertArrayEquals(srpObjectWithPstTlvBytes, parser.serializeObject(builder.build()));
+ }
+}
--- /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.lsp.setup.type01;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+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.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupTypeBuilder;
+
+public class PcepTlvParserTest {
+
+ private static final byte[] pstTlvBytes = { 0x0, 0x1b, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1 };
+
+ @Test
+ public void testPathSetupTypeTlvParser() throws PCEPDeserializerException {
+ final PathSetupTypeTlvParser parser = new PathSetupTypeTlvParser();
+ final PathSetupType pstTlv = new PathSetupTypeBuilder().setPst(true).build();
+
+ assertEquals(pstTlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(pstTlvBytes, 4))));
+ assertArrayEquals(pstTlvBytes, parser.serializeTlv(pstTlv));
+ }
+
+}
--- /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.segment.routing02;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
+import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.Tlvs1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.Tlvs1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.sr.pce.capability.tlv.SrPceCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
+
+public class PcepObjectParserTest {
+
+ private static final byte[] openObjectBytes = { 0x01, 0x10, 0x00, 0x10, 0x20, 0x1e, 0x78, 0x01,
+ /* sr-capability-tlv */
+ 0x0, 0x1a, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1 };
+
+ private TlvRegistry tlvRegistry;
+
+ private SimplePCEPExtensionProviderContext ctx;
+ private SegmentRoutingActivator act;
+
+ @Before
+ public void setUp() {
+ this.ctx = new SimplePCEPExtensionProviderContext();
+ this.act = new SegmentRoutingActivator();
+ this.act.start(this.ctx);
+ this.tlvRegistry = this.ctx.getTlvHandlerRegistry();
+ }
+
+ @Test
+ public void testOpenObjectWithSpcTlv() throws PCEPDeserializerException {
+ final PcepOpenObjectWithSpcTlvParser parser = new PcepOpenObjectWithSpcTlvParser(tlvRegistry);
+
+ final OpenBuilder builder = new OpenBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setVersion(new ProtocolVersion((short) 1));
+ builder.setKeepalive((short) 30);
+ builder.setDeadTimer((short) 120);
+ builder.setSessionId((short) 1);
+
+ Tlvs1 tlv = new Tlvs1Builder().setSrPceCapability(new SrPceCapabilityBuilder().setMsd((short) 1).build())
+ .build();
+ builder.setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, tlv).build());
+
+ final ByteBuf result = Unpooled.wrappedBuffer(openObjectBytes);
+ assertEquals(builder.build(),
+ parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+ assertArrayEquals(openObjectBytes, parser.serializeObject(builder.build()));
+ }
+
+}
--- /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.segment.routing02;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+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.segment.routing._02.rev140506.sr.pce.capability.tlv.SrPceCapability;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.sr.pce.capability.tlv.SrPceCapabilityBuilder;
+
+public class PcepTlvParserTest {
+
+ private static final byte[] spcTlvBytes = { 0x0, 0x1a, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1 };
+
+ @Test
+ public void testSrPceCapabilityParser() throws PCEPDeserializerException {
+ final SrPceCapabilityTlvParser parser = new SrPceCapabilityTlvParser();
+ final SrPceCapability spcTlv = new SrPceCapabilityBuilder().setMsd((short) 1).build();
+ assertEquals(spcTlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(spcTlvBytes, 4))));
+ assertArrayEquals(spcTlvBytes, parser.serializeTlv(spcTlv));
+ }
+
+}