List of usage examples for io.netty.buffer ByteBuf slice
public abstract ByteBuf slice(int index, int length);
From source file:org.opendaylight.protocol.pcep.ietf.PCEPObjectParserTest.java
License:Open Source License
@Test public void testLspObjectWithTLV() throws IOException, PCEPDeserializerException { try (StatefulActivator a = new StatefulActivator(); SyncOptimizationsActivator a2 = new SyncOptimizationsActivator()) { a.start(this.ctx); a2.start(this.ctx); final SyncOptimizationsLspObjectParser parser = new SyncOptimizationsLspObjectParser( this.ctx.getTlvHandlerRegistry(), this.ctx.getVendorInformationTlvRegistry()); final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspObject1WithTLV.bin")); final LspBuilder builder = new LspBuilder(); builder.setProcessingRule(true); builder.setIgnore(true);//from www . j a v a2s. c om builder.setAdministrative(true); builder.setDelegate(false); builder.setRemove(true); builder.setSync(false); builder.addAugmentation(Lsp1.class, new Lsp1Builder().setCreate(false).build()); builder.setOperational(OperationalStatus.GoingDown); builder.setPlspId(new PlspId(0x12345L)); final LspErrorCode tlv1 = new LspErrorCodeBuilder().setErrorCode(627610883L).build(); final SymbolicPathName tlv2 = new SymbolicPathNameBuilder().setPathName( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName( "Med".getBytes())) .build(); final LspDbVersion lspDbVersion = new LspDbVersionBuilder() .setLspDbVersionValue(new BigInteger(DB_VERSION)).build(); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder() .setLspErrorCode(tlv1).setSymbolicPathName(tlv2) .addAugmentation( org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder() .setLspDbVersion(lspDbVersion).build()) .build()); 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)); } }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPObjectParserTest.java
License:Open Source License
@Test public void testStateful07LspObjectWithTlv() throws IOException, PCEPDeserializerException { final Stateful07LspObjectParser parser = new Stateful07LspObjectParser(this.tlvRegistry, this.viTlvRegistry); final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspObject2WithTLV.bin")); final LspBuilder builder = new LspBuilder(); builder.setProcessingRule(true);/* w ww . j a v a 2 s . c o m*/ builder.setIgnore(true); builder.setAdministrative(true); builder.setDelegate(false); builder.setRemove(true); builder.setSync(false); builder.setOperational(OperationalStatus.GoingDown); builder.setPlspId(new PlspId(0x12345L)); final LspErrorCode tlv1 = new LspErrorCodeBuilder().setErrorCode(627610883L).build(); final SymbolicPathName tlv2 = new SymbolicPathNameBuilder().setPathName( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName( "Med".getBytes())) .build(); final Ipv4Builder afi = new Ipv4Builder(); afi.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf( Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }))); afi.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForByteBuf( Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })))); afi.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf( Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }))); final LspIdentifiers tlv3 = new LspIdentifiersBuilder() .setAddressFamily(new Ipv4CaseBuilder().setIpv4(afi.build()).build()).setLspId(new LspId(65535L)) .setTunnelId(new TunnelId(4660)).build(); final RsvpErrorBuilder rsvpBuilder = new RsvpErrorBuilder(); rsvpBuilder.setNode(new IpAddress(Ipv4Util.addressForByteBuf( Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })))); rsvpBuilder.setFlags( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ErrorSpec.Flags( false, true)); rsvpBuilder.setCode((short) 146); rsvpBuilder.setValue(5634); final RsvpErrorSpec tlv4 = new RsvpErrorSpecBuilder() .setErrorType(new RsvpCaseBuilder().setRsvpError(rsvpBuilder.build()).build()).build(); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder() .setLspErrorCode(tlv1).setSymbolicPathName(tlv2).setLspIdentifiers(tlv3) .setRsvpErrorSpec(tlv4).build()); 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)); }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPObjectParserTest.java
License:Open Source License
@Test public void testLspaObject() throws IOException, PCEPDeserializerException { final Stateful07LspaObjectParser parser = new Stateful07LspaObjectParser(this.tlvRegistry, this.viTlvRegistry); final LspaBuilder builder = new LspaBuilder(); final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject3RandVals.bin")); final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName( new byte[] { (byte) 0x4d, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x6f, (byte) 0x66, (byte) 0x20, (byte) 0x73, (byte) 0x79, (byte) 0x6d, (byte) 0x62, (byte) 0x6f, (byte) 0x6c, (byte) 0x69, (byte) 0x63, (byte) 0x20, (byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65 })) .build();/*w ww . j a v a2 s . co m*/ builder.setIgnore(false); builder.setProcessingRule(false); builder.setExcludeAny(new AttributeFilter(0x20A1FEE3L)); builder.setIncludeAny(new AttributeFilter(0x1A025CC7L)); builder.setIncludeAll(new AttributeFilter(0x2BB66532L)); builder.setHoldPriority((short) 0x02); builder.setSetupPriority((short) 0x03); builder.setLocalProtectionDesired(true); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder() .addAugmentation(Tlvs2.class, new Tlvs2Builder().setSymbolicPathName(tlv).build()).build()); // Tlvs container does not contain toString final Object o = parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)); assertEquals(tlv, ((Lspa) o).getTlvs().getAugmentation(Tlvs2.class).getSymbolicPathName()); // assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), ByteArray.cutBytes(result, // 4))); final ByteBuf buf = Unpooled.buffer(); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPObjectParserTest.java
License:Open Source License
@Test public void testSrpObject() throws IOException, PCEPDeserializerException { final CInitiated00SrpObjectParser parser = new CInitiated00SrpObjectParser(this.tlvRegistry, this.viTlvRegistry); final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x21, (byte) 0x10, (byte) 0x00, (byte) 0x0c, 0, 0, 0, (byte) 0x01, 0, 0, 0, (byte) 0x01 }); final SrpBuilder builder = new SrpBuilder(); builder.setProcessingRule(false);//from w w w . j a v a2 s .c o m builder.setIgnore(false); builder.setOperationId(new SrpIdNumber(1L)); builder.addAugmentation(Srp1.class, new Srp1Builder().setRemove(true).build()); builder.setTlvs(new 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)); }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPObjectParserTest.java
License:Open Source License
@Test public void testSRPObjectWithPSTTlv() throws PCEPDeserializerException { final byte[] srpObjectWithPstTlvBytes = { 0x21, 0x10, 0x00, 0x14, 0x0, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x01, /* pst-tlv */ 0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0 }; final CInitiated00SrpObjectParser parser = new CInitiated00SrpObjectParser(this.tlvRegistry, this.viTlvRegistry); final SrpBuilder builder = new SrpBuilder(); builder.setProcessingRule(false);/*from w w w . j av a 2s . c om*/ builder.setIgnore(false); builder.setOperationId(new SrpIdNumber(1L)); builder.addAugmentation(Srp1.class, new Srp1Builder().setRemove(true).build()); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder() .setPathSetupType(new PathSetupTypeBuilder().setPst((short) 0).build()).build()); final ByteBuf result = Unpooled.wrappedBuffer(srpObjectWithPstTlvBytes); 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(srpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf)); }
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);/* w ww .j a v a 2 s .com*/ 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 .jav a 2 s .co 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);//from w w w. j av a 2s . 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());/*w w w . jav a2 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);/*w w w. j a va 2 s . c om*/ 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()); } }