List of usage examples for io.netty.buffer Unpooled EMPTY_BUFFER
ByteBuf EMPTY_BUFFER
To view the source code for io.netty.buffer Unpooled EMPTY_BUFFER.
Click Source Link
From source file:org.opendaylight.protocol.pcep.impl.LabelSubobjectParserTest.java
License:Open Source License
@Test public void testGeneralizedLabel() throws PCEPDeserializerException { final GeneralizedLabelParser parser = new GeneralizedLabelParser(); final GeneralizedLabelBuilder iBuilder = new GeneralizedLabelBuilder(); iBuilder.setGeneralizedLabel(ByteArray.cutBytes(generalizedLabelBytes, 2)); final GeneralizedLabelCaseBuilder builder = new GeneralizedLabelCaseBuilder() .setGeneralizedLabel(iBuilder.build()); assertEquals(builder.build(),// w w w .ja va2 s. co m parser.parseLabel(Unpooled.wrappedBuffer(ByteArray.cutBytes(generalizedLabelBytes, 2)))); final ByteBuf buff = Unpooled.buffer(); parser.serializeLabel(true, false, builder.build(), buff); assertArrayEquals(generalizedLabelBytes, 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()); } }
From source file:org.opendaylight.protocol.pcep.impl.LabelSubobjectParserTest.java
License:Open Source License
@Test public void testWavebandLabel() throws PCEPDeserializerException { final WavebandSwitchingLabelParser parser = new WavebandSwitchingLabelParser(); final WavebandSwitchingLabelBuilder iBuilder = new WavebandSwitchingLabelBuilder(); iBuilder.setWavebandId(0x1234L);//from w w w . jav a 2 s. c o m 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()); } }
From source file:org.opendaylight.protocol.pcep.impl.LabelSubobjectParserTest.java
License:Open Source License
@Test public void testTypeOneLabel() throws PCEPDeserializerException { final Type1LabelParser parser = new Type1LabelParser(); final Type1LabelBuilder iBuilder = new Type1LabelBuilder(); iBuilder.setType1Label(0x120025ffL); final Type1LabelCaseBuilder builder = new Type1LabelCaseBuilder().setType1Label(iBuilder.build()); assertEquals(builder.build(),/*from w w w .j ava2s. co m*/ parser.parseLabel(Unpooled.wrappedBuffer(ByteArray.cutBytes(typeOneLabelBytes, 2)))); final ByteBuf buff = Unpooled.buffer(); parser.serializeLabel(true, true, builder.build(), buff); assertArrayEquals(typeOneLabelBytes, 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()); } }
From source file:org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser.java
License:Open Source License
@Override public void serializeMessage(final Message message, final ByteBuf out) { Preconditions.checkArgument(message instanceof KeepaliveMessage, "Wrong instance of Message. Passed instance of %s. Need KeepaliveMessage.", message.getClass()); MessageUtil.formatMessage(TYPE, Unpooled.EMPTY_BUFFER, out); }
From source file:org.opendaylight.protocol.pcep.impl.message.PCEPStartTLSMessageParser.java
License:Open Source License
@Override public void serializeMessage(final Message message, final ByteBuf out) { Preconditions.checkArgument(message instanceof StartTlsMessage, "Wrong instance of Message. Passed instance of %s. Need StartTlsMessage.", message.getClass()); MessageUtil.formatMessage(TYPE, Unpooled.EMPTY_BUFFER, out); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPEROSubobjectParserTest.java
License:Open Source License
@Test public void testEROIp4PrefixSubobject() throws PCEPDeserializerException { final EROIpv4PrefixSubobjectParser parser = new EROIpv4PrefixSubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setLoose(true);//from w w w . j a va 2 s .c o m 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)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); assertArrayEquals(ip4PrefixBytes, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); 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, true); 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.PCEPEROSubobjectParserTest.java
License:Open Source License
@Test public void testEROIp6PrefixSubobject() throws PCEPDeserializerException { final EROIpv6PrefixSubobjectParser parser = new EROIpv6PrefixSubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setSubobjectType(/*from w ww .j av a2 s. c o m*/ 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()); subs.setLoose(false); assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip6PrefixBytes, 2)), false)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); assertArrayEquals(ip6PrefixBytes, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); 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, true); 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.PCEPEROSubobjectParserTest.java
License:Open Source License
@Test public void testEROAsNumberSubobject() throws PCEPDeserializerException { final EROAsNumberSubobjectParser parser = new EROAsNumberSubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setLoose(true);/*ww w .ja v a2 s . c o m*/ subs.setSubobjectType(new AsNumberCaseBuilder() .setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build()).build()); assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(asNumberBytes, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); assertArrayEquals(asNumberBytes, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); 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, true); 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.PCEPEROSubobjectParserTest.java
License:Open Source License
@Test public void testEROUnnumberedSubobject() throws PCEPDeserializerException { final EROUnnumberedInterfaceSubobjectParser parser = new EROUnnumberedInterfaceSubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setLoose(true);/*from w w w . j a v a 2 s. co m*/ 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); assertArrayEquals(unnumberedBytes, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); 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, true); 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.PCEPEROSubobjectParserTest.java
License:Open Source License
@Test public void testEROPathKey32Subobject() throws PCEPDeserializerException { final EROPathKey32SubobjectParser parser = new EROPathKey32SubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setLoose(true);//from ww w .j a va2 s. c o m 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(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey32Bytes, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); assertArrayEquals(pathKey32Bytes, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); 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, true); fail(); } catch (final IllegalArgumentException e) { assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage()); } }