Search in sources :

Example 1 with WavebandSwitchingLabelBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.waveband.switching.label._case.WavebandSwitchingLabelBuilder in project bgpcep by opendaylight.

the class WavebandSwitchingLabelParser method parseLabel.

@Override
public final LabelType parseLabel(final ByteBuf buffer) throws RSVPParsingException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT_LENGTH) {
        throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + CONTENT_LENGTH + ".");
    }
    final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder();
    builder.setWavebandId(buffer.readUnsignedInt());
    builder.setStartLabel(buffer.readUnsignedInt());
    builder.setEndLabel(buffer.readUnsignedInt());
    return new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(builder.build()).build();
}
Also used : WavebandSwitchingLabelCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCaseBuilder) RSVPParsingException(org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException) WavebandSwitchingLabelBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.waveband.switching.label._case.WavebandSwitchingLabelBuilder)

Example 2 with WavebandSwitchingLabelBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.waveband.switching.label._case.WavebandSwitchingLabelBuilder in project bgpcep by opendaylight.

the class LabelSubobjectParserTest method testWavebandLabel.

@Test
public void testWavebandLabel() throws RSVPParsingException {
    final WavebandSwitchingLabelParser parser = new WavebandSwitchingLabelParser();
    final WavebandSwitchingLabelBuilder iBuilder = new WavebandSwitchingLabelBuilder();
    iBuilder.setWavebandId(0x1234L);
    iBuilder.setStartLabel(0x9999L);
    iBuilder.setEndLabel(0x1111L);
    final WavebandSwitchingLabelCaseBuilder builder = new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(iBuilder.build());
    assertEquals(builder.build(), parser.parseLabel(Unpooled.wrappedBuffer(ByteArray.cutBytes(WAVEBAND_LABEL_BYTES, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeLabel(false, true, builder.build(), buff);
    assertArrayEquals(WAVEBAND_LABEL_BYTES, ByteArray.getAllBytes(buff));
    try {
        parser.parseLabel(null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseLabel(Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}
Also used : WavebandSwitchingLabelCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCaseBuilder) ByteBuf(io.netty.buffer.ByteBuf) WavebandSwitchingLabelBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.waveband.switching.label._case.WavebandSwitchingLabelBuilder) WavebandSwitchingLabelParser(org.opendaylight.protocol.rsvp.parser.impl.subobject.label.WavebandSwitchingLabelParser) Test(org.junit.Test)

Example 3 with WavebandSwitchingLabelBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.waveband.switching.label._case.WavebandSwitchingLabelBuilder in project bgpcep by opendaylight.

the class LabelSubobjectParserTest method testWavebandLabel.

@Test
public void testWavebandLabel() throws PCEPDeserializerException {
    final WavebandSwitchingLabelParser parser = new WavebandSwitchingLabelParser();
    final WavebandSwitchingLabelBuilder iBuilder = new WavebandSwitchingLabelBuilder();
    iBuilder.setWavebandId(0x1234L);
    iBuilder.setStartLabel(0x9999L);
    iBuilder.setEndLabel(0x1111L);
    final WavebandSwitchingLabelCaseBuilder builder = new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(iBuilder.build());
    assertEquals(builder.build(), parser.parseLabel(Unpooled.wrappedBuffer(ByteArray.cutBytes(wavebandLabelBytes, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeLabel(false, true, builder.build(), buff);
    assertArrayEquals(wavebandLabelBytes, ByteArray.getAllBytes(buff));
    try {
        parser.parseLabel(null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseLabel(Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}
Also used : WavebandSwitchingLabelCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCaseBuilder) ByteBuf(io.netty.buffer.ByteBuf) WavebandSwitchingLabelBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.waveband.switching.label._case.WavebandSwitchingLabelBuilder) WavebandSwitchingLabelParser(org.opendaylight.protocol.pcep.parser.subobject.WavebandSwitchingLabelParser) Test(org.junit.Test)

Example 4 with WavebandSwitchingLabelBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.waveband.switching.label._case.WavebandSwitchingLabelBuilder in project bgpcep by opendaylight.

the class WavebandSwitchingLabelParser method parseLabel.

@Override
public LabelType parseLabel(final ByteBuf buffer) throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + CONTENT_LENGTH + ".");
    }
    final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder();
    builder.setWavebandId(buffer.readUnsignedInt());
    builder.setStartLabel(buffer.readUnsignedInt());
    builder.setEndLabel(buffer.readUnsignedInt());
    return new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(builder.build()).build();
}
Also used : WavebandSwitchingLabelCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCaseBuilder) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException) WavebandSwitchingLabelBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.waveband.switching.label._case.WavebandSwitchingLabelBuilder)

Aggregations

WavebandSwitchingLabelCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCaseBuilder)4 WavebandSwitchingLabelBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.waveband.switching.label._case.WavebandSwitchingLabelBuilder)4 ByteBuf (io.netty.buffer.ByteBuf)2 Test (org.junit.Test)2 WavebandSwitchingLabelParser (org.opendaylight.protocol.pcep.parser.subobject.WavebandSwitchingLabelParser)1 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)1 WavebandSwitchingLabelParser (org.opendaylight.protocol.rsvp.parser.impl.subobject.label.WavebandSwitchingLabelParser)1 RSVPParsingException (org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException)1