Example usage for io.netty.buffer Unpooled EMPTY_BUFFER

List of usage examples for io.netty.buffer Unpooled EMPTY_BUFFER

Introduction

In this page you can find the example usage for io.netty.buffer Unpooled EMPTY_BUFFER.

Prototype

ByteBuf EMPTY_BUFFER

To view the source code for io.netty.buffer Unpooled EMPTY_BUFFER.

Click Source Link

Document

A buffer whose capacity is 0 .

Usage

From source file:org.opendaylight.protocol.rsvp.parser.impl.RROSubobjectParserTest.java

License:Open Source License

@Test
public void testRROIp4PrefixSubobject() throws RSVPParsingException {
    final RROIpv4PrefixSubobjectParser parser = new RROIpv4PrefixSubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setProtectionAvailable(true);//from  www  . j av a2  s .  c  o m
    subs.setProtectionInUse(false);
    subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(
            new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build())
            .build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip4PrefixBytes, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(ip4PrefixBytes, 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());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.RROSubobjectParserTest.java

License:Open Source License

@Test
public void testRROIp6PrefixSubobject() throws RSVPParsingException {
    final RROIpv6PrefixSubobjectParser parser = new RROIpv6PrefixSubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setProtectionAvailable(false);/*from   ww  w  .j  a v a2s  .c o  m*/
    subs.setProtectionInUse(true);
    subs.setSubobjectType(
            new IpPrefixCaseBuilder()
                    .setIpPrefix(new IpPrefixBuilder()
                            .setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF,
                                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
                                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
                                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22)))
                            .build())
                    .build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip6PrefixBytes, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(ip6PrefixBytes, 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());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.RROSubobjectParserTest.java

License:Open Source License

@Test
public void testRROUnnumberedSubobject() throws RSVPParsingException {
    final RROUnnumberedInterfaceSubobjectParser parser = new RROUnnumberedInterfaceSubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setProtectionAvailable(false);/*from  w w  w .j  ava  2s  .  c  o  m*/
    subs.setProtectionInUse(true);
    subs.setSubobjectType(new UnnumberedCaseBuilder()
            .setUnnumbered(new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build())
            .build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(unnumberedBytes, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(unnumberedBytes, 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());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.RROSubobjectParserTest.java

License:Open Source License

@Test
public void testRROPathKey32Subobject() throws RSVPParsingException {
    final RROPathKey32SubobjectParser parser = new RROPathKey32SubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
    pBuilder.setPathKey(new PathKey(4660));
    subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    assertEquals(subs.build(),//from  ww  w  .jav a 2 s.  c  o m
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey32Bytes, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(pathKey32Bytes, 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());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.RROSubobjectParserTest.java

License:Open Source License

@Test
public void testRROPathKey128Subobject() throws RSVPParsingException {
    final RROPathKey128SubobjectParser parser = new RROPathKey128SubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A,
            (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
    pBuilder.setPathKey(new PathKey(4660));
    subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    assertEquals(subs.build(),//w w  w  . jav  a 2  s  .c o m
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey128Bytes, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(pathKey128Bytes, 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());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.RROSubobjectParserTest.java

License:Open Source License

@Test
public void testRROLabelSubobject() throws Exception {
    final SimpleRSVPExtensionProviderContext ctx = new SimpleRSVPExtensionProviderContext();
    try (RSVPActivator a = new RSVPActivator()) {
        a.start(ctx);// w  w  w.j a v a  2  s .  c  o  m
        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(labelBytes, 2))));
        final ByteBuf buff = Unpooled.buffer();
        parser.serializeSubobject(subs.build(), buff);
        Assert.assertArrayEquals(labelBytes, 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());
        }
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.XROSubobjectParserTest.java

License:Open Source License

@Test
public void testXROIp4PrefixSubobject() throws RSVPParsingException {
    final XROIpv4PrefixSubobjectParser parser = new XROIpv4PrefixSubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setMandatory(false);//from w  w w.j a  va  2s  .  c  o  m
    subs.setAttribute(ExcludeRouteSubobjects.Attribute.Interface);
    subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(
            new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build())
            .build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip4PrefixBytes, 2)), false));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(ip4PrefixBytes, 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());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.XROSubobjectParserTest.java

License:Open Source License

@Test
public void testXROIp6PrefixSubobject() throws RSVPParsingException {
    final XROIpv6PrefixSubobjectParser parser = new XROIpv6PrefixSubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setMandatory(true);/*from  w  ww  . j  a v  a2  s . c  o  m*/
    subs.setAttribute(ExcludeRouteSubobjects.Attribute.Node);
    subs.setSubobjectType(
            new IpPrefixCaseBuilder()
                    .setIpPrefix(new IpPrefixBuilder()
                            .setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF,
                                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
                                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
                                    (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22)))
                            .build())
                    .build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip6PrefixBytes, 2)), true));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(ip6PrefixBytes, 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());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.XROSubobjectParserTest.java

License:Open Source License

@Test
public void testXROSrlgSubobject() throws RSVPParsingException {
    final XROSRLGSubobjectParser parser = new XROSRLGSubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setMandatory(true);// w  ww  .j  a va 2  s . c  om
    subs.setAttribute(ExcludeRouteSubobjects.Attribute.Srlg);
    subs.setSubobjectType(new SrlgCaseBuilder()
            .setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(0x12345678L)).build()).build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(srlgBytes, 2)), true));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(srlgBytes, 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());
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.XROSubobjectParserTest.java

License:Open Source License

@Test
public void testXROUnnumberedSubobject() throws RSVPParsingException {
    final XROUnnumberedInterfaceSubobjectParser parser = new XROUnnumberedInterfaceSubobjectParser();
    final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
    subs.setMandatory(true);// w ww .  j  a v  a2s .c  om
    subs.setAttribute(ExcludeRouteSubobjects.Attribute.Node);
    subs.setSubobjectType(new UnnumberedCaseBuilder()
            .setUnnumbered(new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build())
            .build());
    assertEquals(subs.build(),
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(unnumberedBytes, 2)), true));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    Assert.assertArrayEquals(unnumberedBytes, 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());
    }
}