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.PCEPRROSubobjectParserTest.java
License:Open Source License
@Test public void testRROLabelSubobject() throws Exception { final SimplePCEPExtensionProviderContext ctx = new SimplePCEPExtensionProviderContext(); try (BaseParserExtensionActivator a = new BaseParserExtensionActivator()) { a.start(ctx);//from w w w .j av a2 s. co m 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()); } } }
From source file:org.opendaylight.protocol.pcep.impl.PCEPXROSubobjectParserTest.java
License:Open Source License
@Test public void testXROIp4PrefixSubobject() throws PCEPDeserializerException { final XROIpv4PrefixSubobjectParser parser = new XROIpv4PrefixSubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setMandatory(false);// ww w .j av a 2 s. c o m subs.setAttribute(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); 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.PCEPXROSubobjectParserTest.java
License:Open Source License
@Test public void testXROIp6PrefixSubobject() throws PCEPDeserializerException { final XROIpv6PrefixSubobjectParser parser = new XROIpv6PrefixSubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setMandatory(true);//from w ww .j av a2 s . co m subs.setAttribute(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); 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.PCEPXROSubobjectParserTest.java
License:Open Source License
@Test public void testXROSrlgSubobject() throws PCEPDeserializerException { final XROSRLGSubobjectParser parser = new XROSRLGSubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setMandatory(true);//from w w w . j a v a 2s . co m subs.setAttribute(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); assertArrayEquals(srlgBytes, 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.PCEPXROSubobjectParserTest.java
License:Open Source License
@Test public void testXROUnnumberedSubobject() throws PCEPDeserializerException { final XROUnnumberedInterfaceSubobjectParser parser = new XROUnnumberedInterfaceSubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setMandatory(true);// w w w. j a v a 2 s .co m subs.setAttribute(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); 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.PCEPXROSubobjectParserTest.java
License:Open Source License
@Test public void testXROAsNumberSubobject() throws PCEPDeserializerException { final XROAsNumberSubobjectParser parser = new XROAsNumberSubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setMandatory(true);//from w w w.ja va 2 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.PCEPXROSubobjectParserTest.java
License:Open Source License
@Test public void testXROPathKey32Subobject() throws PCEPDeserializerException { final XROPathKey32SubobjectParser parser = new XROPathKey32SubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setMandatory(true);/*from ww w . j av a 2s . co 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()); } }
From source file:org.opendaylight.protocol.pcep.impl.PCEPXROSubobjectParserTest.java
License:Open Source License
@Test public void testXROPathKey128Subobject() throws PCEPDeserializerException { final XROPathKey128SubobjectParser parser = new XROPathKey128SubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setMandatory(true);/*from ww w . j a va 2 s . c om*/ 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(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey128Bytes, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); assertArrayEquals(pathKey128Bytes, 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.segment.routing.SrObjectParserTest.java
License:Open Source License
@Test public void testOpenObjectWithSpcTlv() throws PCEPDeserializerException { final PcepOpenObjectWithSpcTlvParser parser = new PcepOpenObjectWithSpcTlvParser(this.tlvRegistry, this.viTlvRegistry); final OpenBuilder builder = new OpenBuilder(); builder.setProcessingRule(false);/*from w ww. ja v 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); final Tlvs1 tlv = new Tlvs1Builder() .setSrPceCapability(new SrPceCapabilityBuilder().setMsd((short) 1).build()).build(); builder.setTlvs(new TlvsBuilder().addAugmentation( org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder() .build()) .addAugmentation(Tlvs1.class, tlv).addAugmentation(Tlvs3.class, new Tlvs3Builder().build()) .build()); final ByteBuf result = Unpooled.wrappedBuffer(openObjectBytes); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); final ByteBuf buffer = Unpooled.buffer(); parser.serializeObject(builder.build(), buffer); parser.serializeTlvs(null, Unpooled.EMPTY_BUFFER); parser.serializeTlvs(new TlvsBuilder().build(), Unpooled.EMPTY_BUFFER); assertArrayEquals(openObjectBytes, ByteArray.getAllBytes(buffer)); }
From source file:org.opendaylight.protocol.rsvp.parser.impl.EROSubobjectParserTest.java
License:Open Source License
@Test public void testEROIp4PrefixSubobject() throws RSVPParsingException { final EROIpv4PrefixSubobjectParser parser = new EROIpv4PrefixSubobjectParser(); final SubobjectContainerBuilder subs = new SubobjectContainerBuilder(); subs.setLoose(true);/*w w w . jav a 2s. com*/ 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(IP_4_PREFIX_BYTES, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); Assert.assertArrayEquals(IP_4_PREFIX_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()); } }