Example usage for io.netty.buffer ByteBuf slice

List of usage examples for io.netty.buffer ByteBuf slice

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf slice.

Prototype

public abstract ByteBuf slice(int index, int length);

Source Link

Document

Returns a slice of this buffer's sub-region.

Usage

From source file:org.opendaylight.protocol.pcep.ietf.PCEPValidatorTest.java

License:Open Source License

@Test
public void testMissingLspObjectErrorInPcRptMsg() throws PCEPDeserializerException {
    final byte[] statefulMsg = { (byte) 0x20, (byte) 0x0B, (byte) 0x00, (byte) 0x1C,
            /* srp-object */
            (byte) 0x21, (byte) 0x10, (byte) 0x00, (byte) 0x0C, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x001, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
            /* lsp-object is missing*/
            /* sr-ero-object */
            (byte) 0x07, (byte) 0x10, (byte) 0x00, (byte) 0x0C,
            /* ipv4 prefix subobject */
            (byte) 0x81, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16,
            (byte) 0x00 };

    try (CrabbeInitiatedActivator a = new CrabbeInitiatedActivator();
            StatefulActivator b = new StatefulActivator()) {
        a.start(this.ctx);
        b.start(this.ctx);
        final Stateful07PCReportMessageParser parser = new Stateful07PCReportMessageParser(
                this.ctx.getObjectHandlerRegistry());

        final PcerrMessageBuilder errMsgBuilder = new PcerrMessageBuilder();
        errMsgBuilder.setErrors(Lists.newArrayList(new ErrorsBuilder()
                .setErrorObject(new ErrorObjectBuilder().setType((short) 6).setValue((short) 8).build())
                .build()));//from w  w  w .  j av a  2  s  .c o  m
        final PcerrBuilder builder = new PcerrBuilder();
        builder.setPcerrMessage(errMsgBuilder.build());

        final ByteBuf buf = Unpooled.wrappedBuffer(statefulMsg);
        final List<Message> errors = Lists.newArrayList();
        parser.parseMessage(buf.slice(4, buf.readableBytes() - 4), errors);
        assertFalse(errors.isEmpty());
        assertEquals(builder.build(), errors.get(0));
    }
}

From source file:org.opendaylight.protocol.pcep.ietf.PCEPValidatorTest.java

License:Open Source License

@Test
public void testUnexpectedRroObjectInPcUpdMsg() throws PCEPDeserializerException {
    final byte[] badUpdateMsg = { (byte) 0x20, (byte) 0x0b, (byte) 0x00, (byte) 0x50,
            /* SRP, LSP and ERO objects */
            (byte) 0x21, (byte) 0x12, (byte) 0x00, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x20, (byte) 0x10,
            (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x09, (byte) 0x07,
            (byte) 0x10, (byte) 0x00, (byte) 0x14, (byte) 0x01, (byte) 0x08, (byte) 0x05, (byte) 0x05,
            (byte) 0x05, (byte) 0x03, (byte) 0x18, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x08,
            (byte) 0x08, (byte) 0x08, (byte) 0x04, (byte) 0x18, (byte) 0x00,
            /* RRO object */
            (byte) 0x08, (byte) 0x10, (byte) 0x00, (byte) 0x24, (byte) 0x01, (byte) 0x08, (byte) 0x0a,
            (byte) 0x00, (byte) 0x00, (byte) 0x83, (byte) 0x20, (byte) 0x20, (byte) 0x03, (byte) 0x08,
            (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
            (byte) 0x08, (byte) 0x0a, (byte) 0x00, (byte) 0x09, (byte) 0xde, (byte) 0x20, (byte) 0x00,
            (byte) 0x03, (byte) 0x08, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00 };

    try (CrabbeInitiatedActivator a = new CrabbeInitiatedActivator()) {
        a.start(this.ctx);

        final Stateful07PCUpdateRequestMessageParser parser = new Stateful07PCUpdateRequestMessageParser(
                this.ctx.getObjectHandlerRegistry());

        final PcerrMessageBuilder errMsgBuilder = new PcerrMessageBuilder();
        errMsgBuilder.setErrors(Lists.newArrayList(new ErrorsBuilder()
                .setErrorObject(new ErrorObjectBuilder().setType((short) 6).setValue((short) 10).build())
                .build()));//from  w w  w.  j  a va  2 s .  c o m
        final PcerrBuilder builder = new PcerrBuilder();
        builder.setPcerrMessage(errMsgBuilder.build());

        final ByteBuf buf = Unpooled.wrappedBuffer(badUpdateMsg);
        final List<Message> errors = Lists.newArrayList();
        parser.parseMessage(buf.slice(4, buf.readableBytes() - 4), errors);
        assertFalse(errors.isEmpty());
        assertEquals(builder.build(), errors.get(0));
    }
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java

License:Open Source License

@Test
public void testOpenObjectWOTLV() throws PCEPDeserializerException, IOException {
    final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry, this.viTlvRegistry);
    final ByteBuf result = Unpooled
            .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));

    final OpenBuilder builder = new OpenBuilder();
    builder.setProcessingRule(false);//from  ww  w .jav a 2  s .  c  o m
    builder.setIgnore(false);
    builder.setVersion(new ProtocolVersion((short) 1));
    builder.setKeepalive((short) 30);
    builder.setDeadTimer((short) 120);
    builder.setSessionId((short) 1);

    builder.setTlvs(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder()
                    .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));

    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java

License:Open Source License

@Test
public void testCloseObject() throws IOException, PCEPDeserializerException {
    final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
    final ByteBuf result = Unpooled
            .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin"));

    final CCloseBuilder builder = new CCloseBuilder();
    builder.setProcessingRule(false);//from   w  w  w. j  a v a  2  s  .co  m
    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()
                    .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));

    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java

