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.PCEPEROSubobjectParserTest.java
License:Open Source License
@Test public void testEROPathKey128Subobject() throws PCEPDeserializerException { final EROPathKey128SubobjectParser parser = new EROPathKey128SubobjectParser(); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setLoose(true);/*from w w w.j ava 2 s .c o m*/ 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.impl.PCEPEROSubobjectParserTest.java
License:Open Source License
@Test public void testEROLabelSubobject() throws Exception { final EROLabelSubobjectParser parser = new EROLabelSubobjectParser(this.ctx.getLabelHandlerRegistry()); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setLoose(true);// w w w .ja v a 2 s. c o m subs.setSubobjectType(new LabelCaseBuilder().setLabel(new LabelBuilder().setUniDirectional(true) .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)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); assertArrayEquals(labelBytes, 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 testEROEXRSSubobject() throws Exception { final EROExplicitExclusionRouteSubobjectParser parser = new EROExplicitExclusionRouteSubobjectParser( this.ctx.getXROSubobjectHandlerRegistry()); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setLoose(true);//from w w w. j a v a 2 s . c o m final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.Exrs> list = Lists .newArrayList(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder(); builder.setMandatory(true); builder.setSubobjectType(new AsNumberCaseBuilder() .setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build()).build()); list.add(builder.build()); subs.setSubobjectType(new ExrsCaseBuilder().setExrs(new ExrsBuilder().setExrs(list).build()).build()); assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(exrsBytes, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); assertArrayEquals(exrsBytes, 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.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);/* w w w . j a va 2 s .c om*/ 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 www.j ava 2 s .c o 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);//ww w .ja va2s . c o 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 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);/* www . jav a2 s. 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 . ja v a 2s. c o 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 ww.ja va2s . com*/ 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);/* www . j av a 2 s .com*/ 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()); } }