List of usage examples for io.netty.buffer ByteBuf array
public abstract byte[] array();
From source file:org.opendaylight.protocol.pcep.ietf.PCEPValidatorTest.java
License:Open Source License
@Test public void testOpenMsg() throws IOException, PCEPDeserializerException { try (StatefulActivator a = new StatefulActivator()) { a.start(this.ctx); final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenMessage1.bin")); final PCEPOpenMessageParser parser = new PCEPOpenMessageParser(this.ctx.getObjectHandlerRegistry()); final OpenMessageBuilder builder = new OpenMessageBuilder(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder(); b.setProcessingRule(false);/*from w w w.j av a 2 s.c o m*/ b.setIgnore(false); b.setVersion(new ProtocolVersion((short) 1)); b.setKeepalive((short) 30); b.setDeadTimer((short) 120); b.setSessionId((short) 1); final Stateful tlv1 = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE).build(); b.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder() .addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(tlv1).build()).build()); builder.setOpen(b.build()); assertEquals(new OpenBuilder().setOpenMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); final ByteBuf buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new OpenBuilder().setOpenMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); } }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPValidatorTest.java
License:Open Source License
@Test public void testUpdMsg() throws IOException, PCEPDeserializerException { try (CrabbeInitiatedActivator a = new CrabbeInitiatedActivator()) { a.start(this.ctx); ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCUpd.2.bin")); final Stateful07PCUpdateRequestMessageParser parser = new Stateful07PCUpdateRequestMessageParser( this.ctx.getObjectHandlerRegistry()); final PcupdMessageBuilder builder = new PcupdMessageBuilder(); final List<Updates> updates = Lists.newArrayList(); final PathBuilder pBuilder = new PathBuilder(); pBuilder.setEro(this.ero); pBuilder.setLspa(this.lspa); updates.add(/*from w ww.ja va 2s . c o m*/ new UpdatesBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder.build()).build()); builder.setUpdates(updates); assertEquals(new PcupdBuilder().setPcupdMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); ByteBuf buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new PcupdBuilder().setPcupdMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCUpd.5.bin")); final List<Updates> updates1 = Lists.newArrayList(); final PathBuilder pBuilder1 = new PathBuilder(); pBuilder1.setEro(this.ero); pBuilder1.setLspa(this.lspa); updates1.add( new UpdatesBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder.build()).build()); updates1.add( new UpdatesBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder1.build()).build()); builder.setUpdates(updates1); assertEquals(new PcupdBuilder().setPcupdMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new PcupdBuilder().setPcupdMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); } }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPValidatorTest.java
License:Open Source License
@Test public void testRptMsg() throws IOException, PCEPDeserializerException { try (CrabbeInitiatedActivator a = new CrabbeInitiatedActivator(); StatefulActivator b = new StatefulActivator()) { a.start(this.ctx); b.start(this.ctx); ByteBuf result = Unpooled.wrappedBuffer(PCRT1); final Stateful07PCReportMessageParser parser = new Stateful07PCReportMessageParser( this.ctx.getObjectHandlerRegistry()); final PcrptMessageBuilder builder = new PcrptMessageBuilder(); final List<Reports> reports = Lists.newArrayList(); reports.add(new ReportsBuilder().setLsp(this.lsp).build()); builder.setReports(reports);/* w ww . j a v a 2 s .co m*/ final Message parseResult = parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()); assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parseResult); ByteBuf buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); result = Unpooled.wrappedBuffer(PCRT2); final List<Reports> reports1 = Lists.newArrayList(); reports1.add(new ReportsBuilder().setLsp(this.lsp).setPath( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.PathBuilder() .setEro(this.ero).setLspa(this.lspa).build()) .build()); builder.setReports(reports1); final ByteBuf input = result.slice(4, result.readableBytes() - 4); assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(input, Collections.emptyList())); buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRpt.3.bin")); final List<Reports> reports2 = Lists.newArrayList(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.PathBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.PathBuilder(); pBuilder.setEro(this.ero); pBuilder.setLspa(this.lspa); pBuilder.setMetrics(Lists.newArrayList(this.metrics, this.metrics)); pBuilder.setRro(this.rro); reports2.add( new ReportsBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder.build()).build()); builder.setReports(reports2); assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRpt.5.bin")); final List<Reports> reports3 = Lists.newArrayList(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.PathBuilder pBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.PathBuilder(); pBuilder1.setEro(this.ero); pBuilder1.setLspa(this.lspa); pBuilder1.setMetrics(Lists.newArrayList(this.metrics, this.metrics)); pBuilder1.setRro(this.rro); reports3.add( new ReportsBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder.build()).build()); reports3.add( new ReportsBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder1.build()).build()); builder.setReports(reports3); assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); result = Unpooled.wrappedBuffer(PCRT3); final List<Reports> reports4 = Lists.newArrayList(); reports4.add(new ReportsBuilder().setLsp(this.lsp).setPath( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.PathBuilder() .setEro(this.ero).setLspa(this.lspa).setBandwidth(this.bandwidth) .setReoptimizationBandwidth(this.reoptimizationBandwidth).build()) .build()); builder.setReports(reports4); final ByteBuf input2 = result.slice(4, result.readableBytes() - 4); assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(input2, Collections.emptyList())); buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); } }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPValidatorTest.java
License:Open Source License
@Test public void testPcinitMsg() throws IOException, PCEPDeserializerException { try (CrabbeInitiatedActivator a = new CrabbeInitiatedActivator()) { a.start(this.ctx); final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/Pcinit.bin")); final CInitiated00PCInitiateMessageParser parser = new CInitiated00PCInitiateMessageParser( this.ctx.getObjectHandlerRegistry()); final PcinitiateMessageBuilder builder = new PcinitiateMessageBuilder(); final RequestsBuilder rBuilder = new RequestsBuilder(); final List<Requests> reqs = Lists.newArrayList(); rBuilder.setSrp(this.srp); rBuilder.setLsp(this.lspSrp); rBuilder.setEro(this.ero); rBuilder.setLspa(this.lspa); rBuilder.setMetrics(Lists.newArrayList(this.metrics)); rBuilder.setIro(this.iro); reqs.add(rBuilder.build());//from www. j a v a 2 s . c o m builder.setRequests(reqs); assertEquals(new PcinitiateBuilder().setPcinitiateMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); final ByteBuf buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new PcinitiateBuilder().setPcinitiateMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); } }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPValidatorTest.java
License:Open Source License
@Test public void testErrorMsg() throws IOException, PCEPDeserializerException { try (StatefulActivator a = new StatefulActivator()) { a.start(this.ctx); final Stateful07ErrorMessageParser parser = new Stateful07ErrorMessageParser( this.ctx.getObjectHandlerRegistry()); ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCErr.1.bin")); ErrorObject error1 = new ErrorObjectBuilder().setIgnore(false).setProcessingRule(false) .setType((short) 19).setValue((short) 1).build(); List<Errors> innerErr = new ArrayList<>(); innerErr.add(new ErrorsBuilder().setErrorObject(error1).build()); PcerrMessageBuilder builder = new PcerrMessageBuilder(); builder.setErrors(innerErr);//from w w w.j a v a 2 s . c o m final List<Srps> srps = new ArrayList<>(); srps.add(new SrpsBuilder().setSrp(new SrpBuilder().setOperationId(new SrpIdNumber(3L)).setIgnore(false) .setProcessingRule(false) .setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder() .build()) .build()).build()); builder.setErrorType(new StatefulCaseBuilder().setStateful( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcerr.pcerr.message.error.type.stateful._case.StatefulBuilder() .setSrps(srps).build()) .build()); assertEquals(new PcerrBuilder().setPcerrMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); ByteBuf buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCErr.5.bin")); error1 = new ErrorObjectBuilder().setIgnore(false).setProcessingRule(false).setType((short) 3) .setValue((short) 1).build(); innerErr = new ArrayList<>(); builder = new PcerrMessageBuilder(); final RpBuilder rpBuilder = new RpBuilder(); rpBuilder.setProcessingRule(true); rpBuilder.setIgnore(false); rpBuilder.setReoptimization(false); rpBuilder.setBiDirectional(false); rpBuilder.setLoose(true); rpBuilder.setMakeBeforeBreak(false); rpBuilder.setOrder(false); rpBuilder.setPathKey(false); rpBuilder.setSupplyOf(false); rpBuilder.setFragmentation(false); rpBuilder.setP2mp(false); rpBuilder.setEroCompression(false); rpBuilder.setPriority((short) 1); rpBuilder.setRequestId(new RequestId(10L)); rpBuilder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder() .build()); rpBuilder.setProcessingRule(false); final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.Rps> rps = Lists .newArrayList(); rps.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.RpsBuilder() .setRp(rpBuilder.build()).build()); innerErr.add(new ErrorsBuilder().setErrorObject(error1).build()); builder.setErrors(innerErr); builder.setErrorType( new RequestCaseBuilder().setRequest(new RequestBuilder().setRps(rps).build()).build()); assertEquals(new PcerrBuilder().setPcerrMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCErr.3.bin")); builder = new PcerrMessageBuilder(); error1 = new ErrorObjectBuilder().setIgnore(false).setProcessingRule(false).setType((short) 3) .setValue((short) 1).build(); innerErr = new ArrayList<>(); innerErr.add(new ErrorsBuilder().setErrorObject(error1).build()); builder.setErrors(innerErr); builder.setErrorType(new SessionCaseBuilder().setSession(new SessionBuilder().setOpen( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder() .setDeadTimer((short) 1).setKeepalive((short) 1) .setVersion(new ProtocolVersion((short) 1)).setSessionId((short) 0).setIgnore(false) .setProcessingRule(false) .setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder() .build()) .build()) .build()).build()); assertEquals(new PcerrBuilder().setPcerrMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); } }
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);/* ww w .j a va2 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); 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 w w w .j ava 2 s. com*/ 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);/*from ww w .j ava 2 s.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 testERObject() throws Exception { final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser( this.ctx.getEROSubobjectHandlerRegistry()); final ByteBuf result = Unpooled.wrappedBuffer( ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin")); final EroBuilder builder = new EroBuilder(); builder.setProcessingRule(false);//w ww . j a va2s.c o m builder.setIgnore(false); final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject> subs = Lists .newArrayList(); subs.add( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder() .setLoose(true) .setSubobjectType(new AsNumberCaseBuilder() .setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()) .build()) .build()); subs.add( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder() .setLoose(true) .setSubobjectType(new IpPrefixCaseBuilder() .setIpPrefix(new IpPrefixBuilder() .setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()) .build()) .build()); subs.add( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder() .setLoose(true) .setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(new UnnumberedBuilder() .setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).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.", 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);/*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.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()); } }