List of usage examples for io.netty.buffer ByteBuf array
public abstract byte[] array();
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);// w w w.j a v a 2 s.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 w w. j a v a 2s .c o m 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);// w ww . j a v a 2s .co m 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()); } }
From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java
License:Open Source License
@Test public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException { final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E }; final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; final PCEPEndPointsIpv4ObjectParser parser = new PCEPEndPointsIpv4ObjectParser(); final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin")); final EndpointsObjBuilder builder = new EndpointsObjBuilder(); builder.setProcessingRule(true);//from w ww. ja v a 2s. c o m builder.setIgnore(false); builder.setAddressFamily( new Ipv4CaseBuilder() .setIpv4(new Ipv4Builder() .setSourceIpv4Address( Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))) .setDestinationIpv4Address( Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))) .build()) .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 testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException { final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1, (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, }; final byte[] srcIPBytes = { (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 }; final PCEPEndPointsIpv6ObjectParser parser = new PCEPEndPointsIpv6ObjectParser(); final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin")); final EndpointsObjBuilder builder = new EndpointsObjBuilder(); builder.setProcessingRule(true);//from w ww. j a va 2 s . c om builder.setIgnore(false); builder.setAddressFamily( new Ipv6CaseBuilder() .setIpv6(new Ipv6Builder() .setSourceIpv6Address( Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))) .setDestinationIpv6Address( Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))) .build()) .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 testErrorObjectWithTlv() throws PCEPDeserializerException, IOException { final PCEPErrorObjectParser parser = new PCEPErrorObjectParser(this.tlvRegistry, this.viTlvRegistry); ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject1.bin")); final ErrorObjectBuilder builder = new ErrorObjectBuilder(); builder.setProcessingRule(true);/*from www .jav a2 s .c o m*/ builder.setIgnore(true); builder.setType((short) 1); builder.setValue((short) 1); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); ByteBuf buf = Unpooled.buffer(); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin")); builder.setType((short) 7); builder.setValue((short) 0); builder.setTlvs(new TlvsBuilder() .setReqMissing(new ReqMissingBuilder().setRequestId(new RequestId(0x00001155L)).build()).build()); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); 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 testLspaObject() throws IOException, PCEPDeserializerException { final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry); ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin")); final LspaBuilder builder = new LspaBuilder(); builder.setProcessingRule(true);// w ww .j a va2 s.c o m builder.setIgnore(true); builder.setExcludeAny(new AttributeFilter(0L)); builder.setIncludeAny(new AttributeFilter(0L)); builder.setIncludeAll(new AttributeFilter(0L)); builder.setHoldPriority((short) 0); builder.setSetupPriority((short) 0); builder.setLocalProtectionDesired(false); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder() .build()); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); ByteBuf buf = Unpooled.buffer(); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin")); builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL)); builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL)); builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL)); builder.setHoldPriority((short) 0xFF); builder.setSetupPriority((short) 0xFF); builder.setLocalProtectionDesired(true); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); 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 testMetricObject() throws IOException, PCEPDeserializerException { final PCEPMetricObjectParser parser = new PCEPMetricObjectParser(); ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin")); final MetricBuilder builder = new MetricBuilder(); builder.setProcessingRule(true);/*from w ww . j av a 2 s. co m*/ builder.setIgnore(true); builder.setComputed(false); builder.setBound(false); builder.setMetricType((short) 1); builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 })); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); ByteBuf buf = Unpooled.buffer(); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin")); builder.setComputed(true); builder.setBound(false); builder.setMetricType((short) 2); builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 })); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); 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 testNoPathObjectWithTlv() throws PCEPDeserializerException, IOException { final PCEPNoPathObjectParser parser = new PCEPNoPathObjectParser(this.tlvRegistry, this.viTlvRegistry); ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject1WithoutTLV.bin")); final NoPathBuilder builder = new NoPathBuilder(); builder.setProcessingRule(true);//w w w . j av a 2s .c o m builder.setIgnore(true); builder.setNatureOfIssue((short) 1); builder.setUnsatisfiedConstraints(true); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder() .build()); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); ByteBuf buf = Unpooled.buffer(); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject2WithTLV.bin")); builder.setNatureOfIssue((short) 0); builder.setUnsatisfiedConstraints(false); final NoPathVectorBuilder b = new NoPathVectorBuilder(); b.setFlags( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags( false, true, false, true, false, true, true, true)); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder() .setNoPathVector(b.build()).build()); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); 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 testNotifyObjectWithTlv() throws PCEPDeserializerException, IOException { final PCEPNotificationObjectParser parser = new PCEPNotificationObjectParser(this.tlvRegistry, this.viTlvRegistry); ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject2WithoutTlv.bin")); final CNotificationBuilder builder = new CNotificationBuilder(); builder.setProcessingRule(true);/*from w w w . j a v a 2 s. c o m*/ builder.setIgnore(true); builder.setType((short) 0xff); builder.setValue((short) 0xff); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); ByteBuf buf = Unpooled.buffer(); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject1WithTlv.bin")); builder.setType((short) 2); builder.setValue((short) 1); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.c.notification.TlvsBuilder() .setOverloadDuration(new OverloadDurationBuilder().setDuration(0xff0000a2L).build()) .build()); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); 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()); } }