use of org.opendaylight.protocol.pcep.ietf.stateful.StatefulPCReportMessageParser in project bgpcep by opendaylight.
the class PCEPValidatorTest method testRptMsg.
@Test
public void testRptMsg() throws IOException, PCEPDeserializerException {
new InitiatedActivator().start(ctx);
new StatefulActivator().start(ctx);
ByteBuf result = Unpooled.wrappedBuffer(PCRT1);
final StatefulPCReportMessageParser parser = new StatefulPCReportMessageParser(this.ctx.getObjectHandlerRegistry());
final PcrptMessageBuilder builder = new PcrptMessageBuilder();
final List<Reports> reports = new ArrayList<>();
reports.add(new ReportsBuilder().setLsp(this.lsp).build());
builder.setReports(reports);
final Message parseResult = parser.parseMessage(result.slice(4, result.readableBytes() - 4), List.of());
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);
builder.setReports(List.of(new ReportsBuilder().setLsp(this.lsp).setPath(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcrpt.message.pcrpt.message.reports.PathBuilder().setEro(this.ero).setLspa(this.lspa).build()).build()));
final ByteBuf input = result.slice(4, result.readableBytes() - 4);
assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(input, List.of()));
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 = new ArrayList<>();
final var pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.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), List.of()));
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.4.bin"));
assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), List.of()));
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRpt.5.bin"));
final List<Reports> reports3 = new ArrayList<>();
final var pBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.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), List.of()));
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 = new ArrayList<>();
reports4.add(new ReportsBuilder().setLsp(this.lsp).setPath(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.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, List.of()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
}
use of org.opendaylight.protocol.pcep.ietf.stateful.StatefulPCReportMessageParser in project bgpcep by opendaylight.
the class PCEPValidatorTest method testMissingLspObjectErrorInPcRptMsg.
@Test
public void testMissingLspObjectErrorInPcRptMsg() throws PCEPDeserializerException {
final byte[] statefulMsg = { (byte) 0x20, (byte) 0x0B, (byte) 0x00, (byte) 0x1C, /* srp-object */
(byte) 0x21, (byte) 0x10, (byte) 0x00, (byte) 0x0C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x001, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, /* sr-ero-object */
(byte) 0x07, (byte) 0x10, (byte) 0x00, (byte) 0x0C, /* ipv4 prefix subobject */
(byte) 0x81, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 };
new InitiatedActivator().start(ctx);
new StatefulActivator().start(ctx);
final StatefulPCReportMessageParser parser = new StatefulPCReportMessageParser(this.ctx.getObjectHandlerRegistry());
final ByteBuf buf = Unpooled.wrappedBuffer(statefulMsg);
final List<Message> errors = new ArrayList<>();
parser.parseMessage(buf.slice(4, buf.readableBytes() - 4), errors);
assertFalse(errors.isEmpty());
assertEquals(new PcerrBuilder().setPcerrMessage(new PcerrMessageBuilder().setErrors(List.of(new ErrorsBuilder().setErrorObject(new ErrorObjectBuilder().setType(Uint8.valueOf(6)).setValue(Uint8.valueOf(8)).build()).build())).build()).build(), errors.get(0));
}
Aggregations