use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.LabelCaseBuilder in project bgpcep by opendaylight.
the class EROSubobjectParserTest method testEROLabelSubobject.
@Test
public void testEROLabelSubobject() throws Exception {
final EROLabelSubobjectParser parser = new EROLabelSubobjectParser(this.ctx.getLabelHandlerRegistry());
final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
subs.setLoose(true);
subs.setSubobjectType(new LabelCaseBuilder().setLabel(new LabelBuilder().setUniDirectional(true).setLabelType(new GeneralizedLabelCaseBuilder().setGeneralizedLabel(new GeneralizedLabelBuilder().setGeneralizedLabel(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF }).build()).build()).build()).build());
assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(LABEL_BYTES, 2)), true));
final ByteBuf buff = Unpooled.buffer();
parser.serializeSubobject(subs.build(), buff);
Assert.assertArrayEquals(LABEL_BYTES, ByteArray.getAllBytes(buff));
try {
parser.parseSubobject(null, true);
Assert.fail();
} catch (final IllegalArgumentException e) {
Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
Assert.fail();
} catch (final IllegalArgumentException e) {
Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.LabelCaseBuilder in project bgpcep by opendaylight.
the class RROSubobjectParserTest method testRROLabelSubobject.
@Test
public void testRROLabelSubobject() throws Exception {
final SimpleRSVPExtensionProviderContext ctx = new SimpleRSVPExtensionProviderContext();
try (RSVPActivator a = new RSVPActivator()) {
a.start(ctx);
final RROLabelSubobjectParser parser = new RROLabelSubobjectParser(ctx.getLabelHandlerRegistry());
final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
subs.setSubobjectType(new LabelCaseBuilder().setLabel(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());
assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(LABEL_BYTES, 2))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeSubobject(subs.build(), buff);
Assert.assertArrayEquals(LABEL_BYTES, ByteArray.getAllBytes(buff));
try {
parser.parseSubobject(null);
Assert.fail();
} catch (final IllegalArgumentException e) {
Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER);
Assert.fail();
} catch (final IllegalArgumentException e) {
Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.LabelCaseBuilder in project bgpcep by opendaylight.
the class EROLabelSubobjectParser method parseSubobject.
@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (buffer.readableBytes() < HEADER_LENGTH) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; " + "Expected: >" + HEADER_LENGTH + ".");
}
final BitArray reserved = BitArray.valueOf(buffer, FLAGS_SIZE);
final short cType = buffer.readUnsignedByte();
final LabelType labelType = this.registry.parseLabel(cType, buffer.slice());
if (labelType == null) {
throw new RSVPParsingException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
}
final LabelBuilder builder = new LabelBuilder();
builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
builder.setLabelType(labelType);
return new SubobjectContainerBuilder().setLoose(loose).setSubobjectType(new LabelCaseBuilder().setLabel(builder.build()).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.LabelCaseBuilder in project bgpcep by opendaylight.
the class PCEPRROSubobjectParserTest method testRROLabelSubobject.
@Test
public void testRROLabelSubobject() throws Exception {
final SimplePCEPExtensionProviderContext ctx = new SimplePCEPExtensionProviderContext();
try (BaseParserExtensionActivator a = new BaseParserExtensionActivator()) {
a.start(ctx);
final RROLabelSubobjectParser parser = new RROLabelSubobjectParser(ctx.getLabelHandlerRegistry());
final SubobjectBuilder subs = new SubobjectBuilder();
subs.setSubobjectType(new LabelCaseBuilder().setLabel(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());
assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(labelBytes, 2))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeSubobject(subs.build(), buff);
assertArrayEquals(labelBytes, ByteArray.getAllBytes(buff));
try {
parser.parseSubobject(null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.LabelCaseBuilder in project bgpcep by opendaylight.
the class EROLabelSubobjectParser method parseSubobject.
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (buffer.readableBytes() < HEADER_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" + HEADER_LENGTH + ".");
}
final BitArray reserved = BitArray.valueOf(buffer, FLAGS_SIZE);
final short cType = buffer.readUnsignedByte();
final LabelType labelType = this.registry.parseLabel(cType, buffer.slice());
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(labelType);
return new SubobjectBuilder().setLoose(loose).setSubobjectType(new LabelCaseBuilder().setLabel(builder.build()).build()).build();
}
Aggregations