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.pcep.impl.PCEPObjectParserTest.java

License:Open Source License

@Test
public void testExcludeRouteObject() throws Exception {
    final PCEPExcludeRouteObjectParser parser = new PCEPExcludeRouteObjectParser(
            this.ctx.getXROSubobjectHandlerRegistry());
    final ByteBuf result = Unpooled
            .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExcludeRouteObject.1.bin"));

    final XroBuilder builder = new XroBuilder();
    builder.setProcessingRule(false);//from ww w.  j a va 2 s  .com
    builder.setIgnore(false);
    builder.setFlags(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro.Flags(
                    true));
    final List<Subobject> subs = Lists.newArrayList();
    subs.add(
            new SubobjectBuilder().setMandatory(true)
                    .setSubobjectType(new IpPrefixCaseBuilder()
                            .setIpPrefix(new IpPrefixBuilder()
                                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.0.0/16"))).build())
                            .build())
                    .setAttribute(Attribute.Node).build());
    subs.add(new SubobjectBuilder().setMandatory(false)
            .setSubobjectType(new AsNumberCaseBuilder()
                    .setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x1234L)).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 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 testPathKeyObject() throws Exception {
    final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(
            this.ctx.getEROSubobjectHandlerRegistry());
    final ByteBuf result = Unpooled
            .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin"));

    final PathKeyBuilder builder = new PathKeyBuilder();
    builder.setProcessingRule(true);/*from  w  ww  .ja v  a2  s  .  c  om*/
    builder.setIgnore(false);
    final List<PathKeys> list = Lists.newArrayList();
    list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234))
            .setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build());
    builder.setPathKeys(list);

    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 testObjectiveFunctionObject() throws IOException, PCEPDeserializerException {
    final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry,
            this.viTlvRegistry);
    final ByteBuf result = Unpooled
            .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin"));

    final OfBuilder builder = new OfBuilder();
    builder.setProcessingRule(true);//from w  w w .ja  v a  2  s. co  m
    builder.setIgnore(false);
    builder.setCode(new OfId(4));
    builder.setTlvs(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.of.TlvsBuilder()
                    .build());

    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 testGlobalConstraintsObject() throws IOException, PCEPDeserializerException {
    final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry,
            this.viTlvRegistry);
    final ByteBuf result = Unpooled
            .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin"));

    final GcBuilder builder = new GcBuilder();
    builder.setProcessingRule(true);//from  ww w  .  jav a 2  s .  c o  m
    builder.setIgnore(false);
    builder.setMaxHop((short) 1);
    builder.setMaxUtilization((short) 0);
    builder.setMinUtilization((short) 100);
    builder.setOverBookingFactor((short) 99);
    builder.setTlvs(
            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder()
                    .build());

    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 testEmptyEroObject() throws PCEPDeserializerException {
    final Object object = this.ctx.getObjectHandlerRegistry().parseObject(PCEPExplicitRouteObjectParser.CLASS,
            PCEPExplicitRouteObjectParser.TYPE, new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
    assertNotNull(object);//w w w  . j av a  2s  .c o m
    assertTrue(object instanceof Ero);
    final Ero eroObject = (Ero) object;
    assertTrue(eroObject.getSubobject().isEmpty());

    final ByteBuf buffer = Unpooled.buffer();
    this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
    final byte[] expected = { 0x07, 0x13, 0x00, 0x04 };
    assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
}

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

License:Open Source License

@Test
public void testRROIp4PrefixSubobject() throws PCEPDeserializerException {
    final RROIpv4PrefixSubobjectParser parser = new RROIpv4PrefixSubobjectParser();
    final SubobjectBuilder subs = new SubobjectBuilder();
    subs.setProtectionAvailable(true);//from w  w  w  .  ja  va  2 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);
    assertArrayEquals(ip4PrefixBytes, 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());
    }
}

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

License:Open Source License

@Test
public void testRROIp6PrefixSubobject() throws PCEPDeserializerException {
    final RROIpv6PrefixSubobjectParser parser = new RROIpv6PrefixSubobjectParser();
    final SubobjectBuilder subs = new SubobjectBuilder();
    subs.setProtectionAvailable(false);//from   ww w .  j a v  a  2  s.co 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);
    assertArrayEquals(ip6PrefixBytes, 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());
    }
}

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

License:Open Source License

@Test
public void testRROUnnumberedSubobject() throws PCEPDeserializerException {
    final RROUnnumberedInterfaceSubobjectParser parser = new RROUnnumberedInterfaceSubobjectParser();
    final SubobjectBuilder subs = new SubobjectBuilder();
    subs.setProtectionAvailable(false);/*from w w w.ja va 2 s  .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);
    assertArrayEquals(unnumberedBytes, 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());
    }
}

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

License:Open Source License

@Test
public void testRROPathKey32Subobject() throws PCEPDeserializerException {
    final RROPathKey32SubobjectParser parser = new RROPathKey32SubobjectParser();
    final SubobjectBuilder subs = new SubobjectBuilder();
    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  .j a  v a  2s.c o m*/
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey32Bytes, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    assertArrayEquals(pathKey32Bytes, 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());
    }
}

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

License:Open Source License

@Test
public void testRROPathKey128Subobject() throws PCEPDeserializerException {
    final RROPathKey128SubobjectParser parser = new RROPathKey128SubobjectParser();
    final SubobjectBuilder subs = new SubobjectBuilder();
    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(),/*from   ww w.  java 2s  .c  o m*/
            parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey128Bytes, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    assertArrayEquals(pathKey128Bytes, 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());
    }
}