License:Open Source License

@Test
public void testLoadBalancingObject() throws IOException, PCEPDeserializerException {
    final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser();
    final ByteBuf result = Unpooled
            .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin"));

    final LoadBalancingBuilder builder = new LoadBalancingBuilder();
    builder.setProcessingRule(true);/*w ww . j a  v a  2  s  .co  m*/
    builder.setIgnore(false);
    builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
    builder.setMinBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));

    assertEquals(builder.build(),
            parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buf = Unpooled.buffer();
    parser.serializeObject(builder.build(), buf);
    assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));

    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java

License:Open Source License

@Test
public void testERObject() throws Exception {
    final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(
            this.ctx.getEROSubobjectHandlerRegistry());
    final ByteBuf result = Unpooled.wrappedBuffer(
            ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin"));

    final EroBuilder builder = new EroBuilder();
    builder.setProcessingRule(false);//  www .ja v a  2 s  .  c  o  m
    builder.setIgnore(false);
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject> subs = Lists
            .newArrayList();
    subs.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder()
                    .setLoose(true)
                    .setSubobjectType(new AsNumberCaseBuilder()
                            .setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build())
                            .build())
                    .build());
    subs.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder()
                    .setLoose(true)
                    .setSubobjectType(new IpPrefixCaseBuilder()
                            .setIpPrefix(new IpPrefixBuilder()
                                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build())
                            .build())
                    .build());
    subs.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder()
                    .setLoose(true)
                    .setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(new UnnumberedBuilder()
                            .setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).build()).build())
                    .build());
    builder.setSubobject(subs);

    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));

    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java

License:Open Source License

@Test
public void testIRObject() throws Exception {
    final PCEPIncludeRouteObjectParser parser = new PCEPIncludeRouteObjectParser(
            this.ctx.getEROSubobjectHandlerRegistry());
    final ByteBuf result = Unpooled.wrappedBuffer(
            ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin"));
    final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };

    final IroBuilder builder = new IroBuilder();
    builder.setProcessingRule(false);/*from   w  w  w  .ja v a 2s.  c om*/
    builder.setIgnore(false);
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobject> subs = Lists
            .newArrayList();
    subs.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder()
                    .setSubobjectType(new AsNumberCaseBuilder()
                            .setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x10L)).build())
                            .build())
                    .setLoose(true).build());
    subs.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder()
                    .setSubobjectType(new IpPrefixCaseBuilder()
                            .setIpPrefix(new IpPrefixBuilder()
                                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("18.52.80.0/21"))).build())
                            .build())
                    .setLoose(true).build());
    subs.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder()
                    .setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder()
                            .setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build())
                            .build())
                    .setLoose(true).build());
    subs.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder()
                    .setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(
                            new UnnumberedBuilder().setRouterId(0x1245678L).setInterfaceId(0x9abcdef0L).build())
                            .build())
                    .setLoose(true).build());
    builder.setSubobject(subs);

    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));

    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java

License:Open Source License

@Test
public void testRRObject() throws Exception {
    final PCEPReportedRouteObjectParser parser = new PCEPReportedRouteObjectParser(
            this.ctx.getRROSubobjectHandlerRegistry());
    final ByteBuf result = Unpooled.wrappedBuffer(
            ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin"));
    final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };

    final RroBuilder builder = new RroBuilder();
    builder.setProcessingRule(false);//from   ww  w . j  a  va 2 s  .  co m
    builder.setIgnore(false);
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject> subs = Lists
            .newArrayList();
    subs.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder()
                    .setSubobjectType(
                            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder()
                                    .setIpPrefix(
                                            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder()
                                                    .setIpPrefix(
                                                            new IpPrefix(new Ipv4Prefix("255.255.255.255/32")))
                                                    .build())
                                    .build())
                    .setProtectionAvailable(false).setProtectionInUse(false).build());
    subs.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder()
                    .setSubobjectType(
                            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder()
                                    .setIpPrefix(
                                            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder()
                                                    .setIpPrefix(new IpPrefix(
                                                            Ipv6Util.prefixForBytes(ip6PrefixBytes, 22)))
                                                    .build())
                                    .build())
                    .setProtectionAvailable(false).setProtectionInUse(false).build());
    subs.add(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder()
                    .setSubobjectType(
                            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.UnnumberedCaseBuilder()
                                    .setUnnumbered(
                                            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder()
                                                    .setRouterId(0x1245678L).setInterfaceId(0x9abcdef0L)
                                                    .build())
                                    .build())
                    .setProtectionAvailable(false).setProtectionInUse(false).build());
    builder.setSubobject(subs);

    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));

    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java

License:Open Source License

@Test
public void testBandwidthObject() throws IOException, PCEPDeserializerException {
    final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser();
    final ByteBuf result = Unpooled
            .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin"));

    final BandwidthBuilder builder = new BandwidthBuilder();
    builder.setProcessingRule(true);/*from w w w  .j a  va2  s.  c  o  m*/
    builder.setIgnore(true);
    builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));

    assertEquals(builder.build(),
            parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buf = Unpooled.buffer();
    parser.serializeObject(builder.build(), buf);
    assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));

    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java

License:Open Source License

@Test
public void testExistingBandwidthObject() throws IOException, PCEPDeserializerException {
    final PCEPExistingBandwidthObjectParser parser = new PCEPExistingBandwidthObjectParser();
    final ByteBuf result = Unpooled
            .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin"));

    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder();
    builder.setProcessingRule(true);/*from   ww w . j av a 2s.  c  o m*/
    builder.setIgnore(true);
    builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));

    assertEquals(builder.build(),
            parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buf = Unpooled.buffer();
    parser.serializeObject(builder.build(), buf);
    assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));

    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}