Search in sources :

Example 1 with StatefulPCReportMessageParser

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());
}
Also used : ReportsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcrpt.message.pcrpt.message.ReportsBuilder) Message(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message) Collections(java.util.Collections) PcrptBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.PcrptBuilder) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) PathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcupd.message.pcupd.message.updates.PathBuilder) StatefulPCReportMessageParser(org.opendaylight.protocol.pcep.ietf.stateful.StatefulPCReportMessageParser) PcrptMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcrpt.message.PcrptMessageBuilder) StatefulActivator(org.opendaylight.protocol.pcep.ietf.stateful.StatefulActivator) Reports(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcrpt.message.pcrpt.message.Reports) InitiatedActivator(org.opendaylight.protocol.pcep.ietf.initiated.InitiatedActivator) Test(org.junit.Test)

Example 2 with StatefulPCReportMessageParser

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));
}
Also used : StatefulActivator(org.opendaylight.protocol.pcep.ietf.stateful.StatefulActivator) PcerrBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcerrBuilder) InitiatedActivator(org.opendaylight.protocol.pcep.ietf.initiated.InitiatedActivator) Message(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message) StatefulPCReportMessageParser(org.opendaylight.protocol.pcep.ietf.stateful.StatefulPCReportMessageParser) ArrayList(java.util.ArrayList) ErrorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.ErrorsBuilder) ByteBuf(io.netty.buffer.ByteBuf) PcerrMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.PcerrMessageBuilder) ErrorObjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObjectBuilder) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 InitiatedActivator (org.opendaylight.protocol.pcep.ietf.initiated.InitiatedActivator)2 StatefulActivator (org.opendaylight.protocol.pcep.ietf.stateful.StatefulActivator)2 StatefulPCReportMessageParser (org.opendaylight.protocol.pcep.ietf.stateful.StatefulPCReportMessageParser)2 Message (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message)2 Collections (java.util.Collections)1 PcrptBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.PcrptBuilder)1 PcrptMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcrpt.message.PcrptMessageBuilder)1 Reports (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcrpt.message.pcrpt.message.Reports)1 ReportsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcrpt.message.pcrpt.message.ReportsBuilder)1 PathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcupd.message.pcupd.message.updates.PathBuilder)1 PcerrBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcerrBuilder)1 ErrorObjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObjectBuilder)1 PcerrMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.PcerrMessageBuilder)1 ErrorsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.ErrorsBuilder)1