Search in sources :

Example 1 with VendorInformationTlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testCloseObjectWithVendorInformationTlv.

@Test
public void testCloseObjectWithVendorInformationTlv() throws IOException, PCEPDeserializerException {
    final byte[] closeBytes = { 0x0f, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x05, /* vendor-information TLV */
    0x00, 0x07, 0x00, 0x08, /* enterprise number */
    0x00, 0x00, 0x00, 0x00, /* enterprise specific information */
    0x00, 0x00, 0x00, 0x05 };
    final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
    final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
    final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
    final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L)).setEnterpriseSpecificInformation(esInfo).build();
    final CCloseBuilder builder = new CCloseBuilder();
    builder.setProcessingRule(false);
    builder.setIgnore(false);
    builder.setReason((short) 5);
    builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder().setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
    assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buf = Unpooled.buffer();
    parser.serializeObject(builder.build(), buf);
    assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
}
Also used : ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) PCEPCloseObjectParser(org.opendaylight.protocol.pcep.parser.object.PCEPCloseObjectParser) CCloseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder) ByteBuf(io.netty.buffer.ByteBuf) VendorInformationTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv) TestEnterpriseSpecificInformation(org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation) EnterpriseNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber) VendorInformationTlvBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder) Subobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject) Test(org.junit.Test)

Example 2 with VendorInformationTlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv in project bgpcep by opendaylight.

the class AbstractVendorInformationTlvParser method parseTlv.

@Override
public final VendorInformationTlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
    if (buffer == null) {
        return null;
    }
    final VendorInformationTlvBuilder viTlvBuider = new VendorInformationTlvBuilder();
    viTlvBuider.setEnterpriseNumber(getEnterpriseNumber());
    if (buffer.isReadable()) {
        final EnterpriseSpecificInformation esInformation = parseEnterpriseSpecificInformation(buffer.slice());
        if (esInformation != null) {
            viTlvBuider.setEnterpriseSpecificInformation(esInformation);
        }
    }
    return viTlvBuider.build();
}
Also used : EnterpriseSpecificInformation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.EnterpriseSpecificInformation) VendorInformationTlvBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder)

Example 3 with VendorInformationTlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv in project bgpcep by opendaylight.

the class AbstractObjectWithTlvsParser method serializeVendorInformationTlvs.

protected final void serializeVendorInformationTlvs(final List<VendorInformationTlv> tlvs, final ByteBuf buffer) {
    if (tlvs != null) {
        for (final VendorInformationTlv tlv : tlvs) {
            LOG.trace("Serializing VENDOR-INFORMATION TLV {}", tlv);
            this.viTlvReg.serializeVendorInformationTlv(tlv, buffer);
            LOG.trace("Serialized VENDOR-INFORMATION TLV : {}.", ByteBufUtil.hexDump(buffer));
        }
    }
}
Also used : VendorInformationTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv)

Example 4 with VendorInformationTlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv in project bgpcep by opendaylight.

the class AbstractObjectWithTlvsParser method parseTlvs.

protected final void parseTlvs(final T builder, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null, "Array of bytes is mandatory. Can't be null.");
    if (!bytes.isReadable()) {
        return;
    }
    final List<VendorInformationTlv> viTlvs = Lists.newArrayList();
    while (bytes.isReadable()) {
        final int type = bytes.readUnsignedShort();
        final int length = bytes.readUnsignedShort();
        if (length > bytes.readableBytes()) {
            throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= " + bytes.readableBytes() + ".");
        }
        final ByteBuf tlvBytes = bytes.readSlice(length);
        LOG.trace("Parsing PCEP TLV : {}", ByteBufUtil.hexDump(tlvBytes));
        if (VendorInformationUtil.isVendorInformationTlv(type)) {
            final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(tlvBytes.readUnsignedInt());
            final Optional<VendorInformationTlv> viTlv = this.viTlvReg.parseVendorInformationTlv(enterpriseNumber, tlvBytes);
            if (viTlv.isPresent()) {
                LOG.trace("Parsed VENDOR-INFORMATION TLV {}.", viTlv.get());
                viTlvs.add(viTlv.get());
            }
        } else {
            final Tlv tlv = this.tlvReg.parseTlv(type, tlvBytes);
            if (tlv != null) {
                LOG.trace("Parsed PCEP TLV {}.", tlv);
                addTlv(builder, tlv);
            }
        }
        bytes.skipBytes(TlvUtil.getPadding(TlvUtil.HEADER_SIZE + length, TlvUtil.PADDED_TO));
    }
    addVendorInformationTlvs(builder, viTlvs);
}
Also used : VendorInformationTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv) EnterpriseNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber) ByteBuf(io.netty.buffer.ByteBuf) VendorInformationTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv) Tlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv)

Example 5 with VendorInformationTlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv in project bgpcep by opendaylight.

the class PCEPTlvParserTest method testVendorInformationTlv.

@Test
public void testVendorInformationTlv() throws PCEPDeserializerException {
    final TestVendorInformationTlvParser parser = new TestVendorInformationTlvParser();
    final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
    final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L)).setEnterpriseSpecificInformation(esInfo).build();
    final VendorInformationTlv parsedTlv = parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(VENDOR_INFO_BYTES, 8)));
    assertEquals(viTlv, parsedTlv);
    final ByteBuf buff = Unpooled.buffer(VENDOR_INFO_BYTES.length);
    parser.serializeTlv(viTlv, buff);
    assertArrayEquals(VENDOR_INFO_BYTES, ByteArray.getAllBytes(buff));
    assertNull(parser.parseTlv(null));
}
Also used : VendorInformationTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv) TestEnterpriseSpecificInformation(org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation) EnterpriseNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber) ByteBuf(io.netty.buffer.ByteBuf) VendorInformationTlvBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder) Test(org.junit.Test)

Aggregations

VendorInformationTlv (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv)5 ByteBuf (io.netty.buffer.ByteBuf)4 EnterpriseNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber)3 VendorInformationTlvBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder)3 Test (org.junit.Test)2 TestEnterpriseSpecificInformation (org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation)2 PCEPCloseObjectParser (org.opendaylight.protocol.pcep.parser.object.PCEPCloseObjectParser)1 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)1 Tlv (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv)1 CCloseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder)1 Subobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject)1 EnterpriseSpecificInformation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.EnterpriseSpecificInformation)1