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 testRPObjectWithTlv() throws PCEPDeserializerException, IOException { final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry); ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject1.bin")); final RpBuilder builder = new RpBuilder(); builder.setProcessingRule(true);/* w ww. jav a 2 s.c om*/ builder.setIgnore(true); builder.setReoptimization(true); builder.setBiDirectional(false); builder.setLoose(true); builder.setMakeBeforeBreak(true); builder.setOrder(false); builder.setPathKey(false); builder.setSupplyOf(false); builder.setFragmentation(false); builder.setP2mp(false); builder.setEroCompression(false); builder.setPriority((short) 5); builder.setRequestId(new RequestId(0xdeadbeefL)); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.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/PCEPRPObject2.bin")); builder.setReoptimization(false); builder.setFragmentation(true); builder.setEroCompression(true); final OrderBuilder b = new OrderBuilder(); b.setDelete(0xffffffffL); b.setSetup(1L); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder() .setOrder(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 testSvecObject() throws IOException, PCEPDeserializerException { final PCEPSvecObjectParser parser = new PCEPSvecObjectParser(); ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin")); final SvecBuilder builder = new SvecBuilder(); builder.setProcessingRule(false);/*from ww w . jav a 2s . c o m*/ builder.setIgnore(false); builder.setLinkDiverse(false); builder.setNodeDiverse(false); builder.setSrlgDiverse(false); builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL))); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), 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/PCEPSvecObject1_10ReqIDs.bin")); builder.setProcessingRule(true); builder.setLinkDiverse(true); builder.setSrlgDiverse(true); final List<RequestId> requestIDs = Lists.newArrayList(); requestIDs.add(new RequestId(0xFFFFFFFFL)); requestIDs.add(new RequestId(0x00000001L)); requestIDs.add(new RequestId(0x01234567L)); requestIDs.add(new RequestId(0x89ABCDEFL)); requestIDs.add(new RequestId(0xFEDCBA98L)); requestIDs.add(new RequestId(0x76543210L)); requestIDs.add(new RequestId(0x15825266L)); requestIDs.add(new RequestId(0x48120BBEL)); requestIDs.add(new RequestId(0x25FB7E52L)); requestIDs.add(new RequestId(0xB2F2546BL)); builder.setRequestsIds(requestIDs); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), 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 testClassTypeObject() throws PCEPDeserializerException { final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser(); final ByteBuf result = Unpooled.wrappedBuffer( new byte[] { (byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04 }); final ClassTypeBuilder builder = new ClassTypeBuilder(); builder.setProcessingRule(true);//from w w w.j a va2 s . co m builder.setIgnore(false); builder.setClassType(new ClassType((short) 4)); 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 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 . ja v a 2s . co m*/ 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);//ww w .j a v a 2 s . co m 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 www .j a va 2 s .c o 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 w w w . j av a 2s . c om*/ 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 testLspaObjectSerializerDefence() throws IOException, PCEPDeserializerException { final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry); final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin")); final LspaBuilder builder = new LspaBuilder(); builder.setProcessingRule(true);/*from w ww . j a v a 2s .c o m*/ builder.setIgnore(true); builder.setLocalProtectionDesired(false); final ByteBuf buf = Unpooled.buffer(result.readableBytes()); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java
License:Open Source License
@Test public void testCloseObjectWithVendorInformationTlv() throws IOException, PCEPDeserializerException { final byte[] closeBytes = { 0x0f, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x05, /* vendor-information TLV */ 0x00, 0x07, 0x00, 0x08,/*from w w w . j av a2 s. c om*/ /* enterprise number */ 0x00, 0x00, 0x00, 0x00, /* enterprise specific information */ 0x00, 0x00, 0x00, 0x05 }; final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry); final ByteBuf result = Unpooled.wrappedBuffer(closeBytes); final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5); final VendorInformationTlv viTlv = new VendorInformationTlvBuilder() .setEnterpriseNumber(new EnterpriseNumber(0L)).setEnterpriseSpecificInformation(esInfo).build(); final CCloseBuilder builder = new CCloseBuilder(); builder.setProcessingRule(false); 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() .setVendorInformationTlv(Lists.newArrayList(viTlv)).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)); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java
License:Open Source License
@Test public void testVendorInformationObject() throws PCEPDeserializerException { final byte[] viObjBytes = { /* vendor-information object */ 0x22, 0x10, 0x00, 0x0C,/* w ww. j a v a2s. c o m*/ /* enterprise number */ 0x00, 0x00, 0x00, 0x00, /* enterprise specific information */ 0x00, 0x00, 0x00, 0x05 }; final TestVendorInformationObjectParser parser = new TestVendorInformationObjectParser(); final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5); final VendorInformationObject viObj = new VendorInformationObjectBuilder() .setEnterpriseNumber(new EnterpriseNumber(0L)).setEnterpriseSpecificInformation(esInfo).build(); final ByteBuf result = Unpooled.wrappedBuffer(viObjBytes); result.readerIndex(8); final VendorInformationObject o = (VendorInformationObject) parser .parseObject(new ObjectHeaderImpl(false, false), result.readSlice(result.readableBytes())); assertEquals(viObj, o); final ByteBuf buf = Unpooled.buffer(viObjBytes.length); parser.serializeObject(viObj, buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); }